-
Notifications
You must be signed in to change notification settings - Fork 127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Creating AccessToken from string does not populate relevant properties #187
Comments
Related Stack Overflow question (created by me): https://stackoverflow.com/questions/46397270/creating-accesstoken-from-tokenstring-with-uber-ios-sdk-failing |
Hey @aspyre, The let decoder = JSONDecoder()
decoder.dateDecodingStrategy = .secondsSince1970
let accessToken = try? decoder.decode(AccessToken.self, from: jsonData)
// If you need to convert a string to data, use String.data(using: .utf8)! Looking at this question, I think it'll be a good idea to make it easier to initialize this object from JSON. I'll leave this issue open to address this. |
Thanks @edjiang for the reply, makes sense and not sure why I didn't connect that I can just use the JSONDecoder. In previous versions of the UberRides SDK the token was created like so, which did in fact populate all the properties as expected:
So, I think I was expecting something similar here. I agree it would be a good idea to make it easier when initializing from JSON, as I expect this would be the primary use case. |
To follow up on this, I believe there is still some work to be done. Two issues:
Of course, these are not particularly complicated, but it does creating an AccessToken object from https://login.uber.com/oauth/v2/token not the trivial task that it used to be. |
Thanks for reporting this. Definitely looks like some warts in here. I didn't realize that the implementation did #1, so I recommended that strategy in error. I'll get these cleaned up for you and fixed. :) |
Thanks for the follow up! |
* Adds two new initializers for AccessToken: `init(tokenString:refreshToken:expirationDate:grantedScopes:)` and `init?(oauthDictionary:)` * Makes `AccessTokenFactory` public * Adds additional test coverage to assert more parameters from JSON deserialization, and test new getters. * Adds comments to document `AccessToken`'s `NSCoding` behavior * Removes the `Codable` protocol from `AccessToken` since it won't be used for JSON serialization / deserialization
* Adds two new initializers for AccessToken: `init(tokenString:refreshToken:expirationDate:grantedScopes:)` and `init?(oauthDictionary:)` * Makes `AccessTokenFactory` public * Adds additional test coverage to assert more parameters from JSON deserialization, and test new getters. * Adds comments to document `AccessToken`'s `NSCoding` behavior * Removes the `Codable` protocol from `AccessToken` since it won't be used for JSON serialization / deserialization
@aspyre should be fixed in 0.8; let me know how it goes! https://github.com/uber/rides-ios-sdk/releases/tag/v0.8.0 |
@edjiang thanks for the note, and the fix! Looking good so far. |
I'm using custom authorisation with the Uber iOS SDK, and having trouble creating the AccessToken in my iOS code. This is the response I get from my server with what appears to be a valid access token:
I then pass this to the AccessToken initialiser, like so:
My access token is created (ie. non-nil), but none of the relevant property are populated.
Digging through the AccessToken.swift source file of the Uber project, I find this:
This means refreshToken and expiration date will never be populated.
It also means that API attempts fail, as the API is expecting the tokenString field to contain the actual access_token text, not the full text.
I have verified that if I initialise the AccessToken like so, then API requests succeed (at least until the access token expires).
The text was updated successfully, but these errors were encountered: