SwiftyConnect - SteemConnect for iOS !

in #utopian-io6 years ago (edited)

wallpaper.png

SwiftyConnect

What is the project about?

Y'all now SteemConnect, which is a Secure access to the Steem ecosystem via the OAuth Flow. Currently SteemConnect is only available in JavaScript and PHP which limits the usage of the Steem blockchain. It is currently almost impossible to create a mobile (iOS) application which makes use of the Steem blockchain in a way, an end user can easily trust the application.

For this reason and to open the Steem blockchain to the AppStore, I have decided to make a Swift Library which uses SteemConnect for Broadcasting Actions & Steem API to fetch data.

SwiftyConnect is still in development, but I already wanted to release a version since broadcasting (should) work and I need some people who test it :)
I have tested every method for broadcasting, and only some for the API.

Technology Stack

Swift as programming language, p2/oauth2 for the authentication flow, steem blockchain jrpc for fetching data.

How To Use

Installation

Carthage

github "caspernikus/SwiftyConnect" ~> 0.1.3

(When building SwiftyConnect the lib OAuth2 is also builded, there is no need to add OAuth2 inside your project, since SwiftyConenct contains OAuth2!)

Usage

SwiftyConnects make use of one main class called Steem. To use Steem you should ALWAYS use the sharedInstance => let steem = Steem.sharedInstance

You are strongly advised to setup Steem inside your AppDelegate (Please add an API Endpoint if you want to use the API)

steem.initialize(config: ["api": "https://api.steemit.com"])

Also inside your AppDelegate you should setup the OAuth Data (if you want to use it)

steem.auth.setConfig(conf: [
            "client_id": "<% YOUR CLIENT ID %>",
            "client_secret": "<% YOUR CLIENT SECRET %>",
            "authorize_uri": "https://v2.steemconnect.com/oauth2/authorize",
            "token_uri": "https://v2.steemconnect.com/api/oauth2/token",
            "redirect_uris": ["testauthapp://oauth/callback"], // CHANGE TO YOUR REDIRECT_URI
            "scope": "login,offline,vote,comment,custom_json", // ADD MORE
            "should_Debug": true, // IF YOU WANT TO RECEIVE DEBUG MESSAGES & VERBOSE STYLE
])

The last step inside the AppDelegate is to make use of the applicationOpenURL function:

func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
        if "testauthapp" == url.scheme {
            steem.auth.handleRedirectURL(url: url)
            return true
        }
        return false
    }

Simply copy & paste it and change testauthapp to your scheme you use in your redirect_uris!

Now we want to tell our App it should listen for schemes with the name testauthapp, to do so open your Info.plist and add following code:

<key>CFBundleURLTypes</key>
<array>
        <dict>
            <key>CFBundleTypeRole</key>
            <string>Viewer</string>
            <key>CFBundleURLName</key>
            <string>testauthapp</string>
            <key>CFBundleURLSchemes</key>
            <array>
                <string>testauthapp</string>
            </array>
        </dict>
</array>

SwiftyConnects 3 Classes

SwiftyConnects has 3 classes you can call from the Steem Class:

  • Auth (Authorize)
  • API (Fetch data)
  • Broadcast (Send data)

Authorization & Revoking

Use authorize to authorize the user and open the SteemConnect Login Page in Safari

steem.auth.authorize() { jsonResponse in
  print(jsonResponse)
}

authorize returns your user data, which can be used whether to check if the auth worked or to setup your user object.

To revoke your token use

steem.auth.revoke { (success) in
}

REMINDER: To completely logout of SteemConnect one has to open SteemConnect on your Safari Browser and logout. Otherwise you can't switch accounts (this is an behaviour by steemconnect... BUT I already developing a multi account management for them)

If you want to check if an user is logged in without calling an endpoint use steem.auth.isAuthorized()

Methods

public class Auth {

    public func setConfig(conf: NSDictionary)

    public func getConfig() -> NSDictionary

