【问题标题】:OAuth 2.0 ios swift implementationOAuth 2.0 ios 快速实现
【发布时间】:2015-04-22 07:35:57
【问题描述】:

我不确定是否可以在 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() 方法。请告诉我。谢谢

【问题讨论】:

    标签: ios swift github ios8 oauth-2.0


    【解决方案1】:

    这样做,

    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"

    【讨论】:

      猜你喜欢
      • 2012-04-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-30
      • 2020-10-14
      • 2013-03-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多