本文整理匯總了PHP中Symfony\Component\Security\Core\Authentication\Token\TokenInterface::getPassword方法的典型用法代碼示例。如果您正苦於以下問題:PHP TokenInterface::getPassword方法的具體用法?PHP TokenInterface::getPassword怎麽用?PHP TokenInterface::getPassword使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Symfony\Component\Security\Core\Authentication\Token\TokenInterface
的用法示例。
在下文中一共展示了TokenInterface::getPassword方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: authenticate
public function authenticate(TokenInterface $token)
{
if (strlen($token->getOAuthToken()) === 0) {
$url = $this->remoteApiUrl . "/oauth/v2/token?" . "client_id=" . $this->remoteApiId . "&client_secret=" . $this->remoteApiSecret . "&grant_type=password" . "&username=" . $token->getUser() . "&password=" . $token->getPassword();
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$apiResponse = json_decode(curl_exec($ch));
curl_close($ch);
if (isset($apiResponse->access_token)) {
$user = $this->userManager->createUser();
$user->setUsername($token->getUsername());
$authenticatedToken = new OAuthUserToken($user->getRoles());
$authenticatedToken->setUser($user);
$authenticatedToken->setOAuthToken($apiResponse->access_token);
$authenticatedToken->setRefreshToken($apiResponse->refresh_token);
$authenticatedToken->setTokenType($apiResponse->token_type);
// We take 3 minutes less (180 seconds) just to be sure.
$authenticatedToken->setExpireTime(time() + $apiResponse->expires_in - 180);
return $authenticatedToken;
} elseif (isset($apiResponse->error_description)) {
throw new AuthenticationException($apiResponse->error_description);
} else {
throw new AuthenticationException('The OAuth authentication failed.');
}
} else {
return $token;
}
}