Closed aspyre closed 6 years ago
Related Stack Overflow question (created by me): https://stackoverflow.com/questions/46397270/creating-accesstoken-from-tokenstring-with-uber-ios-sdk-failing
Hey @aspyre,
The tokenString
is meant to be just the access token itself, as you observed. If you want to parse the JSON itself, I would suggest using the fact that the model conforms to the Decodable
protocol, and pass in your JSON through that method.
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:
AccessTokenFactory.createAccessTokenFromJSONString(jsonString)
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!
@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).