I'm trying to use the OAuthSwift library to get an authorization token for a user logging in with their Twitch account. I'm using the example code but I think there's an issue with Swift 5. I'm using XCode Version 10.3 (10G8):
// create an instance and retain it
oauthswift = OAuth2Swift(
consumerKey: "***",
consumerSecret: "***",
authorizeUrl: "https://id.twitch.tv/oauth2/validate",
responseType: "code"
)
oauthswift.accessTokenBasicAuthentification = true
//let codeVerifier = base64url("abcd...")
//let codeChallenge = codeChallenge(for: codeVerifier)
let handle = oauthswift.authorize(
withCallbackURL: URL(string: "localhost")!,
scope: "", state:"TWITCH") { result in
switch result {
case .success(let (credential, response, parameters)):
print(credential.oauthToken)
// Do your request
case .failure(let error):
print(error.localizedDescription)
}
}
}
I got an error on line oauthswift.accessTokenBasicAuthentification = true
:
Value of type 'OAuthSwift?' has no member 'accessTokenBasicAuthentification'
And then I get an error on the let handle =
line:
Value of type 'OAuthSwift?' has no member 'authorize'
Any help would be greatly appreciated.
Thanks!
EDIT: Might be an issue with Cocoapods. I can't do pod 'OAuthSwift', '~> 2.0.0', says it can't find that version. Just installing using pod 'OAuthSwift'
without the version number just installs v1.3.0
EDIT 2:
Got it! Thanks to Kiril I was able to update the library to v2 (I used pod install instead of pod update). Then once the library updated I had to use add the let
initializer. Updated code:
// create an instance and retain it
let oauthswift = OAuth2Swift(
consumerKey: "***",
consumerSecret: "***",
authorizeUrl: "https://id.twitch.tv/oauth2/validate",
responseType: "code"
)
self.oauthswift = oauthswift
oauthswift.accessTokenBasicAuthentification = true