@@ -361,6 +361,93 @@ describe('OAuth2Strategy', function() {
361
361
} ) ;
362
362
} ) ; // that redirects to service provider with relative redirect URI option
363
363
364
+ describe ( 'that redirects to authorization server using authorization endpoint that has query parameters with scope option' , function ( ) {
365
+ var strategy = new OAuth2Strategy ( {
366
+ authorizationURL : 'https://www.example.com/oauth2/authorize?foo=bar' ,
367
+ tokenURL : 'https://www.example.com/oauth2/token' ,
368
+ clientID : 'ABC123' ,
369
+ clientSecret : 'secret' ,
370
+ callbackURL : 'https://www.example.net/auth/example/callback' ,
371
+ } ,
372
+ function ( accessToken , refreshToken , profile , done ) { } ) ;
373
+
374
+
375
+ var url ;
376
+
377
+ before ( function ( done ) {
378
+ chai . passport . use ( strategy )
379
+ . redirect ( function ( u ) {
380
+ url = u ;
381
+ done ( ) ;
382
+ } )
383
+ . req ( function ( req ) {
384
+ } )
385
+ . authenticate ( { scope : 'email' } ) ;
386
+ } ) ;
387
+
388
+ it ( 'should be redirected' , function ( ) {
389
+ expect ( url ) . to . equal ( 'https://www.example.com/oauth2/authorize?foo=bar&response_type=code&redirect_uri=https%3A%2F%2Fwww.example.net%2Fauth%2Fexample%2Fcallback&scope=email&client_id=ABC123' ) ;
390
+ } ) ;
391
+ } ) ; // that redirects to authorization server using authorization endpoint that has query parameters with scope option
392
+
393
+ describe ( 'that redirects to authorization server using authorization endpoint that has query parameters including scope with scope option' , function ( ) {
394
+ var strategy = new OAuth2Strategy ( {
395
+ authorizationURL : 'https://www.example.com/oauth2/authorize?foo=bar&scope=baz' ,
396
+ tokenURL : 'https://www.example.com/oauth2/token' ,
397
+ clientID : 'ABC123' ,
398
+ clientSecret : 'secret' ,
399
+ callbackURL : 'https://www.example.net/auth/example/callback' ,
400
+ } ,
401
+ function ( accessToken , refreshToken , profile , done ) { } ) ;
402
+
403
+
404
+ var url ;
405
+
406
+ before ( function ( done ) {
407
+ chai . passport . use ( strategy )
408
+ . redirect ( function ( u ) {
409
+ url = u ;
410
+ done ( ) ;
411
+ } )
412
+ . req ( function ( req ) {
413
+ } )
414
+ . authenticate ( { scope : 'email' } ) ;
415
+ } ) ;
416
+
417
+ it ( 'should be redirected' , function ( ) {
418
+ expect ( url ) . to . equal ( 'https://www.example.com/oauth2/authorize?foo=bar&scope=email&response_type=code&redirect_uri=https%3A%2F%2Fwww.example.net%2Fauth%2Fexample%2Fcallback&client_id=ABC123' ) ;
419
+ } ) ;
420
+ } ) ; // that redirects to authorization server using authorization endpoint that has query parameters including scope with scope option
421
+
422
+ describe ( 'that redirects to authorization server using authorization endpoint that has query parameters including state with state option' , function ( ) {
423
+ var strategy = new OAuth2Strategy ( {
424
+ authorizationURL : 'https://www.example.com/oauth2/authorize?foo=bar&state=baz' ,
425
+ tokenURL : 'https://www.example.com/oauth2/token' ,
426
+ clientID : 'ABC123' ,
427
+ clientSecret : 'secret' ,
428
+ callbackURL : 'https://www.example.net/auth/example/callback' ,
429
+ } ,
430
+ function ( accessToken , refreshToken , profile , done ) { } ) ;
431
+
432
+
433
+ var url ;
434
+
435
+ before ( function ( done ) {
436
+ chai . passport . use ( strategy )
437
+ . redirect ( function ( u ) {
438
+ url = u ;
439
+ done ( ) ;
440
+ } )
441
+ . req ( function ( req ) {
442
+ } )
443
+ . authenticate ( { state : 'foo123' } ) ;
444
+ } ) ;
445
+
446
+ it ( 'should be redirected' , function ( ) {
447
+ expect ( url ) . to . equal ( 'https://www.example.com/oauth2/authorize?foo=bar&state=foo123&response_type=code&redirect_uri=https%3A%2F%2Fwww.example.net%2Fauth%2Fexample%2Fcallback&client_id=ABC123' ) ;
448
+ } ) ;
449
+ } ) ; // that redirects to authorization server using authorization endpoint that has query parameters including state with state option
450
+
364
451
} ) ; // issuing authorization request
365
452
366
453
0 commit comments