diff --git a/.phpcs.xml.dist b/.phpcs.xml.dist deleted file mode 100644 index 8a537ea2..00000000 --- a/.phpcs.xml.dist +++ /dev/null @@ -1,188 +0,0 @@ - - Auth0 PHP coding standard - - - src - - - vendor/ - - - - - - - - - - - - - - - error - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/config/config.php b/config/config.php deleted file mode 100644 index 16b1dc6f..00000000 --- a/config/config.php +++ /dev/null @@ -1,100 +0,0 @@ - env( 'AUTH0_DOMAIN' ), - - /* - |-------------------------------------------------------------------------- - | Your APP id - |-------------------------------------------------------------------------- - | As set in the auth0 administration page - |-------------------------------------------------------------------------- - */ - 'client_id' => env( 'AUTH0_CLIENT_ID' ), - - /* - |-------------------------------------------------------------------------- - | Your APP secret - |-------------------------------------------------------------------------- - | As set in the auth0 administration page - |-------------------------------------------------------------------------- - */ - 'client_secret' => env( 'AUTH0_CLIENT_SECRET' ), - - /* - |-------------------------------------------------------------------------- - | The redirect URI - |-------------------------------------------------------------------------- - | Should be the same that the one configure in the route to handle the - | 'Auth0\Login\Auth0Controller@callback' - |-------------------------------------------------------------------------- - */ - 'redirect_uri' => env( 'APP_URL' ).'/auth0/callback', - - /* - |-------------------------------------------------------------------------- - | Persistence Configuration - |-------------------------------------------------------------------------- - | persist_user (Boolean) Optional. Indicates if you want to persist the user info, default true - | persist_access_token (Boolean) Optional. Indicates if you want to persist the access token, default false - | persist_refresh_token (Boolean) Optional. Indicates if you want to persist the refresh token, default false - | persist_id_token (Boolean) Optional. Indicates if you want to persist the id token, default false - |-------------------------------------------------------------------------- - */ - 'persist_user' => true, - 'persist_access_token' => false, - 'persist_refresh_token' => false, - 'persist_id_token' => false, - - /* - |-------------------------------------------------------------------------- - | The authorized token audiences - |-------------------------------------------------------------------------- - */ - // 'api_identifier' => '', - - /* - |-------------------------------------------------------------------------- - | Auth0 Organizations - |-------------------------------------------------------------------------- - | organization (string) Optional. Id of an Organization, if being used. Used when generating log in urls and validating token claims. - |-------------------------------------------------------------------------- - */ - // 'organization' => '', - - /* - |-------------------------------------------------------------------------- - | The secret format - |-------------------------------------------------------------------------- - | Used to know if it should decode the secret when using HS256 - |-------------------------------------------------------------------------- - */ - 'secret_base64_encoded' => false, - - /* - |-------------------------------------------------------------------------- - | Supported algorithms - |-------------------------------------------------------------------------- - | Token decoding algorithms supported by your API - |-------------------------------------------------------------------------- - */ - 'supported_algs' => [ 'RS256' ], - - /* - |-------------------------------------------------------------------------- - | Guzzle Options - |-------------------------------------------------------------------------- - | guzzle_options (array) optional. Used to specify additional connection options e.g. proxy settings - |-------------------------------------------------------------------------- - */ - // 'guzzle_options' => [] -]; diff --git a/phpstan.neon b/phpstan.neon deleted file mode 100644 index 56a236c5..00000000 --- a/phpstan.neon +++ /dev/null @@ -1,10 +0,0 @@ -parameters: - level: 2 - - paths: - - src - - ignoreErrors: - - '#Call to static method#' - - reportUnmatchedIgnoredErrors: false diff --git a/src/Auth0JWTUser.php b/src/Auth0JWTUser.php deleted file mode 100644 index f242062f..00000000 --- a/src/Auth0JWTUser.php +++ /dev/null @@ -1,103 +0,0 @@ -userInfo = $userInfo; - } - - /** - * Get the unique identifier for the user. - * - * @return mixed - */ - public function getAuthIdentifierName() - { - return $this->userInfo['sub']; - } - - /** - * Get the unique identifier for the user. - * - * @return mixed - */ - public function getAuthIdentifier() - { - return $this->userInfo['sub']; - } - - /** - * @return void - */ - public function getAuthPassword() - { - } - - /** - * @return void - */ - public function getRememberToken() - { - } - - /** - * @param string $value - */ - public function setRememberToken($value) - { - } - - /** - * @return void - */ - public function getRememberTokenName() - { - } - - /** - * Add a generic getter to get all the properties of the userInfo. - * - * @return mixed the related value or null if it is not set - */ - public function __get($name) - { - if (! array_key_exists($name, $this->userInfo)) { - return; - } - - return $this->userInfo[$name]; - } - - /** - * @return array - */ - public function getUserInfo() - { - return $this->userInfo; - } - - /** - * @return string - */ - public function __toString() - { - return json_encode($this->userInfo); - } -} diff --git a/src/Auth0Service.php b/src/Auth0Service.php deleted file mode 100644 index 4e6eae2d..00000000 --- a/src/Auth0Service.php +++ /dev/null @@ -1,320 +0,0 @@ -make('cache.store'); - } - - $auth0Config['cache_handler'] = $cache; - - if (isset($auth0Config['api_identifier'])) { - // Auth0\SDK\Auth0 is using `audience` to create a login link. - $auth0Config['audience'] = $auth0Config['api_identifier']; - } - - $this->auth0Config = $auth0Config; - $this->auth0 = new Auth0($auth0Config); - } - - /** - * Creates an instance of the Auth0 SDK using - * the config set in the laravel way and using a LaravelSession - * as a store mechanism. - */ - private function getSDK() - { - return $this->auth0; - } - - /** - * Instantiate a singleton of the Auth0 Authentication class, using the provided configuration. - */ - private function getAuthenticationClass() - { - if (isset($this->singletons['authentication'])) { - return $this->singletons['authentication']; - } - - return $this->singletons['authentication'] = new \Auth0\SDK\API\Authentication( - $this->auth0Config['domain'] ?? null, - $this->auth0Config['client_id'] ?? null, - $this->auth0Config['client_secret'] ?? null, - $this->auth0Config['audience'] ?? null, - null, - [], - $this->auth0Config['organization'] ?? null, - ); - } - - /** - * Logs the user out from the SDK. - */ - public function logout() - { - $this->getSDK()->logout(); - } - - /** - * Redirects the user to the hosted login page - */ - public function login($connection = null, $state = null, $additional_params = ['scope' => 'openid profile email'], $response_type = 'code') - { - if ($connection && ! isset( $additional_params['connection'] )) { - $additional_params['connection'] = $connection; - } - - if ($state && ! isset( $additional_params['state'] )) { - $additional_params['state'] = $state; - } - - $additional_params['response_type'] = $response_type; - $auth_url = $this->auth0->getLoginUrl($additional_params); - - return new RedirectResponse($auth_url); - } - - /** - * Start passwordless login process for email - * - * @param string $email Email address to use. - * @param string $type Use null or "link" to send a link, use "code" to send a verification code. - * @param array $authParams Optional. Link parameters (like scope, redirect_uri, protocol, response_type) to modify. - * @param string|null $forwardedFor Optional. Source IP address. requires Trust Token Endpoint IP Header - * - * @link https://auth0.com/docs/api/authentication#get-code-or-link - */ - public function emailPasswordlessStart( - string $email, - string $type, - array $authParams = [], - ?string $forwardedFor = null - ): array { - return $this->getAuthenticationClass()->email_passwordless_start($email, $type, $authParams, $forwardedFor); - } - - /** - * Start passwordless login process for SMS. - * - * @param string $phoneNumber Phone number to use. - * @param string|null $forwardedFor Optional. Source IP address. requires Trust Token Endpoint IP Header - * - * @link https://auth0.com/docs/api/authentication#get-code-or-link - */ - public function smsPasswordlessStart( - string $phoneNumber, - ?string $forwardedFor = null - ): array { - return $this->getAuthenticationClass()->sms_passwordless_start($phoneNumber, $forwardedFor); - } - - /** - * If invitation parameters are present in the request, handle extraction and automatically redirect to Universal Login. - */ - public function handleInvitation() - { - $this->getSDK()->handleInvitation(); - } - - /** - * Extract invitation details from any incoming GET request. - */ - public function getInvitationParameters() - { - return $this->getSDK()->getInvitationParameters(); - } - - /** - * If the user is logged in, returns the user information. - * - * @return array with the User info as described in https://docs.auth0.com/user-profile and the user access token - */ - public function getUser() - { - // Get the user info from auth0 - $auth0 = $this->getSDK(); - $user = $auth0->getUser(); - - if ($user === null) { - return; - } - - return [ - 'profile' => $user, - 'accessToken' => $auth0->getAccessToken(), - ]; - } - - /** - * Sets a callback to be called when the user is logged in. - * - * @param mixed $cb A function that receives an auth0User and receives a Laravel user - */ - public function onLogin($cb) - { - $this->onLoginCb = $cb; - } - - /** - * @return bool - */ - public function hasOnLogin() - { - return $this->onLoginCb !== null; - } - - /** - * @param \Illuminate\Contracts\Auth\Authenticatable $auth0User - * - * @return mixed - */ - public function callOnLogin($auth0User) - { - $user = call_user_func($this->onLoginCb, $auth0User); - - if(is_array($user) || method_exists($user, 'toArray')) { - if(! is_array($user)) { - $array = $user->toArray(); - } else { - $array = $user; - } - - $this->getSDK()->setUser($array); - } - - return $user; - } - - /** - * Use this to either enable or disable the "remember" function for users. - * - * @param null $value - * - * @return bool|null - */ - public function rememberUser($value = null) - { - if ($value !== null) { - $this->rememberUser = $value; - } - - return $this->rememberUser; - } - - /** - * @param string $encUser - * @param array $verifierOptions - * - * @return array - * - * @throws \Auth0\SDK\Exception\InvalidTokenException - */ - public function decodeJWT($encUser, array $verifierOptions = []) - { - $token_issuer = 'https://'.$this->auth0Config['domain'].'/'; - $apiIdentifier = $this->auth0Config['api_identifier']; - $idTokenAlg = $this->auth0Config['supported_algs'][0] ?? 'RS256'; - - $signature_verifier = null; - if ($idTokenAlg === 'RS256') { - $jwksUri = $this->auth0Config['jwks_uri'] ?? 'https://'.$this->auth0Config['domain'].'/.well-known/jwks.json'; - $jwks_fetcher = new JWKFetcher($this->auth0Config['cache_handler']); - $jwks = $jwks_fetcher->getKeys($jwksUri); - $signature_verifier = new AsymmetricVerifier($jwks); - } elseif ($idTokenAlg === 'HS256') { - $signature_verifier = new SymmetricVerifier($this->auth0Config['client_secret']); - } else { - throw new \Auth0\SDK\Exception\InvalidTokenException('Unsupported token signing algorithm configured. Must be either RS256 or HS256.'); - } - - // Use IdTokenVerifier since Auth0-issued JWTs contain the 'sub' claim, which is used by the Laravel user model - $token_verifier = new TokenVerifier( - $token_issuer, - $apiIdentifier, - $signature_verifier - ); - - $this->apiuser = $token_verifier->verify($encUser, $verifierOptions); - return $this->apiuser; - } - - public function getIdToken() - { - return $this->getSDK()->getIdToken(); - } - - public function getAccessToken() - { - return $this->getSDK()->getAccessToken(); - } - - public function getRefreshToken() - { - return $this->getSDK()->getRefreshToken(); - } - - public function jwtuser() - { - return $this->apiuser; - } -} diff --git a/src/Auth0User.php b/src/Auth0User.php deleted file mode 100644 index 6d78295e..00000000 --- a/src/Auth0User.php +++ /dev/null @@ -1,114 +0,0 @@ -userInfo = $userInfo; - $this->accessToken = $accessToken; - } - - /** - * Get the unique identifier for the user. - * - * @return mixed - */ - public function getAuthIdentifier() - { - if (isset($this->userInfo['sub'])) { - return $this->userInfo['sub']; - } - - return $this->userInfo['user_id']; - } - - /** - * Get id field name. - * - * @return string - */ - public function getAuthIdentifierName() - { - return 'id'; - } - - /** - * Get the password for the user. - * - * @return string - */ - public function getAuthPassword() - { - return $this->accessToken; - } - - /** - * @return void - */ - public function getRememberToken() - { - } - - /** - * @param string $value - */ - public function setRememberToken($value) - { - } - - /** - * @return void - */ - public function getRememberTokenName() - { - } - - /** - * Add a generic getter to get all the properties of the userInfo. - * - * @return mixed|null Returns the related value, or null if not set. - */ - public function __get($name) - { - if (! array_key_exists($name, $this->userInfo)) { - return; - } - - return $this->userInfo[$name]; - } - - /** - * @return mixed - */ - public function getUserInfo() - { - return $this->userInfo; - } - - /** - * @return string - */ - public function __toString() - { - return json_encode($this->userInfo); - } -} diff --git a/src/Auth0UserProvider.php b/src/Auth0UserProvider.php deleted file mode 100644 index 2bd60a7e..00000000 --- a/src/Auth0UserProvider.php +++ /dev/null @@ -1,93 +0,0 @@ -userRepository = $userRepository; - $this->auth0 = $auth0; - } - - /** - * Lets make the repository take care of returning the user related to the - * identifier. - * - * @param mixed $identifier - * - * @return Authenticatable - */ - public function retrieveByID($identifier) - { - return $this->userRepository->getUserByIdentifier($identifier); - } - - /** - * @param array $credentials - * - * @return bool|Authenticatable - */ - public function retrieveByCredentials(array $credentials) - { - if (! isset($credentials['api_token'])) { - return null; - } - - $encUser = $credentials['api_token']; - - try { - $decodedJWT = $this->auth0->decodeJWT($encUser); - } catch (\Auth0\SDK\Exception\CoreException $e) { - return null; - } catch (\Auth0\SDK\Exception\InvalidTokenException $e) { - return null; - } - - return $this->userRepository->getUserByDecodedJWT($decodedJWT); - } - - /** - * Required method by the UserProviderInterface, we don't implement it. - */ - public function retrieveByToken($identifier, $token) - { - return null; - } - - /** - * Required method by the UserProviderInterface, we don't implement it. - */ - public function updateRememberToken(Authenticatable $user, $token) - { - } - - /** - * Required method by the UserProviderInterface, we don't implement it. - */ - public function validateCredentials(Authenticatable $user, array $credentials) - { - return null; - } -} diff --git a/src/Contract/Auth0UserRepository.php b/src/Contract/Auth0UserRepository.php deleted file mode 100644 index 92f79740..00000000 --- a/src/Contract/Auth0UserRepository.php +++ /dev/null @@ -1,31 +0,0 @@ -getSessionKeyName($key); - - \session([$key_name => $value]); - } - - /** - * @param string $key - * @param null $default - * - * @return mixed - */ - public function get(string $key, $default = null) - { - $key_name = $this->getSessionKeyName($key); - - return \session($key_name, $default); - } - - /** - * Removes a persisted value identified by $key. - * - * @see Auth0SDK\BaseAuth0 - * - * @param string $key - */ - public function delete(string $key) - { - $key_name = $this->getSessionKeyName($key); - - \session([$key_name => null]); - } - - /** - * Constructs a session var name. - * - * @param string $key - * - * @return string - */ - public function getSessionKeyName($key) - { - return self::BASE_NAME.'_'.$key; - } -} diff --git a/src/LoginServiceProvider.php b/src/LoginServiceProvider.php deleted file mode 100644 index df71b58a..00000000 --- a/src/LoginServiceProvider.php +++ /dev/null @@ -1,89 +0,0 @@ -make(Auth0UserProvider::class); - }); - - Auth::extend('auth0', static function ($app, $name, $config) { - return new RequestGuard(static function (Request $request, Auth0UserProvider $provider) { - return $provider->retrieveByCredentials(['api_token' => $request->bearerToken()]); - }, $app['request'], $app['auth']->createUserProvider($config['provider'])); - }); - - $this->publishes([ - __DIR__.'/../../config/config.php' => config_path('laravel-auth0.php'), - ]); - - $laravel = app(); - - $oldInfoHeaders = ApiClient::getInfoHeadersData(); - - if ($oldInfoHeaders) { - $infoHeaders = InformationHeaders::Extend($oldInfoHeaders); - - $infoHeaders->setEnvProperty('Laravel', $laravel::VERSION); - $infoHeaders->setPackage('laravel-auth0', self::SDK_VERSION); - - ApiClient::setInfoHeadersData($infoHeaders); - } - } - - /** - * Register the service provider. - */ - public function register() - { - $this->app->bind(StoreInterface::class, static function () { - return new LaravelSessionStore(); - }); - - $this->app->bind(Auth0UserRepositoryContract::class, Auth0UserRepository::class); - - // Bind the auth0 name to a singleton instance of the Auth0 Service - $this->app->singleton(Auth0Service::class, static function ($app) { - return new Auth0Service( - $app->make('config')->get('laravel-auth0'), - $app->make(StoreInterface::class), - $app->make('cache.store') - ); - }); - $this->app->singleton('auth0', function () { - return $this->app->make(Auth0Service::class); - }); - - // When Laravel logs out, logout the auth0 SDK trough the service - Event::listen('auth.logout', static function () { - app('auth0')->logout(); - }); - Event::listen('user.logout', static function () { - app('auth0')->logout(); - }); - Event::listen('Illuminate\Auth\Events\Logout', static function () { - app('auth0')->logout(); - }); - } -} diff --git a/src/Repository/Auth0UserRepository.php b/src/Repository/Auth0UserRepository.php deleted file mode 100644 index 94439e5e..00000000 --- a/src/Repository/Auth0UserRepository.php +++ /dev/null @@ -1,58 +0,0 @@ -getUser(); - - if ($user === null) { - return null; - } - - // Build the user - $auth0User = $this->getUserByUserInfo($user); - - // It is not the same user as logged in, it is not valid - if ($auth0User && $auth0User->getAuthIdentifier() === $identifier) { - return $auth0User; - } - - return null; - } -}