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


PHP TokenInterface::setUser方法代码示例

本文整理汇总了PHP中Symfony\Component\Security\Core\Authentication\Token\TokenInterface::setUser方法的典型用法代码示例。如果您正苦于以下问题:PHP TokenInterface::setUser方法的具体用法?PHP TokenInterface::setUser怎么用?PHP TokenInterface::setUser使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symfony\Component\Security\Core\Authentication\Token\TokenInterface的用法示例。


在下文中一共展示了TokenInterface::setUser方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: 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

示例2: 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");
     }
     // Verify refresh_token
     $refreshToken = $this->refreshTokenRepository->findOneBy(["token" => $credentials['refresh_token'], "client" => $client]);
     if ($refreshToken === null) {
         throw new AuthenticationException("Invalid token");
     }
     // Verify expiry date
     if ($refreshToken->isExpired()) {
         throw new AuthenticationException("Token has expired");
     }
     $user = $refreshToken->getUser();
     $token->setUser($user);
     $token->setClient($client);
     return $token;
 }
开发者ID:koenreiniers,项目名称:oauth-server-bundle,代码行数:42,代码来源:RefreshTokenProvider.php

示例3: authenticate

 public function authenticate(TokenInterface $token)
 {
     $user = $this->userProvider->loadUserByUsername($token->getCredentials());
     if ($user) {
         $token->setUser($user);
         return $token;
     }
     throw new AuthenticationException('Unable to get user for this token');
 }
开发者ID:profcab,项目名称:ilios,代码行数:9,代码来源:Provider.php

示例4: authenticate

 public function authenticate(TokenInterface $token)
 {
     $user = $this->userProvider->loadUserByUsername($token->getUsername());
     die("XXX");
     if ($user && $this->validateLdapUser($user)) {
         $token->setUser($user);
         return $token;
     }
     throw new AuthenticationException('The LDAP authentication failed.');
 }
开发者ID:mapbender,项目名称:fom,代码行数:10,代码来源:LdapProvider.php

示例5: authenticate

 public function authenticate(TokenInterface $token)
 {
     $user = $this->userProvider->loadUserByUsername($token->getUsername());
     if (empty($user) || $user->checkToken($token->token) === false) {
         throw new AuthenticationException('Token authentication failed.');
     }
     $token->setAuthenticated(true);
     $token->setUser($user);
     return $token;
 }
开发者ID:rimi-itk,项目名称:bpi-web-service,代码行数:10,代码来源:PKProvider.php

示例6: authenticateToken

 public function authenticateToken(TokenInterface $token, UserProviderInterface $userProvider, $providerKey)
 {
     $accessToken = $token->getCredentials();
     try {
         $user = $userProvider->loadUserByUsername($accessToken);
     } catch (UsernameNotFoundException $e) {
         throw new UnauthorizedApiException($e->getMessage());
     }
     $token->setUser($user);
     return $token;
 }
开发者ID:enneite,项目名称:swagger-bundle,代码行数:11,代码来源:ApiAuthenticator.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)
 {
     $this->service_container->get($this->wordpress_loader_id)->load();
     $user = wp_get_current_user();
     if (isset($user->data) && isset($user->data->user_nicename)) {
         $token->setUser($user->data->user_email);
         $token->setAuthenticated(true);
         //$token->setRoles(array());
     } else {
         $token->setRedirectUrl($this->redirect_url);
     }
     return $token;
 }
开发者ID:cmoncy,项目名称:WordpressBundle,代码行数:13,代码来源:WordpressAuthenticationProvider.php

示例9: authenticate

 /**
  * Attempts to authenticate a GrantToken
  *
  * @param OAuthToken $token
  *
  * @return OAuthToken
  *
  * @throws AuthenticationException
  */
 public function authenticate(TokenInterface $token)
 {
     $tokenValue = $token->getCredentials();
     $accessToken = $this->accessTokenRepository->findOneBy(["token" => $tokenValue]);
     if ($accessToken === null) {
         throw new AuthenticationException("Invalid access token");
     }
     if ($accessToken->isExpired()) {
         throw new AuthenticationException("Access token has expired");
     }
     $user = $accessToken->getUser();
     $token->setUser($user);
     return $token;
 }
