我正在使用 OAuthSwift 将用户发送到 Twitch 以授权我的应用程序。但是,一旦应用程序获得授权,用户就不会被送回我的应用程序。我收到一条消息,出现在 Safari 中:
You are about to leave Twitch. Twitch has no control over the content or security of http://localhost.
我试图在 AppDelegate 中处理这个问题,但它似乎没有重定向:
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
if (url.host == "http://localhost") {
OAuthSwift.handle(url: url)
}
return true
}
这是触发 Twitch 身份验证的代码:
@IBAction func didPressLoginButton(_ sender: Any) {
// create an instance and retain it
let oauthswift = OAuth2Swift(
consumerKey: "xxxxx",
consumerSecret: "xxxxx",
authorizeUrl: "https://id.twitch.tv/oauth2/authorize",
accessTokenUrl: "https://id.twitch.tv/oauth2/token",
responseType: "code",
contentType: "application/json"
)
oauthswift.authorizeURLHandler = OAuthSwiftOpenURLExternally.sharedInstance
self.oauthswift = oauthswift
//oauthswift.accessTokenBasicAuthentification = true
//let codeVerifier = base64url("abcd...")
//let codeChallenge = codeChallenge(for: codeVerifier)
let handle = oauthswift.authorize(withCallbackURL: URL(string: "http://localhost")!, scope: "user:read:email", state:"TWITCH") { result in
switch result {
case .success(let (credential, response, parameters)):
print(credential.oauthToken)
TwitchTokenManager.shared.accessToken = credential.oauthToken
//Twitch.Clips.getClips
// Do your request
case .failure(let error):
print(error.localizedDescription)
}
}
}
任何帮助将不胜感激。谢谢 :)