Authenticate a user via a token.

@param mixed $token

@return mixed
506182
public function authenticate($token = false)
    {
        $id = $this->getPayload($token)->get('sub');
        if (! $this->auth->byId($id)) {
            return false;
        }

        return $this->auth->user();
    }
571663
protected function refreshAccessToken($token)
    {
        switch ($this->grant) {
            case 'provided_token':
                throw new UnauthorizedException('[internal]', 'The provided token expired.');

            case 'client_credentials':
                return $this->getTokenByClientCredentialsGrant();

            case 'authorization_code':
                return $this->getTokenByRefreshTokenGrant($token);

            default:
                throw new \Exception('Unsupported grant type. Check $this->grant.');
        }
    }
447705
public function decryptToken(string $token)
    {
        $tokenData = false;
        $encrypted = base64_decode($token);

        if ($encrypted) {
            $serialized = Security::decrypt($encrypted, Configure::read('Security.cryptKey'));
            $tokenData = unserialize($serialized);
        }

        return $tokenData;
    }
569765
protected function _decode($token)
    {
        $config = $this->_config;
        try {
            $payload = JWT::decode(
                $token,
                $config['key'] ?: Security::getSalt(),
                $config['allowedAlgs']
            );

            return $payload;
        } catch (Exception $e) {
            if (Configure::read('debug')) {
                throw $e;
            }
            $this->_error = $e;
        }
    }
