Skip to content

Commit ed95851

Browse files
authored
Merge 6.0.0 into master
2 parents af9ebe0 + 55498a3 commit ed95851

16 files changed

+174
-147
lines changed

.DS_Store

-6 KB
Binary file not shown.

.phpcs.xml.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
PHPCompatibility sniffs to check for PHP cross-version incompatible code.
2121
https://github.com/PHPCompatibility/PHPCompatibility
2222
-->
23-
<config name="testVersion" value="5.5-"/>
23+
<config name="testVersion" value="7.1-"/>
2424
<rule ref="PHPCompatibility"/>
2525

2626
</ruleset>

CHANGELOG.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,25 @@
11
# Change Log
22

3+
## [6.0.0](https://github.com/auth0/laravel-auth0/tree/6.0.0) (2020-04-09)
4+
[Full Changelog](https://github.com/auth0/laravel-auth0/compare/5.4.0...6.0.0)
5+
6+
**This is a major release and includes breaking changes!** This release also includes a major version change for the PHP SDK that it relies on. Please see the [migration guide](https://github.com/auth0/auth0-PHP/blob/master/MIGRATE-v5-TO-v7.md) for the PHP SDK for more information.
7+
8+
**Closed issues**
9+
- auth0-PHP 7.0 - State and nonce handling [\#163](https://github.com/auth0/laravel-auth0/issues/163)
10+
- Cannot use actingAs unit tests functionality [\#161](https://github.com/auth0/laravel-auth0/issues/161)
11+
12+
**Added**
13+
- Implement auth0 guard [\#166](https://github.com/auth0/laravel-auth0/pull/166) ([Tamrael](https://github.com/Tamrael))
14+
15+
**Changed**
16+
- Use array for Auth0JWTUser and add repo return types [\#176](https://github.com/auth0/laravel-auth0/pull/176) ([joshcanhelp](https://github.com/joshcanhelp))
17+
- Update PHP SDK to v7.0.0 [\#162](https://github.com/auth0/laravel-auth0/pull/162) ([joshcanhelp](https://github.com/joshcanhelp))
18+
- Bind SessionState handler interface in container [\#147](https://github.com/auth0/laravel-auth0/pull/147) ([nstapelbroek](https://github.com/nstapelbroek))
19+
20+
**Fixed**
21+
- Fix Laravel session management [\#174](https://github.com/auth0/laravel-auth0/pull/174) ([joshcanhelp](https://github.com/joshcanhelp))
22+
323
## [5.4.0](https://github.com/auth0/laravel-auth0/tree/5.4.0) (2020-03-27)
424
[Full Changelog](https://github.com/auth0/laravel-auth0/compare/5.3.1...5.4.0)
525

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,36 @@ You can implement your own cache strategy by creating a new class that implement
4646

4747
You can customize the way you handle the users in your application by creating your own `UserRepository`. This class should implement the `Auth0\Login\Contract\Auth0UserRepository` contract. Please see the [Custom User Handling section of the Laravel Quickstart](https://auth0.com/docs/quickstart/webapp/laravel#optional-custom-user-handling) for the latest example.
4848

49+
### Using auth guard
50+
51+
To protect APIs using an access token generated by Auth0, there is an `auth0` API guard provided ([Laravel documentation on guards](https://laravel.com/docs/7.x/authentication#adding-custom-guards)). To use this guard, add it to `config/auth.php` with the driver `auth0`:
52+
```
53+
'guards' => [
54+
...
55+
'auth0' => [
56+
'driver' => 'auth0',
57+
'provider' => 'auth0',
58+
],
59+
],
60+
61+
'providers' => [
62+
...
63+
'auth0' => [
64+
'driver' => 'auth0',
65+
],
66+
],
67+
```
68+
69+
Once that has been added, add the guard to the middleware of any API route and check authentication during the request:
70+
```
71+
// get user
72+
auth('auth0')->user();
73+
// check if logged in
74+
auth('auth0')->check();
75+
// protect routes via middleware use
76+
Route::group(['middleware' => 'auth:auth0'], function () {});
77+
```
78+
4979
## Installation
5080

5181
Install this plugin into a new or existing project using [Composer](https://getcomposer.org/doc/00-intro.md):

composer.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,19 @@
22
"name": "auth0/login",
33
"description": "Laravel plugin that helps authenticate with the auth0 service",
44
"license": "MIT",
5+
"prefer-stable": true,
56
"require": {
6-
"php": ">=5.5.0",
7+
"php": "^7.1",
8+
"auth0/auth0-php": "^7.1",
79
"illuminate/support": "5.* | ^6.0 | ^7.0",
8-
"auth0/auth0-php": "^5.6.0",
910
"illuminate/contracts": "5.* | ^6.0 | ^7.0"
1011
},
1112
"require-dev": {
12-
"phpunit/phpunit": "^4 | ^7",
13+
"phpunit/phpunit": "^7|^8|^9",
1314
"squizlabs/php_codesniffer": "^3.2",
1415
"phpcompatibility/php-compatibility": "^8.1",
1516
"dealerdirect/phpcodesniffer-composer-installer": "^0.5.0",
16-
"orchestra/testbench": "^3.8"
17+
"orchestra/testbench": "^3.8|^4.0|^5.0"
1718
},
1819
"scripts": {
1920
"test": "SHELL_INTERACTIVE=1 \"vendor/bin/phpunit\" --coverage-text ",

phpunit.xml.dist

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,8 @@
1919
<directory suffix=".php">src/</directory>
2020
</whitelist>
2121
</filter>
22+
<php>
23+
<ini name="session.use_cookies" value="false"/>
24+
<ini name="session.cache_limiter" value="false"/>
25+
</php>
2226
</phpunit>

src/Auth0/Login/Auth0JWTUser.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ class Auth0JWTUser implements \Illuminate\Contracts\Auth\Authenticatable
1515
*
1616
* @param $userInfo
1717
*/
18-
public function __construct($userInfo)
18+
public function __construct(array $userInfo)
1919
{
20-
$this->userInfo = get_object_vars($userInfo);
20+
$this->userInfo = $userInfo;
2121
}
2222

2323
/**

src/Auth0/Login/Auth0Service.php

Lines changed: 21 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,11 @@
22

33
namespace Auth0\Login;
44

5-
use Auth0\SDK\API\Helpers\State\StateHandler;
6-
use Auth0\SDK\API\Helpers\State\SessionStateHandler;
75
use Auth0\SDK\Auth0;
8-
use Auth0\SDK\Helpers\Cache\CacheHandler;
9-
use Auth0\SDK\JWTVerifier;
106
use Auth0\SDK\Store\StoreInterface;
11-
use Config;
12-
use Illuminate\Contracts\Config\Repository;
13-
use Illuminate\Contracts\Container\BindingResolutionException;
7+
use Illuminate\Contracts\Config\Repository as ConfigRepository;
148
use Illuminate\Http\RedirectResponse;
9+
use Psr\SimpleCache\CacheInterface;
1510

1611
/**
1712
* Service that provides access to the Auth0 SDK.
@@ -30,33 +25,35 @@ class Auth0Service
3025
/**
3126
* Auth0Service constructor.
3227
*
33-
* @param array $auth0Config
34-
* @param StoreInterface $sessionStorage
28+
* @param array|null $auth0Config
29+
* @param StoreInterface|null $store
30+
* @param CacheInterface|null $cache
3531
*
36-
* @throws \Auth0\SDK\Exception\CoreException
32+
* @throws \Illuminate\Contracts\Container\BindingResolutionException
3733
*/
3834
public function __construct(
39-
array $auth0Config = null,
35+
array $auth0Config,
4036
StoreInterface $store = null,
41-
StateHandler $stateHandler = null
37+
CacheInterface $cache = null
4238
)
4339
{
44-
if (!$auth0Config instanceof Repository && !is_array($auth0Config)) {
40+
41+
if (!$auth0Config instanceof ConfigRepository && !is_array($auth0Config)) {
4542
$auth0Config = config('laravel-auth0');
4643
}
4744

48-
$store = isset( $auth0Config['store'] ) ? $auth0Config['store'] : $store;
45+
$store = $auth0Config['store'] ?? $store;
4946
if (false !== $store && !$store instanceof StoreInterface) {
5047
$store = new LaravelSessionStore();
5148
}
49+
$auth0Config['store'] = $store;
5250

53-
$stateHandler = isset( $auth0Config['state_handler'] ) ? $auth0Config['state_handler'] : $stateHandler;
54-
if (false !== $stateHandler && !$stateHandler instanceof StateHandler) {
55-
$stateHandler = new SessionStateHandler($store);
51+
$cache = $auth0Config['cache_handler'] ?? $cache;
52+
if (!($cache instanceof CacheInterface)) {
53+
$cache = app()->make('cache.store');
5654
}
55+
$auth0Config['cache_handler'] = $cache;
5756

58-
$auth0Config['store'] = $store;
59-
$auth0Config['state_handler'] = $stateHandler;
6057
$this->auth0 = new Auth0($auth0Config);
6158
}
6259

@@ -163,35 +160,14 @@ public function rememberUser($value = null)
163160

164161
/**
165162
* @param $encUser
163+
* @param array $verifierOptions
166164
*
167-
* @return mixed
165+
* @return array
166+
* @throws \Auth0\SDK\Exception\InvalidTokenException
168167
*/
169-
public function decodeJWT($encUser)
168+
public function decodeJWT($encUser, array $verifierOptions = [])
170169
{
171-
try {
172-
$cache = \App::make(CacheHandler::class);
173-
} catch (BindingResolutionException $e) {
174-
$cache = null;
175-
}
176-
177-
$secret_base64_encoded = config('laravel-auth0.secret_base64_encoded');
178-
179-
if (is_null($secret_base64_encoded)) {
180-
$secret_base64_encoded = true;
181-
}
182-
183-
$verifier = new JWTVerifier([
184-
'valid_audiences' => [config('laravel-auth0.client_id'), config('laravel-auth0.api_identifier')],
185-
'supported_algs' => config('laravel-auth0.supported_algs', ['HS256']),
186-
'client_secret' => config('laravel-auth0.client_secret'),
187-
'authorized_iss' => config('laravel-auth0.authorized_issuers'),
188-
'secret_base64_encoded' => $secret_base64_encoded,
189-
'cache' => $cache,
190-
'guzzle_options' => config('laravel-auth0.guzzle_options'),
191-
]);
192-
193-
$this->apiuser = $verifier->verifyAndDecode($encUser);
194-
170+
$this->apiuser = $this->auth0->decodeIdToken($encUser, $verifierOptions);
195171
return $this->apiuser;
196172
}
197173

src/Auth0/Login/Auth0User.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class Auth0User implements \Illuminate\Contracts\Auth\Authenticatable
1717
* @param array $userInfo
1818
* @param string|null $accessToken
1919
*/
20-
public function __construct($userInfo, $accessToken)
20+
public function __construct(array $userInfo, $accessToken)
2121
{
2222
$this->userInfo = $userInfo;
2323
$this->accessToken = $accessToken;

src/Auth0/Login/Contract/Auth0UserRepository.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,28 @@
22

33
namespace Auth0\Login\Contract;
44

5+
use \Illuminate\Contracts\Auth\Authenticatable;
6+
57
interface Auth0UserRepository
68
{
79
/**
8-
* @param \stdClass $jwt with the data provided in the JWT
10+
* @param array $decodedJwt with the data provided in the JWT
911
*
10-
* @return \Illuminate\Contracts\Auth\Authenticatable
12+
* @return Authenticatable
1113
*/
12-
public function getUserByDecodedJWT($jwt);
14+
public function getUserByDecodedJWT(array $decodedJwt) : Authenticatable;
1315

1416
/**
1517
* @param array $userInfo representing the user profile and user accessToken
1618
*
17-
* @return \Illuminate\Contracts\Auth\Authenticatable
19+
* @return Authenticatable
1820
*/
19-
public function getUserByUserInfo($userInfo);
21+
public function getUserByUserInfo(array $userInfo) : Authenticatable;
2022

2123
/**
22-
* @param mixed $identifier the user id
24+
* @param string|int|null $identifier the user id
2325
*
24-
* @return \Illuminate\Contracts\Auth\Authenticatable
26+
* @return Authenticatable|null
2527
*/
26-
public function getUserByIdentifier($identifier);
28+
public function getUserByIdentifier($identifier) : ?Authenticatable;
2729
}

0 commit comments

Comments
 (0)