13
13
* under the License.
14
14
*/
15
15
16
- const { printPath, setupST, startSTWithMultitenancy, killAllST, cleanST, removeAppAndTenants } = require ( "../utils" ) ;
16
+ const { printPath, setupST, startSTWithMultitenancy, killAllST, cleanST } = require ( "../utils" ) ;
17
17
let STExpress = require ( "../../" ) ;
18
18
let assert = require ( "assert" ) ;
19
19
let { ProcessState } = require ( "../../lib/build/processState" ) ;
20
20
let ThirdPartyRecipe = require ( "../../lib/build/recipe/thirdparty/recipe" ) . default ;
21
21
let Multitenancy = require ( "../../lib/build/recipe/multitenancy" ) ;
22
- let Session = require ( "../../lib/build/recipe/session" ) ;
23
22
let ThirdParty = require ( "../../lib/build/recipe/thirdparty" ) ;
24
- let nock = require ( "nock" ) ;
25
- const express = require ( "express" ) ;
26
- const request = require ( "supertest" ) ;
27
- const { default : fetch } = require ( "cross-fetch" ) ;
28
- let { middleware, errorHandler } = require ( "../../framework/express" ) ;
29
- const { configsForVerification, providers } = require ( "./tpConfigsForVerification" ) ;
30
23
31
24
describe ( `oidcTest: ${ printPath ( "[test/thirdparty/oidc.test.js]" ) } ` , function ( ) {
32
25
beforeEach ( async function ( ) {
@@ -40,7 +33,7 @@ describe(`oidcTest: ${printPath("[test/thirdparty/oidc.test.js]")}`, function ()
40
33
await cleanST ( ) ;
41
34
} ) ;
42
35
43
- it ( "test the code challenge method is used if supported by the provider" , async function ( ) {
36
+ it ( "should use code challenge method S256 if supported by the provider" , async function ( ) {
44
37
const connectionURI = await startSTWithMultitenancy ( ) ;
45
38
46
39
STExpress . init ( {
@@ -91,4 +84,102 @@ describe(`oidcTest: ${printPath("[test/thirdparty/oidc.test.js]")}`, function ()
91
84
assert . ok ( codeChallengeMethod ) ;
92
85
assert . strictEqual ( codeChallengeMethod , "S256" ) ;
93
86
} ) ;
87
+
88
+ it ( "should not use pkce if oidc response does not support S256" , async function ( ) {
89
+ const connectionURI = await startSTWithMultitenancy ( ) ;
90
+
91
+ STExpress . init ( {
92
+ supertokens : {
93
+ connectionURI,
94
+ } ,
95
+ appInfo : {
96
+ apiDomain : "api.supertokens.io" ,
97
+ appName : "SuperTokens" ,
98
+ websiteDomain : "supertokens.io" ,
99
+ } ,
100
+ recipeList : [ ThirdPartyRecipe . init ( ) ] ,
101
+ } ) ;
102
+
103
+ await Multitenancy . createOrUpdateThirdPartyConfig ( "public" , {
104
+ thirdPartyId : "custom-fb" ,
105
+ name : "Custom provider" ,
106
+ clients : [
107
+ {
108
+ clientId : "..." ,
109
+ clientSecret : "..." ,
110
+ scope : [ "profile" , "email" ] ,
111
+ } ,
112
+ ] ,
113
+ oidcDiscoveryEndpoint : "https://facebook.com/.well-known/openid-configuration" ,
114
+ userInfoMap : {
115
+ fromIdTokenPayload : {
116
+ userId : "id" ,
117
+ email : "email" ,
118
+ emailVerified : "email_verified" ,
119
+ } ,
120
+ } ,
121
+ } ) ;
122
+
123
+ const providerInfo = await ThirdParty . getProvider ( "public" , "custom-fb" ) ;
124
+ assert . deepStrictEqual ( providerInfo . config . codeChallengeMethodsSupported , undefined ) ;
125
+
126
+ const authUrl = await providerInfo . getAuthorisationRedirectURL ( {
127
+ redirectURIOnProviderDashboard : "http://localhost:3000/callback" ,
128
+ } ) ;
129
+ assert . strictEqual ( authUrl . urlWithQueryParams . includes ( "code_challenge" ) , false ) ;
130
+ assert . strictEqual ( authUrl . urlWithQueryParams . includes ( "code_challenge_method" ) , false ) ;
131
+ } ) ;
132
+
133
+ it ( "should use pkce if oidc response does not support S256 but forcePKCE is true" , async function ( ) {
134
+ const connectionURI = await startSTWithMultitenancy ( ) ;
135
+
136
+ STExpress . init ( {
137
+ supertokens : {
138
+ connectionURI,
139
+ } ,
140
+ appInfo : {
141
+ apiDomain : "api.supertokens.io" ,
142
+ appName : "SuperTokens" ,
143
+ websiteDomain : "supertokens.io" ,
144
+ } ,
145
+ recipeList : [ ThirdPartyRecipe . init ( ) ] ,
146
+ } ) ;
147
+
148
+ await Multitenancy . createOrUpdateThirdPartyConfig ( "public" , {
149
+ thirdPartyId : "custom-fb" ,
150
+ name : "Custom provider" ,
151
+ clients : [
152
+ {
153
+ clientId : "..." ,
154
+ clientSecret : "..." ,
155
+ scope : [ "profile" , "email" ] ,
156
+ forcePKCE : true ,
157
+ } ,
158
+ ] ,
159
+ oidcDiscoveryEndpoint : "https://facebook.com/.well-known/openid-configuration" ,
160
+ userInfoMap : {
161
+ fromIdTokenPayload : {
162
+ userId : "id" ,
163
+ email : "email" ,
164
+ emailVerified : "email_verified" ,
165
+ } ,
166
+ } ,
167
+ } ) ;
168
+
169
+ const providerInfo = await ThirdParty . getProvider ( "public" , "custom-fb" ) ;
170
+ assert . deepStrictEqual ( providerInfo . config . codeChallengeMethodsSupported , undefined ) ;
171
+
172
+ const authUrl = await providerInfo . getAuthorisationRedirectURL ( {
173
+ redirectURIOnProviderDashboard : "http://localhost:3000/callback" ,
174
+ } ) ;
175
+ assert . ok ( authUrl . pkceCodeVerifier ) ;
176
+ const authUrlObject = new URL ( authUrl . urlWithQueryParams ) ;
177
+ const codeChallengeMethod = authUrlObject . searchParams . get ( "code_challenge_method" ) ;
178
+ const codeChallenge = authUrlObject . searchParams . get ( "code_challenge" ) ;
179
+
180
+ // Check for existence of code_challenge and code_challenge_method
181
+ assert . ok ( codeChallenge ) ;
182
+ assert . ok ( codeChallengeMethod ) ;
183
+ assert . strictEqual ( codeChallengeMethod , "S256" ) ;
184
+ } ) ;
94
185
} ) ;
0 commit comments