File tree 2 files changed +33
-1
lines changed
2 files changed +33
-1
lines changed Original file line number Diff line number Diff line change @@ -177,6 +177,31 @@ describe("OAuth Authorization", () => {
177
177
expect ( codeVerifier ) . toBe ( "test_verifier" ) ;
178
178
} ) ;
179
179
180
+ it ( "includes scope parameter when provided" , async ( ) => {
181
+ const { authorizationUrl } = await startAuthorization (
182
+ "https://auth.example.com" ,
183
+ {
184
+ clientInformation : validClientInfo ,
185
+ redirectUrl : "http://localhost:3000/callback" ,
186
+ scope : "read write profile" ,
187
+ }
188
+ ) ;
189
+
190
+ expect ( authorizationUrl . searchParams . get ( "scope" ) ) . toBe ( "read write profile" ) ;
191
+ } ) ;
192
+
193
+ it ( "excludes scope parameter when not provided" , async ( ) => {
194
+ const { authorizationUrl } = await startAuthorization (
195
+ "https://auth.example.com" ,
196
+ {
197
+ clientInformation : validClientInfo ,
198
+ redirectUrl : "http://localhost:3000/callback" ,
199
+ }
200
+ ) ;
201
+
202
+ expect ( authorizationUrl . searchParams . has ( "scope" ) ) . toBe ( false ) ;
203
+ } ) ;
204
+
180
205
it ( "uses metadata authorization_endpoint when provided" , async ( ) => {
181
206
const { authorizationUrl } = await startAuthorization (
182
207
"https://auth.example.com" ,
Original file line number Diff line number Diff line change @@ -145,7 +145,8 @@ export async function auth(
145
145
const { authorizationUrl, codeVerifier } = await startAuthorization ( serverUrl , {
146
146
metadata,
147
147
clientInformation,
148
- redirectUrl : provider . redirectUrl
148
+ redirectUrl : provider . redirectUrl ,
149
+ scope : provider . clientMetadata . scope
149
150
} ) ;
150
151
151
152
await provider . saveCodeVerifier ( codeVerifier ) ;
@@ -202,10 +203,12 @@ export async function startAuthorization(
202
203
metadata,
203
204
clientInformation,
204
205
redirectUrl,
206
+ scope,
205
207
} : {
206
208
metadata ?: OAuthMetadata ;
207
209
clientInformation : OAuthClientInformation ;
208
210
redirectUrl : string | URL ;
211
+ scope ?: string ;
209
212
} ,
210
213
) : Promise < { authorizationUrl : URL ; codeVerifier : string } > {
211
214
const responseType = "code" ;
@@ -246,6 +249,10 @@ export async function startAuthorization(
246
249
codeChallengeMethod ,
247
250
) ;
248
251
authorizationUrl . searchParams . set ( "redirect_uri" , String ( redirectUrl ) ) ;
252
+
253
+ if ( scope ) {
254
+ authorizationUrl . searchParams . set ( "scope" , scope ) ;
255
+ }
249
256
250
257
return { authorizationUrl, codeVerifier } ;
251
258
}
You can’t perform that action at this time.
0 commit comments