@@ -506,6 +506,9 @@ describe("OAuth Authorization", () => {
506
506
access_token : "newaccess123" ,
507
507
token_type : "Bearer" ,
508
508
expires_in : 3600 ,
509
+ }
510
+ const validTokensWithNewRefreshToken = {
511
+ ...validTokens ,
509
512
refresh_token : "newrefresh123" ,
510
513
} ;
511
514
@@ -520,15 +523,15 @@ describe("OAuth Authorization", () => {
520
523
mockFetch . mockResolvedValueOnce ( {
521
524
ok : true ,
522
525
status : 200 ,
523
- json : async ( ) => validTokens ,
526
+ json : async ( ) => validTokensWithNewRefreshToken ,
524
527
} ) ;
525
528
526
529
const tokens = await refreshAuthorization ( "https://auth.example.com" , {
527
530
clientInformation : validClientInfo ,
528
531
refreshToken : "refresh123" ,
529
532
} ) ;
530
533
531
- expect ( tokens ) . toEqual ( validTokens ) ;
534
+ expect ( tokens ) . toEqual ( validTokensWithNewRefreshToken ) ;
532
535
expect ( mockFetch ) . toHaveBeenCalledWith (
533
536
expect . objectContaining ( {
534
537
href : "https://auth.example.com/token" ,
@@ -548,6 +551,22 @@ describe("OAuth Authorization", () => {
548
551
expect ( body . get ( "client_secret" ) ) . toBe ( "secret123" ) ;
549
552
} ) ;
550
553
554
+ it ( "exchanges refresh token for new tokens and keep existing refresh token if none is returned" , async ( ) => {
555
+ mockFetch . mockResolvedValueOnce ( {
556
+ ok : true ,
557
+ status : 200 ,
558
+ json : async ( ) => validTokens ,
559
+ } ) ;
560
+
561
+ const refreshToken = "refresh123" ;
562
+ const tokens = await refreshAuthorization ( "https://auth.example.com" , {
563
+ clientInformation : validClientInfo ,
564
+ refreshToken,
565
+ } ) ;
566
+
567
+ expect ( tokens ) . toEqual ( { refresh_token : refreshToken , ...validTokens } ) ;
568
+ } ) ;
569
+
551
570
it ( "validates token response schema" , async ( ) => {
552
571
mockFetch . mockResolvedValueOnce ( {
553
572
ok : true ,
0 commit comments