1- import { BadRequestHttpError , createErrorMessage , JwkGenerator , KeyValueStorage } from '@solid/community-server' ;
1+ import { BadRequestHttpError , createErrorMessage , ExpiringStorage , JwkGenerator , } from '@solid/community-server' ;
22import { getLoggerFor } from 'global-logger-factory' ;
33import { importJWK , jwtVerify , SignJWT } from 'jose' ;
4+ import ms , { StringValue } from 'ms' ;
45import { randomUUID } from 'node:crypto' ;
56import { array , reType } from '../util/ReType' ;
67import { Permission } from '../views/Permission' ;
@@ -30,7 +31,7 @@ export class JwtTokenFactory extends TokenFactory {
3031 constructor (
3132 protected readonly keyGen : JwkGenerator ,
3233 protected readonly issuer : string ,
33- protected readonly tokenStore : KeyValueStorage < string , AccessToken > ,
34+ protected readonly tokenStore : ExpiringStorage < string , AccessToken > ,
3435 protected readonly params : JwtTokenParams = { expirationTime : '30m' , aud : 'solid' } ,
3536 ) {
3637 super ( ) ;
@@ -54,9 +55,7 @@ export class JwtTokenFactory extends TokenFactory {
5455 . sign ( jwk ) ;
5556
5657 this . logger . debug ( `Issued new JWT Token ${ JSON . stringify ( token ) } ` ) ;
57- // TODO: tokenstore should expire tokens eventually; can use expiring storage,
58- // or just normal store with timer-based cleanup.
59- await this . tokenStore . set ( jwt , token ) ;
58+ await this . tokenStore . set ( jwt , token , ms ( this . params . expirationTime as StringValue ) ) ;
6059 return { token : jwt , tokenType : 'Bearer' } ;
6160 }
6261
0 commit comments