@@ -95,7 +95,7 @@ public function testValidateAuthorizationRequest(): void
95
95
$ grant ->setDefaultScope (self ::DEFAULT_SCOPE );
96
96
97
97
$ request = (new ServerRequest ())->withQueryParams ([
98
- 'response_type ' => 'code ' ,
98
+ 'response_type ' => 'token ' ,
99
99
'client_id ' => 'foo ' ,
100
100
'redirect_uri ' => self ::REDIRECT_URI ,
101
101
]);
@@ -120,7 +120,7 @@ public function testValidateAuthorizationRequestRedirectUriArray(): void
120
120
$ grant ->setDefaultScope (self ::DEFAULT_SCOPE );
121
121
122
122
$ request = (new ServerRequest ())->withQueryParams ([
123
- 'response_type ' => 'code ' ,
123
+ 'response_type ' => 'token ' ,
124
124
'client_id ' => 'foo ' ,
125
125
'redirect_uri ' => self ::REDIRECT_URI ,
126
126
]);
@@ -135,7 +135,7 @@ public function testValidateAuthorizationRequestMissingClientId(): void
135
135
$ grant = new ImplicitGrant (new DateInterval ('PT10M ' ));
136
136
$ grant ->setClientRepository ($ clientRepositoryMock );
137
137
138
- $ request = (new ServerRequest ())->withQueryParams (['response_type ' => 'code ' ]);
138
+ $ request = (new ServerRequest ())->withQueryParams (['response_type ' => 'token ' ]);
139
139
140
140
$ this ->expectException (OAuthServerException::class);
141
141
$ this ->expectExceptionCode (3 );
@@ -152,7 +152,7 @@ public function testValidateAuthorizationRequestInvalidClientId(): void
152
152
$ grant ->setClientRepository ($ clientRepositoryMock );
153
153
154
154
$ request = (new ServerRequest ())->withQueryParams ([
155
- 'response_type ' => 'code ' ,
155
+ 'response_type ' => 'token ' ,
156
156
'client_id ' => 'foo ' ,
157
157
]);
158
158
@@ -173,7 +173,7 @@ public function testValidateAuthorizationRequestBadRedirectUriString(): void
173
173
$ grant ->setClientRepository ($ clientRepositoryMock );
174
174
175
175
$ request = (new ServerRequest ())->withQueryParams ([
176
- 'response_type ' => 'code ' ,
176
+ 'response_type ' => 'token ' ,
177
177
'client_id ' => 'foo ' ,
178
178
'redirect_uri ' => 'http://bar ' ,
179
179
]);
@@ -195,7 +195,7 @@ public function testValidateAuthorizationRequestBadRedirectUriArray(): void
195
195
$ grant ->setClientRepository ($ clientRepositoryMock );
196
196
197
197
$ request = (new ServerRequest ())->withQueryParams ([
198
- 'response_type ' => 'code ' ,
198
+ 'response_type ' => 'token ' ,
199
199
'client_id ' => 'foo ' ,
200
200
'redirect_uri ' => 'http://bar ' ,
201
201
]);
@@ -206,6 +206,45 @@ public function testValidateAuthorizationRequestBadRedirectUriArray(): void
206
206
$ grant ->validateAuthorizationRequest ($ request );
207
207
}
208
208
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
+
209
248
public function testCompleteAuthorizationRequest (): void
210
249
{
211
250
$ client = new ClientEntity ();
@@ -248,6 +287,7 @@ public function testCompleteAuthorizationRequestDenied(): void
248
287
$ authRequest ->setClient ($ client );
249
288
$ authRequest ->setGrantTypeId ('authorization_code ' );
250
289
$ authRequest ->setUser (new UserEntity ());
290
+ $ authRequest ->setState ('foo ' );
251
291
252
292
$ accessTokenRepositoryMock = $ this ->getMockBuilder (AccessTokenRepositoryInterface::class)->getMock ();
253
293
$ accessTokenRepositoryMock ->method ('getNewToken ' )->willReturn (new AccessTokenEntity ());
@@ -261,10 +301,18 @@ public function testCompleteAuthorizationRequestDenied(): void
261
301
$ grant ->setAccessTokenRepository ($ accessTokenRepositoryMock );
262
302
$ grant ->setScopeRepository ($ scopeRepositoryMock );
263
303
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
+
264
314
$ this ->expectException (OAuthServerException::class);
265
315
$ this ->expectExceptionCode (9 );
266
-
267
- $ grant ->completeAuthorizationRequest ($ authRequest );
268
316
}
269
317
270
318
public function testAccessTokenRepositoryUniqueConstraintCheck (): void
0 commit comments