當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。