refreshableCredentialFromAccessToken projects an OAuth access token onto gh.RefreshableCredential. It derives each absolute expiry by adding the server-reported lifetime (ExpiresIn) to requestedAt, the instant the exchange was initiated, rather than trusting any absolute time from the OAuth library.
(token *oauthapi.AccessToken, requestedAt time.Time)
| 84 | // server issued the token, the derived expiry is never later than the true expiry. A zero lifetime maps to a nil |
| 85 | // pointer so the refresh gating treats the credential as non-expiring rather than already expired. |
| 86 | func refreshableCredentialFromAccessToken(token *oauthapi.AccessToken, requestedAt time.Time) gh.RefreshableCredential { |
| 87 | credential := gh.RefreshableCredential{ |
| 88 | AccessToken: token.Token, |
| 89 | RefreshToken: token.RefreshToken, |
| 90 | ExpiresIn: int(token.ExpiresIn / time.Second), |
| 91 | RefreshTokenExpiresIn: int(token.RefreshTokenExpiresIn / time.Second), |
| 92 | } |
| 93 | if token.ExpiresIn > 0 { |
| 94 | credential.ExpiresAt = new(requestedAt.Add(token.ExpiresIn)) |
| 95 | } |
| 96 | if token.RefreshTokenExpiresIn > 0 { |
| 97 | credential.RefreshTokenExpiresAt = new(requestedAt.Add(token.RefreshTokenExpiresIn)) |
| 98 | } |
| 99 | return credential |
| 100 | } |
| 101 | |
| 102 | // credentialFromAccessToken projects an OAuth access token onto gh.Credential, reusing |
| 103 | // refreshableCredentialFromAccessToken so the expiry mapping lives in one place. requestedAt is the instant the |
no outgoing calls
no test coverage detected