@@ -95,7 +95,7 @@ public function testValidateAuthorizationRequest(): void
9595 $ grant ->setDefaultScope (self ::DEFAULT_SCOPE );
9696
9797 $ request = (new ServerRequest ())->withQueryParams ([
98- 'response_type ' => 'code ' ,
98+ 'response_type ' => 'token ' ,
9999 'client_id ' => 'foo ' ,
100100 'redirect_uri ' => self ::REDIRECT_URI ,
101101 ]);
@@ -120,7 +120,7 @@ public function testValidateAuthorizationRequestRedirectUriArray(): void
120120 $ grant ->setDefaultScope (self ::DEFAULT_SCOPE );
121121
122122 $ request = (new ServerRequest ())->withQueryParams ([
123- 'response_type ' => 'code ' ,
123+ 'response_type ' => 'token ' ,
124124 'client_id ' => 'foo ' ,
125125 'redirect_uri ' => self ::REDIRECT_URI ,
126126 ]);
@@ -135,7 +135,7 @@ public function testValidateAuthorizationRequestMissingClientId(): void
135135 $ grant = new ImplicitGrant (new DateInterval ('PT10M ' ));
136136 $ grant ->setClientRepository ($ clientRepositoryMock );
137137
138- $ request = (new ServerRequest ())->withQueryParams (['response_type ' => 'code ' ]);
138+ $ request = (new ServerRequest ())->withQueryParams (['response_type ' => 'token ' ]);
139139
140140 $ this ->expectException (OAuthServerException::class);
141141 $ this ->expectExceptionCode (3 );
@@ -152,7 +152,7 @@ public function testValidateAuthorizationRequestInvalidClientId(): void
152152 $ grant ->setClientRepository ($ clientRepositoryMock );
153153
154154 $ request = (new ServerRequest ())->withQueryParams ([
155- 'response_type ' => 'code ' ,
155+ 'response_type ' => 'token ' ,
156156 'client_id ' => 'foo ' ,
157157 ]);
158158
@@ -173,7 +173,7 @@ public function testValidateAuthorizationRequestBadRedirectUriString(): void
173173 $ grant ->setClientRepository ($ clientRepositoryMock );
174174
175175 $ request = (new ServerRequest ())->withQueryParams ([
176- 'response_type ' => 'code ' ,
176+ 'response_type ' => 'token ' ,
177177 'client_id ' => 'foo ' ,
178178 'redirect_uri ' => 'http://bar ' ,
179179 ]);
@@ -195,7 +195,7 @@ public function testValidateAuthorizationRequestBadRedirectUriArray(): void
195195 $ grant ->setClientRepository ($ clientRepositoryMock );
196196
197197 $ request = (new ServerRequest ())->withQueryParams ([
198- 'response_type ' => 'code ' ,
198+ 'response_type ' => 'token ' ,
199199 'client_id ' => 'foo ' ,
200200 'redirect_uri ' => 'http://bar ' ,
201201 ]);
@@ -206,6 +206,45 @@ public function testValidateAuthorizationRequestBadRedirectUriArray(): void
206206 $ grant ->validateAuthorizationRequest ($ request );
207207 }
208208
209+ public function testValidateAuthorizationRequestInvalidScopes (): void
210+ {
211+ $ client = new ClientEntity ();
212+ $ client ->setRedirectUri (self ::REDIRECT_URI );
213+
214+ $ clientRepositoryMock = $ this ->getMockBuilder (ClientRepositoryInterface::class)->getMock ();
215+ $ clientRepositoryMock ->method ('getClientEntity ' )->willReturn ($ client );
216+
217+ $ scopeRepositoryMock = $ this ->getMockBuilder (ScopeRepositoryInterface::class)->getMock ();
218+ $ scopeRepositoryMock ->method ('getScopeEntityByIdentifier ' )->willReturn (null );
219+
220+ $ grant = new ImplicitGrant (new DateInterval ('PT10M ' ));
221+
222+ $ grant ->setClientRepository ($ clientRepositoryMock );
223+ $ grant ->setScopeRepository ($ scopeRepositoryMock );
224+ $ grant ->setDefaultScope (self ::DEFAULT_SCOPE );
225+
226+ $ request = (new ServerRequest ())->withQueryParams ([
227+ 'response_type ' => 'token ' ,
228+ 'client_id ' => 'foo ' ,
229+ 'redirect_uri ' => self ::REDIRECT_URI ,
230+ 'scope ' => 'foo ' ,
231+ 'state ' => 'foo ' ,
232+ ]);
233+
234+ try {
235+ $ grant ->validateAuthorizationRequest ($ request );
236+ } catch (OAuthServerException $ e ) {
237+ self ::assertSame (5 , $ e ->getCode ());
238+ self ::assertSame ('invalid_scope ' , $ e ->getErrorType ());
239+ self ::assertSame ('https://foo/bar#state=foo ' , $ e ->getRedirectUri ());
240+
241+ return ;
242+ }
243+
244+ $ this ->expectException (OAuthServerException::class);
245+ $ this ->expectExceptionCode (5 );
246+ }
247+
209248 public function testCompleteAuthorizationRequest (): void
210249 {
211250 $ client = new ClientEntity ();
@@ -248,6 +287,7 @@ public function testCompleteAuthorizationRequestDenied(): void
248287 $ authRequest ->setClient ($ client );
249288 $ authRequest ->setGrantTypeId ('authorization_code ' );
250289 $ authRequest ->setUser (new UserEntity ());
290+ $ authRequest ->setState ('foo ' );
251291
252292 $ accessTokenRepositoryMock = $ this ->getMockBuilder (AccessTokenRepositoryInterface::class)->getMock ();
253293 $ accessTokenRepositoryMock ->method ('getNewToken ' )->willReturn (new AccessTokenEntity ());
@@ -261,10 +301,18 @@ public function testCompleteAuthorizationRequestDenied(): void
261301 $ grant ->setAccessTokenRepository ($ accessTokenRepositoryMock );
262302 $ grant ->setScopeRepository ($ scopeRepositoryMock );
263303
304+ try {
305+ $ grant ->completeAuthorizationRequest ($ authRequest );
306+ } catch (OAuthServerException $ e ) {
307+ self ::assertSame (9 , $ e ->getCode ());
308+ self ::assertSame ('access_denied ' , $ e ->getErrorType ());
309+ self ::assertSame ('https://foo/bar#state=foo ' , $ e ->getRedirectUri ());
310+
311+ return ;
312+ }
313+
264314 $ this ->expectException (OAuthServerException::class);
265315 $ this ->expectExceptionCode (9 );
266-
267- $ grant ->completeAuthorizationRequest ($ authRequest );
268316 }
269317
270318 public function testAccessTokenRepositoryUniqueConstraintCheck (): void
0 commit comments