本文整理汇总了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;
}
示例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;
}
示例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');
}
示例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.');
}
示例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;
}
示例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;
}
示例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)
{
$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;
}
示例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;
}
示例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());
}
示例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');
}
示例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;
}
示例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');
}
}
示例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));
}
}
示例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;
}