33namespace Ipunkt \Laravel \OAuthIntrospection \Http \Controllers ;
44
55use Illuminate \Http \JsonResponse ;
6+ use Illuminate \Support \Arr ;
7+ use Illuminate \Support \Str ;
68use Laravel \Passport \Bridge \AccessTokenRepository ;
79use Laravel \Passport \ClientRepository ;
810use Laravel \Passport \Passport ;
@@ -70,12 +72,12 @@ public function introspectToken(ServerRequestInterface $request)
7072 try {
7173 $ this ->resourceServer ->validateAuthenticatedRequest ($ request );
7274
73- if (array_get ($ request ->getParsedBody (), 'token_type_hint ' , 'access_token ' ) !== 'access_token ' ) {
75+ if (Arr:: get ($ request ->getParsedBody (), 'token_type_hint ' , 'access_token ' ) !== 'access_token ' ) {
7476 // unsupported introspection
7577 return $ this ->notActiveResponse ();
7678 }
7779
78- $ accessToken = array_get ($ request ->getParsedBody (), 'token ' );
80+ $ accessToken = Arr:: get ($ request ->getParsedBody (), 'token ' );
7981 if ($ accessToken === null ) {
8082 return $ this ->notActiveResponse ();
8183 }
@@ -91,19 +93,19 @@ public function introspectToken(ServerRequestInterface $request)
9193
9294 /** @var string $userModel */
9395 $ userModel = config ('auth.providers.users.model ' );
94- $ user = (new $ userModel )->findOrFail ($ token ->getClaim ('sub ' ));
96+ $ user = (new $ userModel )->find ($ token ->getClaim ('sub ' ));
9597
9698 return $ this ->jsonResponse ([
9799 'active ' => true ,
98100 'scope ' => trim (implode (' ' , (array )$ token ->getClaim ('scopes ' , []))),
99- 'client_id ' => intval ( $ token ->getClaim ('aud ' ) ),
100- 'username ' => $ user ->email ,
101+ 'client_id ' => $ token ->getClaim ('aud ' ),
102+ 'username ' => optional ( $ user) ->email ,
101103 'token_type ' => 'access_token ' ,
102104 'exp ' => intval ($ token ->getClaim ('exp ' )),
103105 'iat ' => intval ($ token ->getClaim ('iat ' )),
104106 'nbf ' => intval ($ token ->getClaim ('nbf ' )),
105- 'sub ' => intval ( $ token ->getClaim ('sub ' ) ),
106- 'aud ' => intval ( $ token ->getClaim ('aud ' ) ),
107+ 'sub ' => $ token ->getClaim ('sub ' ),
108+ 'aud ' => $ token ->getClaim ('aud ' ),
107109 'jti ' => $ token ->getClaim ('jti ' ),
108110 ]);
109111 } catch (OAuthServerException $ oAuthServerException ) {
@@ -190,7 +192,7 @@ private function exceptionResponse(\Exception $exception, $status = 500) : JsonR
190192 {
191193 return $ this ->errorResponse ([
192194 'error ' => [
193- 'id ' => str_slug (get_class ($ exception ) . ' ' . $ status ),
195+ 'id ' => Str:: slug (get_class ($ exception ) . ' ' . $ status ),
194196 'status ' => $ status ,
195197 'title ' => $ exception ->getMessage (),
196198 'detail ' => $ exception ->getTraceAsString ()
0 commit comments