/** * @param string $userId * @return mixed */ public function findOne($userId) { if ('' != $userId) { return ApiUsers::get(Yii::$app->getModule('auth0')->domain, Yii::$app->getModule('auth0')->apiTokens['usersRead'], $userId); } return false; }
/** * Exchanges the code from the URI parameters for an access token, id token and user info * @return Boolean Wheter it exchanged the code or not correctly */ private function exchangeCode() { if (!isset($_REQUEST['code'])) { return false; } $code = $_REQUEST['code']; $this->debugInfo("Code: " . $code); // Generate the url to the API that will give us the access token and id token $auth_url = $this->generateUrl('token'); // Make the call $auth0_response = $this->oauth_client->getAccessToken($auth_url, "authorization_code", array("code" => $code, "redirect_uri" => $this->redirect_uri)); // Parse it $auth0_response = $auth0_response['result']; $this->debugInfo(json_encode($auth0_response)); $access_token = isset($auth0_response['access_token']) ? $auth0_response['access_token'] : false; $id_token = isset($auth0_response['id_token']) ? $auth0_response['id_token'] : false; if (!$access_token) { throw new ApiException('Invalid access_token - Retry login.'); } // Set the access token in the oauth client for future calls to the Auth0 API $this->oauth_client->setAccessToken($access_token); $this->oauth_client->setAccessTokenType(Client::ACCESS_TOKEN_BEARER); // Set it and persist it, if needed $this->setAccessToken($access_token); $this->setIdToken($id_token); $token = Auth0JWT::decode($id_token, $this->client_id, $this->client_secret); $user = ApiUsers::get($this->domain, $id_token, $token->user_id); $this->setUser($user); return true; }
public function privatePing() { $userData = \Auth0\SDK\Api\ApiUsers::get(getenv('AUTH0_DOMAIN'), $this->token, $this->tokenInfo->sub); return array("status" => 'ok', "message" => 'Shh, it\' secret', "user" => array("email" => $userData["email"], "username" => $userData["username"])); }
/** * Get the Auth0 User Profile based on the JWT (and validate it). * * @return User info as described in https://docs.auth0.com/user-profile */ public function getUserProfileByA0UID($jwt, $a0UID) { return ApiUsers::get($this->domain, $jwt, $a0UID); }