File tree Expand file tree Collapse file tree 2 files changed +34
-2
lines changed
Expand file tree Collapse file tree 2 files changed +34
-2
lines changed Original file line number Diff line number Diff line change @@ -522,6 +522,38 @@ describe("create-client", () => {
522522 expect ( accessToken ) . toEqual ( expect . stringMatching ( / \. e y J / ) ) ;
523523 scope . done ( ) ;
524524 } ) ;
525+
526+ it ( "refreshes the access token when forceRefresh is true" , async ( ) => {
527+ // First create a client with a valid (non-expired) token
528+ const { scope : initialScope } = nockRefresh ( {
529+ accessTokenClaims : {
530+ jti : "initial-token" ,
531+ // Set future expiration
532+ exp : Date . now ( ) / 1000 + 3600 ,
533+ } ,
534+ } ) ;
535+
536+ client = await createClient ( "client_123abc" , {
537+ redirectUri : "https://example.com/" ,
538+ } ) ;
539+ initialScope . done ( ) ;
540+
541+ // Setup a refresh response for the forced refresh
542+ const { scope : refreshScope } = nockRefresh ( {
543+ accessTokenClaims : {
544+ jti : "forced-refresh-token" ,
545+ } ,
546+ } ) ;
547+
548+ // Get the token with forceRefresh: true
549+ const accessToken = await client . getAccessToken ( {
550+ forceRefresh : true ,
551+ } ) ;
552+
553+ // Verify the token was refreshed
554+ expect ( getClaims ( accessToken ) . jti ) . toEqual ( "forced-refresh-token" ) ;
555+ refreshScope . done ( ) ;
556+ } ) ;
525557 } ) ;
526558
527559 describe ( "when the current session is not authenticated" , ( ) => {
Original file line number Diff line number Diff line change @@ -140,8 +140,8 @@ export class Client {
140140 }
141141 }
142142
143- async getAccessToken ( ) : Promise < string > {
144- if ( this . #shouldRefresh( ) ) {
143+ async getAccessToken ( options ?: { forceRefresh ?: boolean } ) : Promise < string > {
144+ if ( options ?. forceRefresh || this . #shouldRefresh( ) ) {
145145 try {
146146 await this . #refreshSession( ) ;
147147 } catch ( err ) {
You can’t perform that action at this time.
0 commit comments