Skip to content

Commit 5fc2027

Browse files
author
Robert Kummer
authored
Merge pull request #15 from C0deWiser/master
Laravel 8, optional username, uuid (not integer) client_id etc
2 parents d2c2694 + 1511d58 commit 5fc2027

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

composer.json

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"name": "ipunkt/laravel-oauth-introspection",
33
"description": "OAuth 2.0 Token Introspection implementation for extending Laravel Passport (RFC 7662)",
4+
"version": "2.0",
45
"keywords": [
56
"laravel",
67
"passport",
@@ -16,10 +17,10 @@
1617
}
1718
],
1819
"require": {
19-
"php": "^7.0",
20-
"guzzlehttp/guzzle": "~6.0",
21-
"ipunkt/laravel-package-manager": "^1.0",
22-
"laravel/passport": "~1.0|~2.0|~3.0|~4.0|~5.0|~6.0|~7.0"
20+
"php": ">=7.0",
21+
"guzzlehttp/guzzle": ">=7.0",
22+
"ipunkt/laravel-package-manager": "^2.0",
23+
"laravel/passport": ">=8.0"
2324
},
2425
"autoload": {
2526
"psr-4": {

src/Http/Controllers/IntrospectionController.php

+10-8
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
namespace Ipunkt\Laravel\OAuthIntrospection\Http\Controllers;
44

55
use Illuminate\Http\JsonResponse;
6+
use Illuminate\Support\Arr;
7+
use Illuminate\Support\Str;
68
use Laravel\Passport\Bridge\AccessTokenRepository;
79
use Laravel\Passport\ClientRepository;
810
use 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

Comments
 (0)