1237326
public function verifyEmailToken($token)
	{
		$this->debug->groupCollapsed(__METHOD__);
		$return = false;
		$token = base64_decode($token);
		$vals = array(
			'token_hash' => $this->db->quoteValue(sha1($token)),
		);
		$query = Str::quickTemp('SELECT * FROM `email_tokens`
			WHERE `token_hash` = [::token_hash::]', $vals);
		$rows = $this->db->query($query)[0];
		$this->debug->table($rows, 'rows');
		if ($rows) {
			// found token in table
			$return = $rows[0]['userid'];
			// remove the token
			$where = $vals;
			$this->db->rowMan('email_tokens', null, $where);
			$this->log('pwForgotTokenSuccess', $rows[0]['userid']);
		} else {
			$this->log('pwForgotTokenFail');
		}
		$this->debug->groupEnd();
		return $return;
	}
1189650
public function getUserFromToken($token)
    {
        $expiration = U::unixToDb(time() - UserLink::$forgotLinkTimeframe);
        $link = UserLink::where('link', $token)
            ->where('type', UserLink::FORGOT_PASSWORD)
            ->where('created_at', $expiration, '>')
            ->first();

        if (!$link) {
            throw new AuthException('This link has expired or is invalid.');
        }

        $userClass = $this->auth->getUserClass();

        return $userClass::find($link->user_id);
    }
530865
public function decode($token)
    {
        $decoded = json_decode($token, true);

        if (is_array($decoded) === true &&
            array_key_exists(self::KEY_USER_ID, $decoded) === true &&
            array_key_exists(self::KEY_SECRET, $decoded) === true
        ) {
            $token  = $decoded[self::KEY_SECRET];
            $userId = intval($decoded[self::KEY_USER_ID]);
            /** @var User $user */
            $user   = (new User())->query()->find($userId);

            if ($user !== null && $user->{User::FIELD_API_TOKEN} === $token) {
                $account = new Account($user, [Account::ATTR_ID => $userId]);

                $this->getLogger()->debug('Account authenticated.', [User::FIELD_ID => $userId]);

                return $account;
            }
        }

        return new Anonymous();
    }
993613
protected function checkToken($token)
    {
        try {
            $response = $this->http->get($this->checkTokenURL(), [
                'headers' => [
                    'X-Requested-With' => 'XMLHttpRequest',
                    'Authorization' => 'Bearer ' . $token
                ]
            ]);
            $content = json_decode($response->getBody()->getContents());
            if (isset($content->message)) {
                if ($content->message === 'Token is valid') {
                    return true;
                }
            }
        } catch (\Exception $e) {
            return false;
        }
        return false;
    }
1123514
protected function getUserByToken($token) {
		$response = $this->getHttpClient()->request('GET', 'https://openapi.naver.com/v1/nid/getUserProfile.xml', [
			'headers' => [
				'Authorization' => 'Bearer ' . $token,
		    ],
		]);
		
		$xml = $response->getBody()->getContents();
		
		return $this->parseXML($xml)['response'];
		
	}
1001788
public function handlesToken($token)
    {
        return (
            isset($this->tokensHandled)
            && is_array($this->tokensHandled)
            && in_array($token, $this->tokensHandled)
        );
    }
583086
public function verifyToken(Token $token)
    {
        $alg = $token->getHeader('alg');

        if (empty($this->supportedAlgs[$alg])) {
            throw new InvalidParamException('Algorithm not supported');
        }

        $signer = Yii::createObject($this->supportedAlgs[$alg]);
        return $token->verify($signer, $this->key);
    }
225684
public function getByAccessToken(string $token)
	{
		return $this->setAuthorizer($this->getModel()->where('access_token', '=', $token)->first());
	}
241845
protected function _token($token = null)
    {
        if ($token) {
            return $token;
        }

        $token = $this->_request()->data('token');
        if ($token) {
            return $token;
        }

        $token = $this->_request()->param('token');
        if ($token) {
            return $token;
        }

        return $this->_request()->query('token');
    }
662482
protected function requireToken($token)
    {
        if ($token) {
            return $this->setToken($token);
        } elseif ($this->token) {
            return $this;
        } else {
            throw new JWTException('A token is required', 400);
        }
    }
1189152
protected function doGetAuthenticationInfo($token)
    {
        if(!token instanceof UsernamePasswordToken)
            throw new Exception('Invalid Token Type');
        $user = $token->getPrincipal();
        if(!$user)
            throw new Exception('Null usernames not permitted');
        $password = $this->_getPasswordFromDB($user);
        $account = new DefaultAccount($user, $password);
        return $account;
    
    }
381954
public function actionLoginCallback($token)
    {
        /** @var \amnah\yii2\user\models\User $user */
        /** @var \amnah\yii2\user\models\Profile $profile */
        /** @var \amnah\yii2\user\models\Role $role */
        /** @var \amnah\yii2\user\models\UserToken $userToken */

        $user = $this->module->model("User");
        $profile = $this->module->model("Profile");
        $userToken = $this->module->model("UserToken");

        // check token and log user in directly
        $userToken = $userToken::findByToken($token, $userToken::TYPE_EMAIL_LOGIN);
        if ($userToken && $userToken->user) {
            $returnUrl = $this->performLogin($userToken->user, $userToken->data);
            $userToken->delete();
            return $this->redirect($returnUrl);
        }

        // load post data
        $post = Yii::$app->request->post();
        $userLoaded = $user->load($post);
        $profileLoaded = $profile->load($post);
        if ($userToken && ($userLoaded || $profileLoaded)) {

            // ensure that email is taken from the $userToken (and not from user input)
            $user->email = $userToken->data;

            // validate and register
            if ($user->validate() && $profile->validate()) {
                $role = $this->module->model("Role");
                $user->setRegisterAttributes($role::ROLE_USER, $user::STATUS_ACTIVE)->save();
                $profile->setUser($user->id)->save();

                // log user in and delete token
                $returnUrl = $this->performLogin($user);
                $userToken->delete();
                return $this->redirect($returnUrl);
            }
        }

        $user->email = $userToken ? $userToken->data : null;
        return $this->render("loginCallback", compact("user", "profile", "userToken"));
    }
845831
public function processRequestToken($token) {
        // Setup the params
        $params = [
            'client_id'     => $this->clientID,
            'client_secret' => $this->secret,
            'code'          => $token,
            'grant_type'    => 'authorization_code',
            'redirect_uri'  => $this->redirectURI
        ];

        // Parse the cURL result
        return CURL::post($this->url, $params);
    }