当前位置: 首页>>代码示例>>PHP>>正文


PHP TokenInterface::getCredentials方法代码示例

本文整理汇总了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());
 }
开发者ID:TJUSSE,项目名称:ICSS,代码行数:30,代码来源:HybridAuthenticator.php

示例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());
 }
开发者ID:AlexEvesDeveloper,项目名称:hl-stuff,代码行数:14,代码来源:AbstractAuthenticator.php

示例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.');
 }
开发者ID:aml-bendall,项目名称:ExpandAkeneoApi,代码行数:9,代码来源:Provider.php

示例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());
 }
开发者ID:formvault,项目名称:Antenna,代码行数:10,代码来源:UsernamePasswordAuthenticator.php

示例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());
 }
开发者ID:phppro,项目名称:sso,代码行数:15,代码来源:SsoPreAuthenticator.php

示例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());
 }
开发者ID:ekreative,项目名称:redmine-login,代码行数:12,代码来源:RedmineSimpleFormAuthenticator.php

示例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;
 }
开发者ID:ProPheT777,项目名称:silex-rest-skeleton,代码行数:22,代码来源:JWTAuthenticationProvider.php

示例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;
 }
开发者ID:pnnartas,项目名称:destek-sistemi,代码行数:14,代码来源:AuthProvider.php

示例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;
 }
开发者ID:Okami-,项目名称:ilios,代码行数:28,代码来源:JsonWebTokenAuthenticator.php

示例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"];
 }
开发者ID:heidilabs,项目名称:HeidiLabsSauthBundle,代码行数:10,代码来源:GoogleService.php

示例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;
 }
开发者ID:nucleartux,项目名称:HWIOAuthBundle,代码行数:19,代码来源:OAuthProvider.php

示例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;
 }
开发者ID:koenreiniers,项目名称:oauth-server-bundle,代码行数:35,代码来源:ClientCredentialsProvider.php

示例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;
 }
开发者ID:evaneos,项目名称:silex-jwt-provider,代码行数:25,代码来源:JWTAuthenticationProvider.php

示例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());
 }
开发者ID:gobudgit,项目名称:gobudgit,代码行数:16,代码来源:OauthAuthenticator.php

示例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());
 }
开发者ID:heidilabs,项目名称:HeidiLabsSauthBundle,代码行数:33,代码来源:SauthAuthenticator.php


注:本文中的Symfony\Component\Security\Core\Authentication\Token\TokenInterface::getCredentials方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。