本文整理汇总了PHP中Symfony\Component\Security\Core\Authentication\Token\TokenInterface::getCredentials方法的典型用法代码示例。如果您正苦于以下问题:PHP TokenInterface::getCredentials方法的具体用法?PHP TokenInterface::getCredentials怎么用?PHP TokenInterface::getCredentials使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Security\Core\Authentication\Token\TokenInterface
的用法示例。
在下文中一共展示了TokenInterface::getCredentials方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: authenticateToken
public function authenticateToken(TokenInterface $token, UserProviderInterface $userProvider, $providerKey)
{
// 检查 user provider
if (!$userProvider instanceof HybridUserProvider) {
throw new \InvalidArgumentException(sprintf('The user provider must be an instance of HybridUserProvider (%s was given).', get_class($userProvider)));
}
$credential = $token->getCredentials();
$user = $token->getUser();
if ($user instanceof HybridUser) {
return new PreAuthenticatedToken($user, $credential, $providerKey, $user->getRoles());
}
if ($credential['type'] === 'sso') {
// 检查 SSO token
$username = $userProvider->getUsernameForToken($credential['token']);
if (!$username) {
throw new AuthenticationException('统一身份登录会话无效,可能会话已过期。');
}
} else {
if ($token->getCredentials()['type'] === 'internal') {
$username = $userProvider->getUsernameForInternalUser($credential['user'], $credential['pass']);
if (!$username) {
throw new AuthenticationException('用户名或密码错误。');
}
} else {
throw new AccessDeniedException('不支持的登录认证类型。');
}
}
$user = $userProvider->loadUserByUsername($username);
return new PreAuthenticatedToken($user, $credential, $providerKey, $user->getRoles());
}
示例2: authenticateToken
/**
* @param TokenInterface $token
* @param UserProviderInterface $userProvider
* @param string $providerKey
*
* @return PreAuthenticatedToken
*/
public function authenticateToken(TokenInterface $token, UserProviderInterface $userProvider, $providerKey)
{
if (!($user = $token->getUser()) instanceof UserInterface) {
$user = $this->userProvider->loadUserByUsername($token->getCredentials());
}
return new PreAuthenticatedToken($user, $token->getCredentials(), $providerKey, $user->getRoles());
}
示例3: authenticate
public function authenticate(TokenInterface $token)
{
$user = $this->userProvider->loadUserByUsername($token->getUsername());
if ($user && $this->validateDigest($token->getCredentials(), $token->getAttribute('nonce'), $token->getAttribute('created'), $this->getSecret($user), $this->getSalt($user))) {
$authenticatedToken = new Token($user, $token->getCredentials(), $this->providerKey, $user->getRoles());
return $authenticatedToken;
}
throw new AuthenticationException('WSSE authentication failed.');
}
示例4: authenticateToken
public function authenticateToken(TokenInterface $token, UserProviderInterface $userProvider, $providerKey)
{
$user = $userProvider->loadUserByUsername($token->getUsername());
$this->userChecker->checkPreAuth($user);
if (!$this->encoder->isPasswordValid($user, $token->getCredentials())) {
throw new BadCredentialsException('The presented password is invalid.');
}
$this->userChecker->checkPostAuth($user);
return new UsernamePasswordToken($user, $token->getCredentials(), $providerKey, $user->getRoles());
}
示例5: authenticateToken
/**
* {@inheritdoc}
*/
public function authenticateToken(TokenInterface $token, UserProviderInterface $userProvider, $providerKey)
{
if (is_subclass_of($token->getUser(), $this->userClass)) {
return new PreAuthenticatedToken($token->getUser(), $token->getCredentials(), $providerKey, $token->getUser()->getRoles());
}
$ssoToken = $this->tokenRepository->find($token->getCredentials());
if (!$ssoToken) {
throw new AuthenticationException();
}
$user = $userProvider->loadUserByUsername($ssoToken->getUsername());
return new PreAuthenticatedToken($user, $token->getCredentials(), $providerKey, $user->getRoles());
}
示例6: authenticateToken
public function authenticateToken(TokenInterface $token, UserProviderInterface $userProvider, $providerKey)
{
if (!$userProvider instanceof RedmineUserProvider) {
throw new \InvalidArgumentException(sprintf('The user provider must be an instance of RedmineUserProvider (%s was given).', get_class($userProvider)));
}
$apiKey = $token->getCredentials();
$user = $userProvider->getUserForUsernamePassword($token->getUsername(), $token->getCredentials());
if (!$user) {
throw new AuthenticationException('Invalid credentials');
}
return new UsernamePasswordToken($user, $apiKey, $providerKey, $user->getRoles());
}
示例7: authenticate
/**
* Attempts to authenticate a TokenInterface object.
*
* @param TokenInterface $token The TokenInterface instance to authenticate
*
* @return TokenInterface An authenticated TokenInterface instance, never null
*
* @throws AuthenticationException if the authentication fails
*/
public function authenticate(TokenInterface $token)
{
if (!$token instanceof JWTToken) {
throw new AuthenticationException(sprintf('%s works only for JWTToken', __CLASS__));
}
if (!$token->getCredentials()) {
throw new AuthenticationException('JWTToken must contain a token in order to authenticate.');
}
$decodedToken = $this->JWTDecoder->decode($token->getCredentials());
$user = $this->userConverter->buildUserFromToken($decodedToken);
$token->setUser($user);
return $token;
}
示例8: authenticate
public function authenticate(TokenInterface $token)
{
$user = $this->userProvider->loadUserByUsername($token->getUser(), $token->getCredentials());
$newToken = new UserToken($token->getUser(), $token->getCredentials(), "main", $user->getRoles());
$encoder = $this->encoder->getEncoder($user);
// compute the encoded password
$encodedPassword = $encoder->encodePassword($token->getCredentials(), $user->salt);
$newToken = new UserToken($token->getUser(), $token->getCredentials(), "secured_area", $user->getRoles());
$username = $newToken->getUser();
if (empty($username) || $user->getPassword() != $encodedPassword) {
throw new BadCredentialsException('Bad credentials :)');
}
return $newToken;
}
示例9: authenticateToken
public function authenticateToken(TokenInterface $token, UserProviderInterface $userProvider, $providerKey)
{
if (!$userProvider instanceof EntityUserProvider) {
throw new \InvalidArgumentException(sprintf('The user provider must be an instance of EntityUserProvider (%s was given).', get_class($userProvider)));
}
try {
$jwt = $token->getCredentials();
$username = $this->jwtManager->getUserIdFromToken($jwt);
$issuedAt = $this->jwtManager->getIssuedAtFromToken($jwt);
} catch (\UnexpectedValueException $e) {
throw new BadCredentialsException('Invalid JSON Web Token: ' . $e->getMessage());
} catch (\Exception $e) {
throw new BadCredentialsException('Invalid JSON Web Token');
}
$user = $userProvider->loadUserByUsername($username);
$authentication = $user->getAuthentication();
if ($authentication) {
$tokenNotValidBefore = $authentication->getInvalidateTokenIssuedBefore();
if ($tokenNotValidBefore) {
if ($tokenNotValidBefore > $issuedAt) {
throw new BadCredentialsException('Invalid JSON Web Token: Not issued before ' . $tokenNotValidBefore->format('c'));
}
}
}
$authenticatedToken = new PreAuthenticatedToken($user, $jwt, $providerKey);
$authenticatedToken->setAuthenticated(true);
return $authenticatedToken;
}
示例10: authenticate
/**
* {@inheritdoc}
*/
public function authenticate(TokenInterface $token, UserProviderInterface $userProvider)
{
$this->googleClient->authenticate($token->getCredentials());
$this->gtoken = json_decode($this->googleClient->getAccessToken());
$attributes = $this->googleClient->verifyIdToken($this->gtoken->id_token)->getAttributes();
return $attributes["payload"]["sub"];
}
示例11: authenticate
/**
* {@inheritDoc}
*/
public function authenticate(TokenInterface $token)
{
$resourceOwner = $this->resourceOwnerMap->getResourceOwnerByName($token->getResourceOwnerName());
$userResponse = $resourceOwner->getUserInformation($token->getCredentials());
try {
$user = $this->userProvider->loadUserByOAuthUserResponse($userResponse);
} catch (OAuthAwareExceptionInterface $e) {
$e->setAccessToken($token->getCredentials());
$e->setResourceOwnerName($token->getResourceOwnerName());
throw $e;
}
$token = new OAuthToken($token->getCredentials(), $user->getRoles());
$token->setUser($user);
$token->setAuthenticated(true);
return $token;
}
示例12: authenticate
/**
* Attempts to authenticate a GrantToken
*
* @param GrantToken $token
*
* @return GrantToken
*
* @throws AuthenticationException
*/
public function authenticate(TokenInterface $token)
{
$credentials = $token->getCredentials();
$clientId = $credentials['client_id'];
/** @var ClientInterface $client */
$client = $this->clientRepository->find($clientId);
// Verify client id
if (!$client) {
throw new AuthenticationException("Client with id {$clientId} does not exist");
}
// Verify client secret
$clientSecret = $credentials['client_secret'];
if (!$client->getSecret() === $clientSecret) {
throw new AuthenticationException("Invalid client secret");
}
// Verify grant type
if (!in_array($token->getGrantType(), $client->getAllowedGrantTypes())) {
throw new AuthenticationException("Grant type not allowed");
}
if ($client->getUser() === null) {
throw new AuthenticationException("Client is not associated with any user");
}
$token->setUser($client->getUser());
$token->setClient($client);
return $token;
}
示例13: authenticate
/**
* Attempts to authenticate a TokenInterface object.
*
* @param TokenInterface $token The TokenInterface instance to authenticate
*
* @throws AuthenticationException if the authentication fails
* @return TokenInterface An authenticated TokenInterface instance, never null
*
*/
public function authenticate(TokenInterface $token)
{
if (!$token instanceof JWTToken) {
throw new AuthenticationException(sprintf('%s works only for JWTToken', __CLASS__));
}
if (!$token->getCredentials()) {
throw new AuthenticationException('JWTToken must contain a token in order to authenticate.');
}
try {
$user = $this->userBuilder->buildUserFromToken($token->getCredentials());
} catch (JWTDecodeUnexpectedValueException $e) {
throw new AuthenticationException('Failed to decode the JWT');
}
$token->setUser($user);
return $token;
}
示例14: authenticateToken
public function authenticateToken(TokenInterface $token, UserProviderInterface $userProvider, $providerKey)
{
try {
$this->resourceServer->isValidRequest(true);
} catch (AccessDeniedException $e) {
throw new AuthenticationException(sprintf('OAuth token "%s" does not exist or is expired.', $token->getCredentials()));
}
$userIdentifier = $this->resourceServer->getAccessToken()->getSession()->getOwnerId();
try {
$user = $userProvider->loadUserByUsername($userIdentifier);
} catch (UsernameNotFoundException $e) {
$e->setUsername($userIdentifier);
throw $e;
}
return new PreAuthenticatedToken($user, $token->getCredentials(), $providerKey, $user->getRoles());
}
示例15: authenticateToken
/**
* {@inheritdoc}
*/
public function authenticateToken(TokenInterface $token, UserProviderInterface $userProvider, $providerKey)
{
if (!$userProvider instanceof UserManager) {
throw new \InvalidArgumentException(sprintf('The user provider must be an instance of UserManager (%s was given).', get_class($userProvider)));
}
$user = $token->getUser();
if ($user instanceof AbstractUser) {
return new SauthToken($user, $token->getCredentials(), $providerKey, $user->getRoles());
}
$service = $this->oauth->getService($token->getServiceId());
$userId = $service->authenticate($token, $userProvider);
if (!$userId) {
throw new AuthenticationException(sprintf('Authentication Problem.'));
}
$credentials = $userProvider->getCredentials($token->getServiceId(), $userId);
if ($credentials) {
$user = $credentials->getUser();
} else {
$username = $service->getUsername($userId);
$user = $userProvider->loadUserByUsername($username);
if (!$user) {
if ($this->allowRegistration === false) {
throw new AccessDeniedException("We couldn't find a user matching these credentials. New registrations are currently closed.");
}
$user = $userProvider->createNew($username);
}
$userProvider->saveCredentials($user, $token->getServiceId(), $userId, $service->getUserTokens());
}
return new SauthToken($user, $token->getCredentials(), $providerKey, $user->getRoles());
}