【问题标题】:Oauth2 facebook callback swiftOauth2 facebook回调迅速
【发布时间】:2018-08-28 14:52:22
【问题描述】:

我想登录 Facebook 并重定向到我的应用,但我遇到了问题。有我的代码:

 let oauthswift = OAuth2Swift(
                consumerKey:    "4242424242",
                consumerSecret: "",
                authorizeUrl:   "https://www.facebook.com/dialog/oauth",
                accessTokenUrl: "https://graph.facebook.com/oauth/access_token",
                responseType:   "code"
            )
oauthswift.authorizeURLHandler = SafariURLHandler(viewController: self, oauthSwift: oauthswift)
          let state = generateState(withLength: 20)
          guard let rwURL = URL(string:"https://myapp.test/callback/facebook") else { return }
         let _ = oauthswift.authorize( withCallbackURL:rwURL, scope: "public_profile", state: state,
                success: { credential, response, parameters in
                  ..........}

Bundle is ID is myapp.test

Info.plist:

 <key>CFBundleURLTypes</key>
        <array>
            <dict>
                <key>CFBundleURLSchemes</key>
                <array>
                    <string>myapp.test</string>
                </array>
            </dict>
        </array>

当我尝试重定向到我的应用程序时“Safari 无法打开页面,因为找不到服务器”

在“有效 OAuth 重定向 URI”部分的 developers.facebook.com 页面中,我有相同的 url“https://myapp.test/callback/facebook”。我做错了什么? 谢谢。

【问题讨论】:

    标签: ios swift facebook oauth-2.0 facebook-oauth


    【解决方案1】:

    如果您希望 OAuth 在身份验证后打开您的应用,则重定向 URL 应为 myapp.test://callback/facebook,而不是 https://...。否则它只会尝试在 safari 中打开此 URL。

    如果有帮助,请告诉我。

    【讨论】:

    • 在这种情况下,我在 safari 中的重定向 url 是:(facebook.com/dialog/…),错误是:重定向 url 必须是绝对的
    • 尝试以下操作:myapp://oauth-callback(并且不要忘记将myapp 添加为 URL 方案)。当我删除第一部分中的点或您的 URI 时,它会将错误切换为 The redirect_uri URL is not supported,因此这可能是它对您不起作用的原因。此线程也可能对您有所帮助:stackoverflow.com/questions/33788368/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-22
    • 2017-03-15
    • 1970-01-01
    • 2013-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多