(
clientId: string,
scopes: string[],
resource?: URL,
consumedRefreshTokenHash?: string,
)
| 272 | } |
| 273 | |
| 274 | private issueTokens( |
| 275 | clientId: string, |
| 276 | scopes: string[], |
| 277 | resource?: URL, |
| 278 | consumedRefreshTokenHash?: string, |
| 279 | ): OAuthTokens { |
| 280 | const now = Math.floor(Date.now() / 1000); |
| 281 | const accessToken = randomToken(); |
| 282 | const refreshToken = randomToken(); |
| 283 | const accessExpiresAt = now + this.config.accessTokenTtlSeconds; |
| 284 | const refreshExpiresAt = now + this.config.refreshTokenTtlSeconds; |
| 285 | |
| 286 | const saved = this.oauthStore.saveTokenPair( |
| 287 | { |
| 288 | accessTokenHash: hashToken(accessToken), |
| 289 | accessToken: { |
| 290 | clientId, |
| 291 | scopes, |
| 292 | expiresAt: accessExpiresAt, |
| 293 | resource: resource?.href, |
| 294 | }, |
| 295 | refreshTokenHash: hashToken(refreshToken), |
| 296 | refreshToken: { |
| 297 | clientId, |
| 298 | scopes, |
| 299 | expiresAt: refreshExpiresAt, |
| 300 | resource: resource?.href, |
| 301 | }, |
| 302 | }, |
| 303 | consumedRefreshTokenHash, |
| 304 | ); |
| 305 | if (!saved) { |
| 306 | throw new InvalidGrantError("Invalid refresh token"); |
| 307 | } |
| 308 | |
| 309 | return { |
| 310 | access_token: accessToken, |
| 311 | token_type: "bearer", |
| 312 | expires_in: this.config.accessTokenTtlSeconds, |
| 313 | refresh_token: refreshToken, |
| 314 | scope: scopes.join(" "), |
| 315 | }; |
| 316 | } |
| 317 | } |
| 318 | |
| 319 | function authorizationFormFields( |
no test coverage detected