开发者ID:koenreiniers,项目名称:oauth-server-bundle,代码行数:23,代码来源:AccessTokenProvider.php

示例10: 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)
 {
     /** @var SignedTokenInterface $token */
     $user = $this->userProvider->loadUserByUsername($token->getUsername());
     $signData = $this->getAuthSignData($token->getRequest());
     $signData[] = $user->{$this->config['secret_getter']}();
     $expectedSignature = hash($this->config['hash_alg'], implode($this->config['data_delimiter'], $signData));
     if ($token->getSignature() == $expectedSignature) {
         $token->setUser($user);
         return $token;
     }
     $this->logger->critical(sprintf('Invalid auth signature. Expect "%s", got "%s"', $expectedSignature, $token->getSignature()), ['signData' => $signData]);
     throw new AuthenticationException("Invalid auth signature " . $token->getSignature());
 }
开发者ID:epustobaev,项目名称:signed-auth-bundle,代码行数:23,代码来源:SignedAuthProvider.php

示例11: 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) {
         $userName = $token->getTokenContext()->name;
     } else {
         $userName = $token->getUsername();
     }
     $user = $this->userProvider->loadUserByUsername($userName);
     if (null != $user) {
         $token->setUser($user);
         return $token;
     }
     throw new AuthenticationException('JWT auth failed');
 }
开发者ID:bananos,项目名称:kanban,代码行数:23,代码来源:JWTProvider.php

示例12: 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

示例13: 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)
 {
     $params = $token->getRequestParameters();
     if (!empty($params['ask_response']) && $params['ask_response'] == 'give_response') {
         $response = new Response();
         $response->setContent('mockedResponseWithAskResponseParameter');
         return $response;
     }
     if ($params['oauth_token'] == 'nnch734d00sl2jdk') {
         $user = new UserMock('123456789', 'testUser', 'email@email.email');
         $token->setUser($user);
         return $token;
     } else {
         throw new AuthenticationException('OAuth authentication failed');
     }
 }
开发者ID:cultuurnet,项目名称:symfony-security-oauth,代码行数:25,代码来源:OAuthAuthenticationProviderMock.php

示例14: setUser

 /**
  * @param mixed $user
  * @param TokenInterface $token
  * @throws \InvalidArgumentException
  */
 protected function setUser($user, TokenInterface $token)
 {
     if (!$user) {
         return;
     }
     $userId = filter_var($user, FILTER_VALIDATE_INT);
     if ($userId) {
         $userEntity = $this->registry->getRepository('OroUserBundle:User')->find($userId);
     } else {
         $userEntity = $this->userManager->findUserByUsernameOrEmail($user);
     }
     if ($userEntity) {
         $token->setUser($userEntity);
     } else {
         throw new \InvalidArgumentException(sprintf('Can\'t find user with identifier %s', $user));
     }
 }
开发者ID:xamin123,项目名称:platform,代码行数:22,代码来源:ConsoleContextListener.php

示例15: 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");
     }
     // Verify redirect uri
     $redirectUri = $credentials['redirect_uri'];
     if (!in_array($redirectUri, $client->getRedirectUris())) {
         throw new AuthenticationException("Invalid redirect uri");
     }
     // Verify authorization code
     $code = $credentials['code'];
     $authorizationCode = $this->authorizationCodeRepository->findOneBy(["code" => $code, "client" => $client]);
     if ($authorizationCode === null) {
         throw new AuthenticationException("Invalid code");
     }
     // Verify that redirect uri's match
     if ($authorizationCode->getRedirectUri() !== $redirectUri) {
         throw new AuthenticationException("Redirect uri does not match redirect uri from previous request");
     }
     // Verify expiry date
     if ($authorizationCode->isExpired()) {
         throw new AuthenticationException("Code has expired");
     }
     $user = $authorizationCode->getUser();
     $token->setUser($user);
     $token->setClient($client);
     return $token;
 }
开发者ID:koenreiniers,项目名称:oauth-server-bundle,代码行数:52,代码来源:AuthorizationCodeProvider.php


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