@@ -525,13 +525,71 @@ public function testGrantAccessTokenWithGrantUserWithReducedScope()
525
525
array ('date ' => null )
526
526
));
527
527
528
+ $ this ->assertRegExp ('{"access_token":"[^"]+","expires_in":3600,"token_type":"bearer","scope":"scope1"} ' , $ response ->getContent ());
529
+
530
+ $ token = $ stub ->getLastAccessToken ();
531
+ $ this ->assertSame ('cid ' , $ token ->getClientId ());
532
+ $ this ->assertSame ('scope1 ' , $ token ->getScope ());
533
+ }
534
+
535
+ public function testGrantAccessTokenWithGrantUserWithNoScope ()
536
+ {
537
+ $ stub = new OAuth2GrantUserStub ;
538
+ $ stub ->addClient (new OAuth2Client ('cid ' , 'cpass ' ));
539
+ $ stub ->addUser ('foo ' , 'bar ' , 'scope1 scope2 ' );
540
+ $ stub ->setAllowedGrantTypes (array ('authorization_code ' , 'password ' ));
541
+
542
+ $ oauth2 = new OAuth2 ($ stub );
543
+
544
+ $ response = $ oauth2 ->grantAccessToken (new Request (array (
545
+ 'grant_type ' => 'password ' ,
546
+ 'client_id ' => 'cid ' ,
547
+ 'client_secret ' => 'cpass ' ,
548
+ 'username ' => 'foo ' ,
549
+ 'password ' => 'bar ' ,
550
+ )));
551
+
552
+ $ this ->assertSame (array (
553
+ 'content-type ' => array ('application/json ' ),
554
+ 'cache-control ' => array ('no-store, private ' ),
555
+ 'pragma ' => array ('no-cache ' ),
556
+ ), array_diff_key (
557
+ $ response ->headers ->all (),
558
+ array ('date ' => null )
559
+ ));
560
+
528
561
$ this ->assertRegExp ('{"access_token":"[^"]+","expires_in":3600,"token_type":"bearer","scope":"scope1 scope2"} ' , $ response ->getContent ());
529
562
530
563
$ token = $ stub ->getLastAccessToken ();
531
564
$ this ->assertSame ('cid ' , $ token ->getClientId ());
532
565
$ this ->assertSame ('scope1 scope2 ' , $ token ->getScope ());
533
566
}
534
567
568
+ public function testGrantAccessTokenWithGrantUserWithNewScopeThrowsError ()
569
+ {
570
+ $ stub = new OAuth2GrantUserStub ;
571
+ $ stub ->addClient (new OAuth2Client ('cid ' , 'cpass ' ));
572
+ $ stub ->addUser ('foo ' , 'bar ' , 'scope1 scope2 ' );
573
+ $ stub ->setAllowedGrantTypes (array ('authorization_code ' , 'password ' ));
574
+
575
+ $ oauth2 = new OAuth2 ($ stub );
576
+
577
+ try {
578
+ $ response = $ oauth2 ->grantAccessToken (new Request (array (
579
+ 'grant_type ' => 'password ' ,
580
+ 'client_id ' => 'cid ' ,
581
+ 'client_secret ' => 'cpass ' ,
582
+ 'username ' => 'foo ' ,
583
+ 'password ' => 'bar ' ,
584
+ 'scope ' => 'scope3 ' ,
585
+ )));
586
+ $ this ->fail ('The expected exception OAuth2ServerException was not thrown ' );
587
+ } catch (OAuth2ServerException $ e ) {
588
+ $ this ->assertSame ('invalid_scope ' , $ e ->getMessage ());
589
+ $ this ->assertSame ('An unsupported scope was requested. ' , $ e ->getDescription ());
590
+ }
591
+ }
592
+
535
593
/**
536
594
* Tests OAuth2->grantAccessToken() with client credentials
537
595
*
0 commit comments