Skip to content
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

APIProvider fails to authorize requests 25 minutes after sending the first request #137

Closed
abdulowork opened this issue Apr 7, 2021 · 2 comments · Fixed by #180
Closed
Labels

Comments

@abdulowork
Copy link

How to reproduce:

  1. Create an APIProvider and call any request.
  2. Sleep for 25 minutes and call another request.

Why it happens:

APIProvider holds a reference to JWTRequestsAuthenticator instance that manages requests authorization.

private lazy var requestsAuthenticator = JWTRequestsAuthenticator(apiConfiguration: self.configuration)

When JWTRequestsAuthenticator is instantiated it instantiates a JWT object that in turn creates a payload set with an expirationTime = Date().addingTimeInterval(expireDuration).timeIntervalSince1970.

self.jwtCreator = JWT(keyIdentifier: apiConfiguration.privateKeyID, issuerIdentifier: apiConfiguration.issuerID, expireDuration: 60 * 20)

public init(keyIdentifier: String, issuerIdentifier: String, expireDuration: TimeInterval, baseDate: Date = Date()) {
header = Header(keyIdentifier: keyIdentifier)
payload = Payload(issuerIdentifier: issuerIdentifier, expirationTime: baseDate.addingTimeInterval(expireDuration).timeIntervalSince1970)

The expirationTime is thus constant. When JWTRequestsAuthenticator renews the cachedToken, the new token is created with the original expirationTime which makes the jwt token invalid.

@github-actions
Copy link

github-actions bot commented May 8, 2021

This issue is stale because it has been open for 30 days with no activity. Remove the Stale label or comment or this will be closed in 10 days.

@github-actions github-actions bot added the Stale label May 8, 2021
@github-actions github-actions bot closed this as completed Jun 7, 2021
@jordibruin
Copy link
Contributor

@AvdLee was this fixed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants