[英]Oauth2 facebook callback swift
I want to login to Facebook and redirect to my app but I have a problem. 我想登录Facebook并重定向到我的应用程序,但是我遇到了问题。 There is my code: 有我的代码:
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 捆绑ID是myapp.test
Info.plist: 信息清单:
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>myapp.test</string>
</array>
</dict>
</array>
When I try to redirect into my app "Safari cannot open the page because the server cannot be found" 当我尝试重定向到我的应用程序时,“ Safari无法打开页面,因为找不到服务器”
In developers.facebook.com page in the section "Valid OAuth redirect URIs" I have same url " https://myapp.test/callback/facebook ". 在developers.facebook.com页面的“有效OAuth重定向URI”部分中,我具有相同的网址“ https://myapp.test/callback/facebook ”。 What I am doing wrong? 我做错了什么? Thank you. 谢谢。
If you want OAuth to open your app after the authentication, the redirect URL should be myapp.test://callback/facebook
, not https://...
. 如果您希望OAuth在身份验证后打开您的应用,则重定向URL应该是myapp.test://callback/facebook
,而不是https://...
Otherwise it will simply try to open this URL inside safari. 否则,它将简单地尝试在野生动物园中打开此URL。
Let me know if that helps. 让我知道是否有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.