-
Notifications
You must be signed in to change notification settings - Fork 2
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
Authorization Refresh #3
Conversation
767b90a
to
c7539ae
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks again! This was something that was on my todo list
I haven't set up CI yet, so could you execute
swift format --in-place --recursive --parallel .
to format the files?
extension TokenResponse { | ||
|
||
/// A boolean indicates weather to token is valid 10 seconds before it's actual expiry time. | ||
var isValid: Bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this doesn't ever become false, as the Date.now
is new every time and expiresInSeconds
doesn't get updated since the response is received.
Maybe we can add a private expirationDate
property to TokenResponse
to which we assign Date.now.addingTimeInterval(TimeInterval(expiresInSeconds))
when the TokenResponse
gets initialized
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it's a very good point, sorry for that.
I will push a fix and write a test for it.
2db24de
to
7bcfcdc
Compare
@fpseverino I fixed it, and added a test against it. if you have some idea on how to improve it let me know. |
I improved it, and now tests take 2 seconds. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, I'll add CI, run swift-format
and update the DocC, then I'll release a new version.
Thanks again!
Thank you 🙏🏻 |
Currently if the token is expired, every request after it fails and there is no way of refreshing it since it's being done on the client init.
this PR introduces better authorization handling, with the following changes:
The refresh flow is inspired by this article:
Building a token refresh flow with async/await and Swift Concurrency