我不确定是否可以在 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/