當前位置: 首頁>>代碼示例>>PHP>>正文


PHP TokenInterface::setClient方法代碼示例

本文整理匯總了PHP中Symfony\Component\Security\Core\Authentication\Token\TokenInterface::setClient方法的典型用法代碼示例。如果您正苦於以下問題:PHP TokenInterface::setClient方法的具體用法?PHP TokenInterface::setClient怎麽用?PHP TokenInterface::setClient使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Symfony\Component\Security\Core\Authentication\Token\TokenInterface的用法示例。


在下文中一共展示了TokenInterface::setClient方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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

 /**
  * 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::setClient方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。