我正在使用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)
}
}
}
任何帮助将不胜感激。谢谢:)
答案 0 :(得分:0)
我在Android中说了这一点(不确定是否会有所帮助),但事实证明,我在Web视图中输入了错误的客户ID。
一旦我将其更改为Twitch开发人员仪表板中的正确客户端ID,它就会拉动身份验证页面。另外,我将自己的家庭URL用作重定向,而不是localhost。不知道这是否有所作为。祝你好运!