Skip to content

Commit

Permalink
1.0.2
Browse files Browse the repository at this point in the history
Small fixes
  • Loading branch information
Hergen Dillema committed Sep 21, 2020
1 parent 85de2b8 commit 6747969
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "werk365/jwtauthroles",
"description": "Made to use fusionauth users in Laravel using JWT. Possible to either use pem keys directly or use the jwks endpoint.",
"version": "1.0.1",
"version": "1.0.2",
"license": "MIT",
"authors": [
{
"name": "Hergen Dillema",
"email": "[email protected]",
"homepage": "https://365werk/nl"
"homepage": "https://365werk.nl"
}
],
"homepage": "https://github.com/365werk/jwtauthroles",
Expand Down
11 changes: 9 additions & 2 deletions src/JwtAuthRoles.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ private static function jwkToPem(object $jwk): ?string
'n' => new BigInteger(JWT::urlsafeB64Decode($jwk->n), 256),
]);

if($rsa->getPublicKey() === false){
return null;
}

return $rsa->getPublicKey();
}

Expand Down Expand Up @@ -107,6 +111,9 @@ private static function verifyToken(string $jwt, string $uri, bool $jwk = false)
if (! $kid) {
throw AuthException::auth(422, 'Malformed JWT');
}

$row = null;

if (config('jwtauthroles.cache.enabled')) {
if (config('jwtauthroles.cache.type') === 'database') {
$row = JwtKey::where('kid', $kid)
Expand All @@ -125,8 +132,8 @@ private static function verifyToken(string $jwt, string $uri, bool $jwk = false)
}

if (config('jwtauthroles.cache.enabled')) {
if (config('jwtauthroles.cache.type') === 'database') {
$row = $row ?? JwtKey::create(['kid' => $kid, 'key' => $publicKey]);
if (config('jwtauthroles.cache.type') === 'database' && !$row) {
JwtKey::create(['kid' => $kid, 'key' => $publicKey]);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Middlewares/RoleMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function handle($request, Closure $next, $role)
$user_roles = array_map('strtolower', Auth::user()->roles);
$same = (array_intersect($roles, $user_roles));

if (! $same) {
if (empty($same)) {
throw AuthException::auth('401', 'User does not have right roles');
}

Expand Down

0 comments on commit 6747969

Please sign in to comment.