@@ -11,6 +11,7 @@ import {
11
11
auth ,
12
12
type OAuthClientProvider ,
13
13
} from "./auth.js" ;
14
+ import { OAuthMetadata } from 'src/shared/auth.js' ;
14
15
15
16
// Mock fetch globally
16
17
const mockFetch = jest . fn ( ) ;
@@ -588,6 +589,13 @@ describe("OAuth Authorization", () => {
588
589
refresh_token : "refresh123" ,
589
590
} ;
590
591
592
+ const validMetadata = {
593
+ issuer : "https://auth.example.com" ,
594
+ authorization_endpoint : "https://auth.example.com/authorize" ,
595
+ token_endpoint : "https://auth.example.com/token" ,
596
+ response_types_supported : [ "code" ]
597
+ } ;
598
+
591
599
const validClientInfo = {
592
600
client_id : "client123" ,
593
601
client_secret : "secret123" ,
@@ -641,13 +649,15 @@ describe("OAuth Authorization", () => {
641
649
} ) ;
642
650
643
651
const tokens = await exchangeAuthorization ( "https://auth.example.com" , {
652
+ metadata : validMetadata ,
644
653
clientInformation : validClientInfo ,
645
654
authorizationCode : "code123" ,
646
655
codeVerifier : "verifier123" ,
647
656
redirectUri : "http://localhost:3000/callback" ,
648
- addClientAuthentication : ( headers : Headers , params : URLSearchParams , url : string | URL ) => {
657
+ addClientAuthentication : ( headers : Headers , params : URLSearchParams , url : string | URL , metadata : OAuthMetadata ) => {
649
658
headers . set ( "Authorization" , "Basic " + btoa ( validClientInfo . client_id + ":" + validClientInfo . client_secret ) ) ;
650
659
params . set ( "example_url" , typeof url === 'string' ? url : url . toString ( ) ) ;
660
+ params . set ( "example_metadata" , metadata . authorization_endpoint ) ;
651
661
params . set ( "example_param" , "example_value" ) ;
652
662
} ,
653
663
} ) ;
@@ -672,6 +682,7 @@ describe("OAuth Authorization", () => {
672
682
expect ( body . get ( "client_id" ) ) . toBeNull ( ) ;
673
683
expect ( body . get ( "redirect_uri" ) ) . toBe ( "http://localhost:3000/callback" ) ;
674
684
expect ( body . get ( "example_url" ) ) . toBe ( "https://auth.example.com" ) ;
685
+ expect ( body . get ( "example_metadata" ) ) . toBe ( "https://auth.example.com/authorize" ) ;
675
686
expect ( body . get ( "example_param" ) ) . toBe ( "example_value" ) ;
676
687
expect ( body . get ( "client_secret" ) ) . toBeNull ( ) ;
677
688
} ) ;
@@ -724,6 +735,13 @@ describe("OAuth Authorization", () => {
724
735
refresh_token : "newrefresh123" ,
725
736
} ;
726
737
738
+ const validMetadata = {
739
+ issuer : "https://auth.example.com" ,
740
+ authorization_endpoint : "https://auth.example.com/authorize" ,
741
+ token_endpoint : "https://auth.example.com/token" ,
742
+ response_types_supported : [ "code" ]
743
+ } ;
744
+
727
745
const validClientInfo = {
728
746
client_id : "client123" ,
729
747
client_secret : "secret123" ,
@@ -773,11 +791,13 @@ describe("OAuth Authorization", () => {
773
791
} ) ;
774
792
775
793
const tokens = await refreshAuthorization ( "https://auth.example.com" , {
794
+ metadata : validMetadata ,
776
795
clientInformation : validClientInfo ,
777
796
refreshToken : "refresh123" ,
778
- addClientAuthentication : ( headers : Headers , params : URLSearchParams , url : string | URL ) => {
797
+ addClientAuthentication : ( headers : Headers , params : URLSearchParams , url : string | URL , metadata : OAuthMetadata ) => {
779
798
headers . set ( "Authorization" , "Basic " + btoa ( validClientInfo . client_id + ":" + validClientInfo . client_secret ) ) ;
780
799
params . set ( "example_url" , typeof url === 'string' ? url : url . toString ( ) ) ;
800
+ params . set ( "example_metadata" , metadata . authorization_endpoint ) ;
781
801
params . set ( "example_param" , "example_value" ) ;
782
802
} ,
783
803
} ) ;
@@ -800,6 +820,7 @@ describe("OAuth Authorization", () => {
800
820
expect ( body . get ( "refresh_token" ) ) . toBe ( "refresh123" ) ;
801
821
expect ( body . get ( "client_id" ) ) . toBeNull ( ) ;
802
822
expect ( body . get ( "example_url" ) ) . toBe ( "https://auth.example.com" ) ;
823
+ expect ( body . get ( "example_metadata" ) ) . toBe ( "https://auth.example.com/authorize" ) ;
803
824
expect ( body . get ( "example_param" ) ) . toBe ( "example_value" ) ;
804
825
expect ( body . get ( "client_secret" ) ) . toBeNull ( ) ;
805
826
} ) ;
0 commit comments