diff --git a/src/Auth0/Login/Auth0JWTUser.php b/src/Auth0/Login/Auth0JWTUser.php index 7ac637e8..ce5ddb9b 100644 --- a/src/Auth0/Login/Auth0JWTUser.php +++ b/src/Auth0/Login/Auth0JWTUser.php @@ -15,9 +15,9 @@ class Auth0JWTUser implements \Illuminate\Contracts\Auth\Authenticatable * * @param $userInfo */ - public function __construct($userInfo) + public function __construct(array $userInfo) { - $this->userInfo = get_object_vars($userInfo); + $this->userInfo = $userInfo; } /** diff --git a/src/Auth0/Login/Auth0Service.php b/src/Auth0/Login/Auth0Service.php index 1c922781..2d22401e 100644 --- a/src/Auth0/Login/Auth0Service.php +++ b/src/Auth0/Login/Auth0Service.php @@ -162,12 +162,12 @@ public function rememberUser($value = null) * @param $encUser * @param array $verifierOptions * - * @return object + * @return array * @throws \Auth0\SDK\Exception\InvalidTokenException */ public function decodeJWT($encUser, array $verifierOptions = []) { - $this->apiuser = (object) $this->auth0->decodeIdToken($encUser, $verifierOptions); + $this->apiuser = $this->auth0->decodeIdToken($encUser, $verifierOptions); return $this->apiuser; } diff --git a/src/Auth0/Login/Auth0User.php b/src/Auth0/Login/Auth0User.php index 67351bfe..9420e2e6 100644 --- a/src/Auth0/Login/Auth0User.php +++ b/src/Auth0/Login/Auth0User.php @@ -14,10 +14,10 @@ class Auth0User implements \Illuminate\Contracts\Auth\Authenticatable /** * Auth0User constructor. * - * @param $userInfo + * @param array $userInfo * @param $accessToken */ - public function __construct($userInfo, $accessToken) + public function __construct(array $userInfo, $accessToken) { $this->userInfo = $userInfo; $this->accessToken = $accessToken; diff --git a/src/Auth0/Login/Contract/Auth0UserRepository.php b/src/Auth0/Login/Contract/Auth0UserRepository.php index a87fbc14..439101e0 100644 --- a/src/Auth0/Login/Contract/Auth0UserRepository.php +++ b/src/Auth0/Login/Contract/Auth0UserRepository.php @@ -2,26 +2,28 @@ namespace Auth0\Login\Contract; +use \Illuminate\Contracts\Auth\Authenticatable; + interface Auth0UserRepository { /** - * @param stdClass $jwt with the data provided in the JWT + * @param array $decodedJwt with the data provided in the JWT * - * @return \Illuminate\Contracts\Auth\Authenticatable + * @return Authenticatable */ - public function getUserByDecodedJWT($jwt); + public function getUserByDecodedJWT(array $decodedJwt) : Authenticatable; /** * @param array $userInfo representing the user profile and user accessToken * - * @return \Illuminate\Contracts\Auth\Authenticatable + * @return Authenticatable */ - public function getUserByUserInfo($userInfo); + public function getUserByUserInfo(array $userInfo) : Authenticatable; /** - * @param $identifier the user id + * @param string|int|null $identifier the user id * - * @return \Illuminate\Contracts\Auth\Authenticatable + * @return Authenticatable|null */ - public function getUserByIdentifier($identifier); + public function getUserByIdentifier($identifier) : ?Authenticatable; } diff --git a/src/Auth0/Login/Repository/Auth0UserRepository.php b/src/Auth0/Login/Repository/Auth0UserRepository.php index af64182e..dc6b8b90 100644 --- a/src/Auth0/Login/Repository/Auth0UserRepository.php +++ b/src/Auth0/Login/Repository/Auth0UserRepository.php @@ -5,17 +5,18 @@ use Auth0\Login\Auth0User; use Auth0\Login\Auth0JWTUser; use Auth0\Login\Contract\Auth0UserRepository as Auth0UserRepositoryContract; +use Illuminate\Contracts\Auth\Authenticatable; class Auth0UserRepository implements Auth0UserRepositoryContract { /** - * @param \Auth0\Login\Contract\stdClass $jwt + * @param array $decodedJwt * * @return Auth0JWTUser */ - public function getUserByDecodedJWT($jwt) + public function getUserByDecodedJWT(array $decodedJwt) : Authenticatable { - return new Auth0JWTUser($jwt); + return new Auth0JWTUser($decodedJwt); } /** @@ -23,23 +24,23 @@ public function getUserByDecodedJWT($jwt) * * @return Auth0User */ - public function getUserByUserInfo($userInfo) + public function getUserByUserInfo(array $userInfo) : Authenticatable { return new Auth0User($userInfo['profile'], $userInfo['accessToken']); } /** - * @param \Auth0\Login\Contract\the $identifier + * @param string|int|null $identifier * - * @return Auth0User|\Illuminate\Contracts\Auth\Authenticatable|null + * @return Authenticatable|null */ - public function getUserByIdentifier($identifier) + public function getUserByIdentifier($identifier) : ?Authenticatable { // Get the user info of the user logged in (probably in session) $user = \App::make('auth0')->getUser(); if ($user === null) { - return; + return null; } // Build the user diff --git a/tests/Auth0ServiceTest.php b/tests/Auth0ServiceTest.php index 74254aa2..3d2711cc 100644 --- a/tests/Auth0ServiceTest.php +++ b/tests/Auth0ServiceTest.php @@ -90,7 +90,7 @@ public function testThatGuardAuthenticatesUsers() { $this->assertTrue(\Auth('auth0')->guest()); - $user = new Auth0JWTUser((object)['sub' => 'x']); + $user = new Auth0JWTUser(['sub' => 'x']); \Auth('auth0')->setUser($user); diff --git a/tests/Unit/Auth0JWTUserTest.php b/tests/Unit/Auth0JWTUserTest.php index fd85df97..e96cea7d 100644 --- a/tests/Unit/Auth0JWTUserTest.php +++ b/tests/Unit/Auth0JWTUserTest.php @@ -15,7 +15,7 @@ class Auth0JWTUserTest extends TestCase public function setUp(): void { parent::setUp(); - $this->auth0JwtUser = new Auth0JWTUser((object)[ + $this->auth0JwtUser = new Auth0JWTUser([ "name" => "John Doe", "iss" => "http://auth0.com", "sub" => "someone@example.com",