3
3
namespace Ipunkt \Laravel \OAuthIntrospection \Http \Controllers ;
4
4
5
5
use Illuminate \Http \JsonResponse ;
6
+ use Illuminate \Support \Arr ;
7
+ use Illuminate \Support \Str ;
6
8
use Laravel \Passport \Bridge \AccessTokenRepository ;
7
9
use Laravel \Passport \ClientRepository ;
8
10
use Laravel \Passport \Passport ;
@@ -70,12 +72,12 @@ public function introspectToken(ServerRequestInterface $request)
70
72
try {
71
73
$ this ->resourceServer ->validateAuthenticatedRequest ($ request );
72
74
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 ' ) {
74
76
// unsupported introspection
75
77
return $ this ->notActiveResponse ();
76
78
}
77
79
78
- $ accessToken = array_get ($ request ->getParsedBody (), 'token ' );
80
+ $ accessToken = Arr:: get ($ request ->getParsedBody (), 'token ' );
79
81
if ($ accessToken === null ) {
80
82
return $ this ->notActiveResponse ();
81
83
}
@@ -91,19 +93,19 @@ public function introspectToken(ServerRequestInterface $request)
91
93
92
94
/** @var string $userModel */
93
95
$ userModel = config ('auth.providers.users.model ' );
94
- $ user = (new $ userModel )->findOrFail ($ token ->getClaim ('sub ' ));
96
+ $ user = (new $ userModel )->find ($ token ->getClaim ('sub ' ));
95
97
96
98
return $ this ->jsonResponse ([
97
99
'active ' => true ,
98
100
'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 ,
101
103
'token_type ' => 'access_token ' ,
102
104
'exp ' => intval ($ token ->getClaim ('exp ' )),
103
105
'iat ' => intval ($ token ->getClaim ('iat ' )),
104
106
'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 ' ),
107
109
'jti ' => $ token ->getClaim ('jti ' ),
108
110
]);
109
111
} catch (OAuthServerException $ oAuthServerException ) {
@@ -190,7 +192,7 @@ private function exceptionResponse(\Exception $exception, $status = 500) : JsonR
190
192
{
191
193
return $ this ->errorResponse ([
192
194
'error ' => [
193
- 'id ' => str_slug (get_class ($ exception ) . ' ' . $ status ),
195
+ 'id ' => Str:: slug (get_class ($ exception ) . ' ' . $ status ),
194
196
'status ' => $ status ,
195
197
'title ' => $ exception ->getMessage (),
196
198
'detail ' => $ exception ->getTraceAsString ()
0 commit comments