@@ -18,13 +18,16 @@ describe("generateAuthUrl", () => {
18
18
state : "state123" ,
19
19
} ;
20
20
const expectedUrl =
21
- "https://auth.example.com/oauth2/auth?client_id=client123&response_type=code&start_page=login&login_hint=user%40example.com&is_create_org=true&connection_id=conn123&redirect_uri=https%3A%2F%2Fexample.com&audience=audience123&scope=openid+profile&prompt=login&state=state123" ;
21
+ "https://auth.example.com/oauth2/auth?client_id=client123&response_type=code&start_page=login&login_hint=user%40example.com&is_create_org=true&connection_id=conn123&redirect_uri=https%3A%2F%2Fexample.com&audience=audience123&scope=openid+profile&prompt=login&state=state123&code_challenge_method=S256 " ;
22
22
23
23
const result = generateAuthUrl ( domain , IssuerRouteTypes . login , options ) ;
24
24
const nonce = result . url . searchParams . get ( "nonce" ) ;
25
25
expect ( nonce ) . not . toBeNull ( ) ;
26
26
expect ( nonce ! . length ) . toBe ( 16 ) ;
27
27
result . url . searchParams . delete ( "nonce" ) ;
28
+ const codeChallenge = result . url . searchParams . get ( "code_challenge" ) ;
29
+ expect ( codeChallenge ! . length ) . toBe ( 32 ) ;
30
+ result . url . searchParams . delete ( "code_challenge" ) ;
28
31
expect ( result . url . toString ( ) ) . toBe ( expectedUrl ) ;
29
32
} ) ;
30
33
@@ -41,13 +44,14 @@ describe("generateAuthUrl", () => {
41
44
prompt : "create" ,
42
45
} ;
43
46
const expectedUrl =
44
- "https://auth.example.com/oauth2/auth?client_id=client123&response_type=code&start_page=login&redirect_uri=https%3A%2F%2Fexample2.com&scope=openid+profile&prompt=create&state=state123&code_challenge=challenge123&code_challenge_method=S256" ;
47
+ "https://auth.example.com/oauth2/auth?client_id=client123&response_type=code&start_page=login&redirect_uri=https%3A%2F%2Fexample2.com&audience=& scope=openid+profile&prompt=create&state=state123&code_challenge=challenge123&code_challenge_method=S256" ;
45
48
46
49
const result = generateAuthUrl ( domain , IssuerRouteTypes . login , options ) ;
47
50
const nonce = result . url . searchParams . get ( "nonce" ) ;
48
51
expect ( nonce ) . not . toBeNull ( ) ;
49
52
expect ( nonce ! . length ) . toBe ( 16 ) ;
50
53
result . url . searchParams . delete ( "nonce" ) ;
54
+
51
55
expect ( result . url . toString ( ) ) . toBe ( expectedUrl ) ;
52
56
} ) ;
53
57
@@ -61,13 +65,18 @@ describe("generateAuthUrl", () => {
61
65
state : "state123" ,
62
66
} ;
63
67
const expectedUrl =
64
- "https://auth.example.com/oauth2/auth?client_id=client123&response_type=code&start_page=login&redirect_uri=https%3A%2F%2Fexample2.com&scope=openid+profile+offline&prompt=create&state=state123" ;
68
+ "https://auth.example.com/oauth2/auth?client_id=client123&response_type=code&start_page=login&redirect_uri=https%3A%2F%2Fexample2.com&audience=& scope=openid+profile+offline&prompt=create&state=state123&code_challenge_method=S256 " ;
65
69
66
70
const result = generateAuthUrl ( domain , IssuerRouteTypes . login , options ) ;
67
71
const nonce = result . url . searchParams . get ( "nonce" ) ;
68
72
expect ( nonce ) . not . toBeNull ( ) ;
69
73
expect ( nonce ! . length ) . toBe ( 16 ) ;
70
74
result . url . searchParams . delete ( "nonce" ) ;
75
+
76
+ const codeChallenge = result . url . searchParams . get ( "code_challenge" ) ;
77
+ expect ( codeChallenge ! . length ) . toBe ( 32 ) ;
78
+ result . url . searchParams . delete ( "code_challenge" ) ;
79
+
71
80
expect ( result . url . toString ( ) ) . toBe ( expectedUrl ) ;
72
81
} ) ;
73
82
@@ -80,7 +89,7 @@ describe("generateAuthUrl", () => {
80
89
prompt : "create" ,
81
90
} ;
82
91
const expectedUrl =
83
- "https://auth.example.com/oauth2/auth?client_id=client123&response_type=code&start_page=login&redirect_uri=https%3A%2F%2Fexample2.com&scope=openid+profile+offline&prompt=create" ;
92
+ "https://auth.example.com/oauth2/auth?client_id=client123&response_type=code&start_page=login&redirect_uri=https%3A%2F%2Fexample2.com&audience=& scope=openid+profile+offline&prompt=create&code_challenge_method=S256 " ;
84
93
85
94
const result = generateAuthUrl ( domain , IssuerRouteTypes . login , options ) ;
86
95
const nonce = result . url . searchParams . get ( "nonce" ) ;
@@ -89,6 +98,9 @@ describe("generateAuthUrl", () => {
89
98
const state = result . url . searchParams . get ( "state" ) ;
90
99
expect ( state ) . not . toBeNull ( ) ;
91
100
expect ( state ! . length ) . toBe ( 32 ) ;
101
+ const codeChallenge = result . url . searchParams . get ( "code_challenge" ) ;
102
+ expect ( codeChallenge ! . length ) . toBe ( 32 ) ;
103
+ result . url . searchParams . delete ( "code_challenge" ) ;
92
104
result . url . searchParams . delete ( "nonce" ) ;
93
105
result . url . searchParams . delete ( "state" ) ;
94
106
expect ( result . url . toString ( ) ) . toBe ( expectedUrl ) ;
0 commit comments