Skip to content

Commit

Permalink
Add laravel 11 support (#9)
Browse files Browse the repository at this point in the history
* add laravel 11 support

* laravel 11 require php 8.2

* allow version 11 of illuminate/support

* return null when user not found
  • Loading branch information
abublihi authored May 25, 2024
1 parent 6ff65f9 commit b452501
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 10 deletions.
10 changes: 9 additions & 1 deletion .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,22 @@ jobs:
matrix:
os: [ubuntu-latest]
php: [7.4, 8.1, 8.2, 8.3]
laravel: [8.*, 9.*, 10.*]
laravel: [8.*, 9.*, 10.*, 11.*]
stability: [prefer-stable]
exclude:
- laravel: 11.*
php: 8.1
- laravel: 11.*
php: 8.0
- laravel: 11.*
php: 7.4
- laravel: 10.*
php: 7.4
- laravel: 9.*
php: 7.4
include:
- laravel: 11.*
testbench: 9.*
- laravel: 10.*
testbench: 8.*
- laravel: 9.*
Expand Down
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,26 @@

All notable changes to `laravel-external-jwt-guard` will be documented in this file

## v1.1.5

- add a test when no authorization header is not set JwtGuardTest.php by @abublihi in #7

## v1.1.2

## v1.1.1

- add array dot support to id_claim and roles_claim by @MuhammedAlkhudiry in #4
- @MuhammedAlkhudiry made their first contribution in #4

## v1.1.0

- Roles middleware feature by @abublihi in #3

## v1.0.1

- Fix: issue validation not disabled from config by @abublihi in #2


## 1.0.0

- initial release
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
],
"require": {
"php": "^7.4|^8.0",
"illuminate/support": "^8.0|^9.0|^10.0",
"illuminate/support": "^8.0|^9.0|^10.0|^11.0",
"lcobucci/clock": "^2.0|^3.0",
"lcobucci/jwt": "^4.2|^5.0"
},
"require-dev": {
"orchestra/testbench": "^6.0|^7.0|^8.0",
"phpunit/phpunit": "^9.0"
"orchestra/testbench": "^6.0|^7.0|^8.0|^9.0",
"phpunit/phpunit": "^9.0|^10.0"
},
"autoload": {
"psr-4": {
Expand Down
7 changes: 4 additions & 3 deletions src/JwtGuardDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,10 @@ public function user()
);
}

if (!$user) {
throw new CouldNotFindUserWithProvidedIdException("id_attribute: {$this->authorizationServerConfig->idAttribute}, auth server id: {$this->parsedJwt->getId()}");
}
// Do not throw an exception, as laravel will return unauthorized with status code 401 which is more suitable
// if (!$user) {
// throw new CouldNotFindUserWithProvidedIdException("id_attribute: {$this->authorizationServerConfig->idAttribute}, auth server id: {$this->parsedJwt->getId()}");
// }

return $this->user = $user;
}
Expand Down
5 changes: 2 additions & 3 deletions tests/Feature/JwtGuardTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,10 @@ function test_it_returns_unauthorized_without_jwt_header()
* @test
* @define-route usesAuthRoutes
*/
function test_it_returns_500_with_not_found_user_with_provided_id_using_jwt()
function test_it_returns_401_when_not_found_the_user_with_provided_id_using_jwt()
{
// set the create_user to false
config(['externaljwtguard.authorization_servers.default.create_user' => false]);
$user = User::factory()->makeOne();

$jwt = $this->issueToken(
[],
Expand All @@ -129,7 +128,7 @@ function test_it_returns_500_with_not_found_user_with_provided_id_using_jwt()
'Authorization' => 'Bearer '.$jwt
])->getJson('current-user');

$response->assertStatus(500);
$response->assertStatus(401);
}

/**
Expand Down

0 comments on commit b452501

Please sign in to comment.