ios - OAuth 2.0 ios 快速实现

标签 ios swift github ios8 oauth-2.0

我不确定是否可以在 stackoverflow 中询问 github 相关源代码的问题,但我一直在尝试理解代码库。

来源:https://github.com/gabriel-jones/OAuthSwift

我正在尝试将 OAuth2.0 集成到我的项目中以进行各种身份验证。 在 read.md 上,它说

 let oauthswift = OAuth2Swift(
    consumerKey:    "********",
    consumerSecret: "********",
    authorizeUrl:   "https://api.instagram.com/oauth/authorize",
    responseType:   "token"
)

oauthswift.authorizeWithCallbackURL( NSURL(string: "oauth-                    swift://oauth-callback/instagram"), scope: "likes+comments",   state:"INSTAGRAM", success: {credential, response in
println(credential.oauth_token) }, failure: failureHandler) 

我不明白如何将成功作为参数发送?

我试过类似的东西:

    var credential =  OAuthSwiftCredential(consumer_key: "****", consumer_secret: "****")
    var response : NSHTTPURLResponse? = nil

    oauthswift.authorizeWithCallbackURL(callbackURL: NSURL(string: "oauth-swift://oauth-callback/"), scope: "***", state: "****", params: emptyDictionary, success: {
        credential, response
    }, failure: failureHandler())

我查看了实现类,但似乎没有掌握如何调用 authorizeWithCallbackURL() 方法。请让我知道。谢谢

最佳答案

这样做,

oauthswift.authorizeWithCallbackURL( NSURL(string: encodedCallBackUrl!)!, scope: "your%20scope", state: state, success: {
        credential, response in
        // Success
        println(credential.oauth_token)


        }, failure: {(error:NSError!) -> Void in

        // Failure 

            println(error.localizedDescription)
    })

请在上面的代码中将您的范围更改为您想要的 scope: "your%20scope"

关于ios - OAuth 2.0 ios 快速实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29790763/

相关文章:

ios - 在设备上部署时如何将参数传递给 IPA?

ios - 将单元委托(delegate)添加到类时出错 - swift

ios - 我可以仅使用 appStoreConnect 帐户将应用程序放入 TestFlight 中吗

ios - 制作 Tabbar Controller rootViewController

Github 部署 key : How do I authorize more than one repository for a single machine?

ios - 无法使用退格键从 iOS 中的文本字段中删除字符

ios - 在 iphone 6 中从后台重新打开时应用程序崩溃

swift - 如何在swift中调用piccure边框的扩展文件

git - 奇怪的 git 行为在 pull 上游 merge 后恢复本地分支中所做的更改

Git 克隆到当前目录