    public func isAuthorized() -> Bool

    public func revoke(callback: @escaping ((Bool) -> Swift.Void))

    public func handleRedirectURL(url: URL)

    public func me(callback: @escaping ((JSONString) -> Swift.Void))

    public func updateUserMetadata(userMetadata: JSONString, callback: @escaping ((JSONString) -> Swift.Void))

    public func authorize(callback: @escaping ((JSONString) -> Swift.Void))
}

Broadcasting

Broadcasting is used to send data to the blockchain, and requires a valid authorized account!

Methods

public class Broadcast {

    public func vote(voter: String, author: String, permlink: String, weight: Int, completion: ((JSONString) -> Swift.Void)?)

    public func reblog(account: String, author: String, permlink: String, completion: ((JSONString) -> Swift.Void)?)

    public func customJSON(account: String, json: JSONString, completion: ((JSONString) -> Swift.Void)?)

    public func follow(follower: String, following: String, completion: ((JSONString) -> Swift.Void)?)

    public func unfollow(unfollower: String, unfollowing: String, completion: ((JSONString) -> Swift.Void)?)

    public func ignore(follower: String, following: String, completion: ((JSONString) -> Swift.Void)?)

    public func claimRewardBalance(account: String, rewardSBD: String, rewardSteem: String, rewardVests: Int, completion: ((JSONString) -> Swift.Void)?)

    public func comment(parentAuthor: String?, parentPermlink: String?, author: String, permlink: String, title: String, body: String, jsonMetadata: SwiftySteem.JSONMetadata, completion: ((JSONString) -> Swift.Void)?)
}

All Methods return a JSON / NSDictionary, to know what they return simply test it and print it out.
If a method failed you can check if response["error"] is not nil, it will return the error.

API

The naming and usage of the API is the same as in SteemJS, check out their docu for all methods!
When fully tests are done I will provide a full documentation myself.

All Methods return a NSDictionary.

Reminder: There is a lack of Unit Tests for the API, currently I do not know if every method works as expected ! But try it out yourself, I guess most of them will work !

Known Errors

["error-code": 500, "error": "internal server error"]

This basically means your data is wrong or your action is invalid (e.g voting a post you already have voted)

Roadmap

  • V0.2:
    • Full API Unit Tests
    • Full API Documentation
  • V1.0:
    • Full Documentation
    • Sign Actions

How to contribute?

Create Pull Requests

GitHub Link

Proof for GitHub

Screen Shot 2018-02-23 at 10.47.12.png

benediktveith is my main GitHub account.
Check here for another proof



Posted on Utopian.io - Rewarding Open Source Contributors

Sort:  

Thank you for the contribution. It has been approved.

A project with great meaning, awesome! I hope it will be well adopted by the community! Keep up the great work!

You can contact us on Discord.
[utopian-moderator]

Hey @mkt, I just gave you a tip for your hard work on moderation. Upvote this comment to support the utopian moderators and increase your future rewards!

Thank you @mkt

I really hope some people will use it and create some great apps for iOS !
My intention was to open Steem to a whole new platform, let‘s hope it get integrated :)

Hey, I'm trying to use swiftyconnect but I'm having some problem, is there any way to get in contact with you or someone who can help fix the problem?

Is it steemconnect alternate? I didn't understand properly!

SwiftyConnect uses SteemConnect, it is just a swift (programming language) binding for it. Meaning you can use the same features as steemconnect provides for javascript / php.

Yes !! I Understand!
Thank you for your great contribution.

Hey @moonrise I am @utopian-io. I have just upvoted you!

Achievements

  • You have less than 500 followers. Just gave you a gift to help you succeed!
  • Seems like you contribute quite often. AMAZING!

Community-Driven Witness!

I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!

mooncryption-utopian-witness-gif

Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x

Coin Marketplace

STEEM 0.15
TRX 0.15
JST 0.028
BTC 53949.09
ETH 2223.84
USDT 1.00
SBD 2.31