I have an issue where I am not sure If I am doing anything wrong or if there is an issue with 2.0 token.
When I initiate the app and login by authorizing the user like so:
let oauthUser = try await Twift.Authentication().authenticateUser(
clientId: Constants.clientID,
redirectUri: URL(string: Constants.urlScheme)!,
scope: Set(OAuth2Scope.allCases),
presentationContextProvider: nil)
client = Twift(.oauth2UserAuth(oauthUser))
UserDefaults.encodeUser(user: oauthUser)
self.oauthUser = oauthUser
completion(true)
Everything works fine (UserDefaults storing is temporary)
But after launching the app for example...few hours later, same build in xcode, I use the path:
if let oauthUser = UserDefaults.decodeUser() {
client = Twift(.oauth2UserAuth(oauthUser))
completion(true)
However, the call I make after this, using the said client, fails to get a response other than Unauthorised
When I follow the call, refresh is not used as authToken is valid, and by checking expiresIn
myself, I saw that is true.
So, seems that the client is not initiated/authorized then?
The only difference in two flows is that first one uses authenticateUser
and second one does not, but I am storing that user properly (I read it before and after storing and it seems 👌)
Here is the call that gets invalid response"
https://api.twitter.com/2/users/me?user.fields=description,profile_image_url
with token:
Bearer akNhMEZxTklrSU1ZV19TVS1qM2FSenRmdmdlWm9OZ0x6dTd6WktzUWlzZmE0OjE2NTQxMTE1MDg1NTE6MTowOmF0OjE
Update:
If I perform the force refresh, everything is fine 🤷♂️.
client?.refreshOAuth2AccessToken()
So maybe the Twift(.oauth2UserAuth(oauthUser))
just needs to be async?
Hope I am not talking out my ass here, just typing this as I debug 😂