|
1 | | -import { BadRequestHttpError, createErrorMessage, JwkGenerator, KeyValueStorage } from '@solid/community-server'; |
| 1 | +import { BadRequestHttpError, createErrorMessage, ExpiringStorage, JwkGenerator, } from '@solid/community-server'; |
2 | 2 | import { getLoggerFor } from 'global-logger-factory'; |
3 | 3 | import { importJWK, jwtVerify, SignJWT } from 'jose'; |
| 4 | +import ms, { StringValue } from 'ms'; |
4 | 5 | import { randomUUID } from 'node:crypto'; |
5 | 6 | import { array, reType } from '../util/ReType'; |
6 | 7 | import { Permission } from '../views/Permission'; |
@@ -31,7 +32,7 @@ export class JwtTokenFactory extends TokenFactory { |
31 | 32 | constructor( |
32 | 33 | protected readonly keyGen: JwkGenerator, |
33 | 34 | protected readonly issuer: string, |
34 | | - protected readonly tokenStore: KeyValueStorage<string, AccessToken>, |
| 35 | + protected readonly tokenStore: ExpiringStorage<string, AccessToken>, |
35 | 36 | protected readonly params: JwtTokenParams = { expirationTime: '30m', aud: 'solid' }, |
36 | 37 | protected readonly addSub = false, |
37 | 38 | ) { |
@@ -61,9 +62,7 @@ export class JwtTokenFactory extends TokenFactory { |
61 | 62 | const jwt = await signJwt.sign(jwk); |
62 | 63 |
|
63 | 64 | this.logger.debug(`Issued new JWT Token ${JSON.stringify(token)}`); |
64 | | - // TODO: tokenstore should expire tokens eventually; can use expiring storage, |
65 | | - // or just normal store with timer-based cleanup. |
66 | | - await this.tokenStore.set(jwt, token); |
| 65 | + await this.tokenStore.set(jwt, token, ms(this.params.expirationTime as StringValue)); |
67 | 66 | return { token: jwt, tokenType: 'Bearer' }; |
68 | 67 | } |
69 | 68 |
|
|
0 commit comments