@@ -338,4 +338,67 @@ public function testPromptLogin()
338338 $ response ->assertSessionHas ('promptedForLogin ' , true );
339339 $ response ->assertRedirectToRoute ('login ' );
340340 }
341+
342+ public function testUnauthorizedClient ()
343+ {
344+ $ client = ClientFactory::new ()->create ([
345+ 'grant_types ' => [],
346+ ]);
347+
348+ $ query = http_build_query ([
349+ 'client_id ' => $ client ->getKey (),
350+ 'redirect_uri ' => $ client ->redirect_uris [0 ],
351+ 'response_type ' => 'code ' ,
352+ ]);
353+
354+ $ user = UserFactory::new ()->create ();
355+ $ this ->actingAs ($ user , 'web ' );
356+
357+ $ json = $ this ->get ('/oauth/authorize? ' .$ query )
358+ ->assertBadRequest ()
359+ ->assertSessionMissing (['authRequest ' , 'authToken ' ])
360+ ->json ();
361+
362+ $ this ->assertSame ('unauthorized_client ' , $ json ['error ' ]);
363+ $ this ->assertSame (
364+ 'The authenticated client is not authorized to use this authorization grant type. ' ,
365+ $ json ['error_description ' ]
366+ );
367+ }
368+
369+ public function testIssueAccessTokenWithoutRefreshToken ()
370+ {
371+ $ client = ClientFactory::new ()->create ([
372+ 'grant_types ' => ['authorization_code ' ],
373+ ]);
374+
375+ $ query = http_build_query ([
376+ 'client_id ' => $ client ->getKey (),
377+ 'redirect_uri ' => $ redirect = $ client ->redirect_uris [0 ],
378+ 'response_type ' => 'code ' ,
379+ ]);
380+
381+ $ user = UserFactory::new ()->create ();
382+ $ this ->actingAs ($ user , 'web ' );
383+
384+ $ authToken = $ this ->get ('/oauth/authorize? ' .$ query )
385+ ->assertOk ()
386+ ->json ('authToken ' );
387+
388+ $ response = $ this ->post ('/oauth/authorize ' , ['auth_token ' => $ authToken ])->assertRedirect ();
389+ parse_str (parse_url ($ response ->headers ->get ('Location ' ), PHP_URL_QUERY ), $ params );
390+
391+ $ json = $ this ->post ('/oauth/token ' , [
392+ 'grant_type ' => 'authorization_code ' ,
393+ 'client_id ' => $ client ->getKey (),
394+ 'client_secret ' => $ client ->plainSecret ,
395+ 'redirect_uri ' => $ redirect ,
396+ 'code ' => $ params ['code ' ],
397+ ])->assertOk ()->json ();
398+
399+ $ this ->assertArrayHasKey ('access_token ' , $ json );
400+ $ this ->assertArrayNotHasKey ('refresh_token ' , $ json );
401+ $ this ->assertSame ('Bearer ' , $ json ['token_type ' ]);
402+ $ this ->assertArrayHasKey ('expires_in ' , $ json );
403+ }
341404}
0 commit comments