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


PHP AccessTokenEntity::setSession方法代码示例

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


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

示例1: completeFlow

 /**
  * Complete the client credentials grant
  *
  * @return array
  *
  * @throws
  */
 public function completeFlow()
 {
     $selfClient = app('selfClient');
     // Get the required params
     if (is_null($selfClient)) {
         throw new Exception\InvalidClientException();
     }
     // Validate client ID and client secret
     $client = $this->server->getClientStorage()->get($selfClient->id, $selfClient->secret, null, $this->getIdentifier());
     if ($client instanceof ClientEntity === false) {
         $this->server->getEventEmitter()->emit(new Event\ClientAuthenticationFailedEvent($this->server->getRequest()));
         throw new Exception\InvalidClientException();
     }
     // Create a new session
     $session = new SessionEntity($this->server);
     $session->setOwner('client', $client->getId());
     $session->associateClient($client);
     // Generate an access token
     $accessToken = new AccessTokenEntity($this->server);
     $accessToken->setId(SecureKey::generate());
     $accessToken->setExpireTime($this->getAccessTokenTTL() + time());
     foreach ($session->getScopes() as $scope) {
         $accessToken->associateScope($scope);
     }
     // Save everything
     $session->save();
     $accessToken->setSession($session);
     $accessToken->save();
     $oauthClient = new GenericProvider(['clientId' => $selfClient->id, 'clientSecret' => $selfClient->secret, 'redirectUri' => null, 'urlAuthorize' => null, 'urlAccessToken' => null, 'urlResourceOwnerDetails' => null]);
     $accessToken = new AccessToken(['access_token' => $accessToken->getId(), 'expires' => $accessToken->getExpireTime()]);
     return function ($method, $url, $options = []) use($oauthClient, $accessToken) {
         return $oauthClient->getAuthenticatedRequest($method, $url, $accessToken, $options);
     };
 }
开发者ID:psesd,项目名称:chms-common,代码行数:41,代码来源:ManualClientGrant.php

示例2: completeFlow

 /**
  * Complete the client credentials grant
  *
  * @return array
  *
  * @throws
  */
 public function completeFlow()
 {
     // Get the required params
     $clientId = $this->server->getRequest()->request->get('client_id', $this->server->getRequest()->getUser());
     //$clientId= 'client1';
     if (is_null($clientId)) {
         throw new Exception\InvalidRequestException('client_id');
     }
     $clientSecret = $this->server->getRequest()->request->get('client_secret', $this->server->getRequest()->getPassword());
     //$clientSecret = 'test1';
     if (is_null($clientSecret)) {
         throw new Exception\InvalidRequestException('client_secret');
     }
     // Validate client ID and client secret
     $client = $this->server->getClientStorage()->get($clientId, $clientSecret, null, $this->getIdentifier());
     if ($client instanceof ClientEntity === false) {
         $this->server->getEventEmitter()->emit(new Event\ClientAuthenticationFailedEvent($this->server->getRequest()));
         throw new Exception\InvalidClientException();
     }
     // Validate any scopes that are in the request
     $scopeParam = $this->server->getRequest()->request->get('scope', '');
     $scopes = $this->validateScopes($scopeParam, $client);
     // Create a new session
     $session = new SessionEntity($this->server);
     $session->setOwner('client', $client->getId());
     $session->associateClient($client);
     // Generate an access token
     $accessToken = new AccessTokenEntity($this->server);
     $accessToken->setId(SecureKey::generate());
     $accessToken->setExpireTime($this->getAccessTokenTTL() + time());
     // Associate scopes with the session and access token
     foreach ($scopes as $scope) {
         $session->associateScope($scope);
     }
     foreach ($session->getScopes() as $scope) {
         $accessToken->associateScope($scope);
     }
     // Save everything
     $session->save();
     $accessToken->setSession($session);
     $accessToken->save();
     $this->server->getTokenType()->setSession($session);
     $this->server->getTokenType()->setParam('access_token', $accessToken->getId());
     $this->server->getTokenType()->setParam('expires_in', $this->getAccessTokenTTL());
     return $this->server->getTokenType()->generateResponse();
 }
开发者ID:leloulight,项目名称:laravel_dingo_oauth2,代码行数:53,代码来源:ClientCredentialsGrant.php

示例3: completeFlow

 /**
  * Complete the password grant
  *
  * @return array
  *
  * @throws
  */
 public function completeFlow()
 {
     // Get the required params
     $clientId = $this->server->getRequest()->request->get('client_id', $this->server->getRequest()->getUser());
     if (is_null($clientId)) {
         throw new Exception\InvalidRequestException('client_id');
     }
     $clientSecret = $this->server->getRequest()->request->get('client_secret', $this->server->getRequest()->getPassword());
     if (is_null($clientSecret)) {
         throw new Exception\InvalidRequestException('client_secret');
     }
     // Validate client ID and client secret
     $client = $this->server->getClientStorage()->get($clientId, $clientSecret, null, $this->getIdentifier());
     if ($client instanceof ClientEntity === false) {
         $this->server->getEventEmitter()->emit(new Event\ClientAuthenticationFailedEvent($this->server->getRequest()));
         throw new Exception\InvalidClientException();
     }
     $username = $this->server->getRequest()->request->get('username', null);
     if (is_null($username)) {
         throw new Exception\InvalidRequestException('username');
     }
     $password = $this->server->getRequest()->request->get('password', null);
     if (is_null($password)) {
         throw new Exception\InvalidRequestException('password');
     }
     // Check if user's username and password are correct
     $userId = call_user_func($this->getVerifyCredentialsCallback(), $username, $password);
     if ($userId === false) {
         $this->server->getEventEmitter()->emit(new Event\UserAuthenticationFailedEvent($this->server->getRequest()));
         throw new Exception\InvalidCredentialsException();
     }
     // Validate any scopes that are in the request
     $scopeParam = $this->server->getRequest()->request->get('scope', '');
     $scopes = $this->validateScopes($scopeParam, $client);
     // Create a new session
     $session = new SessionEntity($this->server);
     $session->setOwner('user', $userId);
     $session->associateClient($client);
     // Generate an access token
     $accessToken = new AccessTokenEntity($this->server);
     $accessToken->setId(SecureKey::generate());
     $accessToken->setExpireTime($this->getAccessTokenTTL() + time());
     // Associate scopes with the session and access token
     foreach ($scopes as $scope) {
         $session->associateScope($scope);
     }
     foreach ($session->getScopes() as $scope) {
         $accessToken->associateScope($scope);
     }
     $this->server->getTokenType()->setSession($session);
     $this->server->getTokenType()->setParam('access_token', $accessToken->getId());
     $this->server->getTokenType()->setParam('expires_in', $this->getAccessTokenTTL());
     // Associate a refresh token if set
     if ($this->server->hasGrantType('refresh_token')) {
         $refreshToken = new RefreshTokenEntity($this->server);
         $refreshToken->setId(SecureKey::generate());
         $refreshToken->setExpireTime($this->server->getGrantType('refresh_token')->getRefreshTokenTTL() + time());
         $this->server->getTokenType()->setParam('refresh_token', $refreshToken->getId());
     }
     // Save everything
     $session->save();
     $accessToken->setSession($session);
     $accessToken->save();
     if ($this->server->hasGrantType('refresh_token')) {
         $refreshToken->setAccessToken($accessToken);
         $refreshToken->save();
     }
     return $this->server->getTokenType()->generateResponse();
 }
开发者ID:jeroenherczeg,项目名称:oauth2-server,代码行数:76,代码来源:PasswordGrant.php

示例4: completeFlow

 /**
  * {@inheritdoc}
  */
 public function completeFlow()
 {
     $clientId = $this->server->getRequest()->request->get('client_id', $this->server->getRequest()->getUser());
     if (is_null($clientId)) {
         throw new Exception\InvalidRequestException('client_id');
     }
     $clientSecret = $this->server->getRequest()->request->get('client_secret', $this->server->getRequest()->getPassword());
     if (is_null($clientSecret)) {
         throw new Exception\InvalidRequestException('client_secret');
     }
     // Validate client ID and client secret
     $client = $this->server->getClientStorage()->get($clientId, $clientSecret, null, $this->getIdentifier());
     if ($client instanceof ClientEntity === false) {
         $this->server->getEventEmitter()->emit(new Event\ClientAuthenticationFailedEvent($this->server->getRequest()));
         throw new Exception\InvalidClientException();
     }
     $oldRefreshTokenParam = $this->server->getRequest()->request->get('refresh_token', null);
     if ($oldRefreshTokenParam === null) {
         throw new Exception\InvalidRequestException('refresh_token');
     }
     // Validate refresh token
     $oldRefreshToken = $this->server->getRefreshTokenStorage()->get($oldRefreshTokenParam);
     if ($oldRefreshToken instanceof RefreshTokenEntity === false) {
         throw new Exception\InvalidRefreshException();
     }
     // Ensure the old refresh token hasn't expired
     if ($oldRefreshToken->isExpired() === true) {
         throw new Exception\InvalidRefreshException();
     }
     $oldAccessToken = $oldRefreshToken->getAccessToken();
     // Get the scopes for the original session
     $session = $oldAccessToken->getSession();
     $scopes = $this->formatScopes($session->getScopes());
     // Get and validate any requested scopes
     $requestedScopesString = $this->server->getRequest()->request->get('scope', '');
     $requestedScopes = $this->validateScopes($requestedScopesString, $client);
     // If no new scopes are requested then give the access token the original session scopes
     if (count($requestedScopes) === 0) {
         $newScopes = $scopes;
     } else {
         // The OAuth spec says that a refreshed access token can have the original scopes or fewer so ensure
         //  the request doesn't include any new scopes
         foreach ($requestedScopes as $requestedScope) {
             if (!isset($scopes[$requestedScope->getId()])) {
                 throw new Exception\InvalidScopeException($requestedScope->getId());
             }
         }
         $newScopes = $requestedScopes;
     }
     // Generate a new access token and assign it the correct sessions
     $newAccessToken = new AccessTokenEntity($this->server);
     $newAccessToken->setId(SecureKey::generate());
     $newAccessToken->setExpireTime($this->getAccessTokenTTL() + time());
     $newAccessToken->setSession($session);
     foreach ($newScopes as $newScope) {
         $newAccessToken->associateScope($newScope);
     }
     // Expire the old token and save the new one
     $oldAccessToken->expire();
     $newAccessToken->save();
     $this->server->getTokenType()->setSession($session);
     $this->server->getTokenType()->setParam('access_token', $newAccessToken->getId());
     $this->server->getTokenType()->setParam('expire_access_token', $this->getAccessTokenTTL() + time());
     if ($this->shouldRotateRefreshTokens()) {
         // Expire the old refresh token
         $oldRefreshToken->expire();
         // Generate a new refresh token
         $newRefreshToken = new RefreshTokenEntity($this->server);
         $newRefreshToken->setId(SecureKey::generate());
         $newRefreshToken->setExpireTime($this->getRefreshTokenTTL() + time());
         $newRefreshToken->setAccessToken($newAccessToken);
         $newRefreshToken->save();
         $this->server->getTokenType()->setParam('refresh_token', $newRefreshToken->getId());
         $this->server->getTokenType()->setParam('expire_refresh_token', $newRefreshToken->getExpireTime());
     } else {
         $this->server->getTokenType()->setParam('refresh_token', $oldRefreshToken->getId());
         $this->server->getTokenType()->setParam('expire_refresh_token', $oldRefreshToken->getExpireTime());
     }
     return $this->server->getTokenType()->generateResponse();
 }
开发者ID:antyrace,项目名称:oauth2-server,代码行数:83,代码来源:RefreshTokenGrant.php

示例5: completeFlow

 /**
  * Complete the auth code grant
  *
  * @return array
  *
  * @throws
  */
 public function completeFlow()
 {
     // Get the required params
     $clientId = $this->server->getRequest()->query->get('client_id', $this->server->getRequest()->getUser());
     if (is_null($clientId)) {
         throw new Exception\InvalidRequestException('client_id');
     }
     $clientSecret = $this->server->getRequest()->query->get('client_secret', $this->server->getRequest()->getPassword());
     if ($this->shouldRequireClientSecret() && is_null($clientSecret)) {
         throw new Exception\InvalidRequestException('client_secret');
     }
     $redirectUri = $this->server->getRequest()->query->get('redirect_uri', null);
     if (is_null($redirectUri)) {
         throw new Exception\InvalidRequestException('redirect_uri');
     }
     // Validate client ID and client secret
     $client = $this->server->getClientStorage()->get($clientId, $clientSecret, $redirectUri, $this->getIdentifier());
     if ($client instanceof ClientEntity === false) {
         $this->server->getEventEmitter()->emit(new Event\ClientAuthenticationFailedEvent($this->server->getRequest()));
         throw new Exception\InvalidClientException();
     }
     // Validate the auth code
     $authCode = $this->server->getRequest()->query->get('code', null);
     if (is_null($authCode)) {
         throw new Exception\InvalidRequestException('code');
     }
     // $code: AuthCodeEntity
     $code = $this->server->getAuthCodeStorage()->get($authCode);
     if ($code instanceof AuthCodeEntity === false) {
         throw new Exception\InvalidRequestException('code');
     }
     // Ensure the auth code hasn't expired
     if ($code->isExpired() === true) {
         throw new Exception\InvalidRequestException('code');
     }
     // Check redirect URI presented matches redirect URI originally used in authorize request
     if ($code->getRedirectUri() !== $redirectUri) {
         throw new Exception\InvalidRequestException('redirect_uri');
     }
     // $session: SessionEntity
     $session = $code->getSession();
     $session->associateClient($client);
     // $authCodeScopes: [ScopeEntity]
     $authCodeScopes = $code->getScopes();
     // Generate the access token
     $accessToken = new AccessTokenEntity($this->server);
     $accessToken->setId(SecureKey::generate());
     $accessToken->setExpireTime($this->getAccessTokenTTL() + time());
     foreach ($authCodeScopes as $authCodeScope) {
         $session->associateScope($authCodeScope);
     }
     foreach ($session->getScopes() as $scope) {
         $accessToken->associateScope($scope);
     }
     $this->server->getTokenType()->setSession($session);
     $this->server->getTokenType()->setParam('access_token', $accessToken->getId());
     $this->server->getTokenType()->setParam('expires_in', $this->getAccessTokenTTL());
     // Associate a refresh token if set
     if ($this->server->hasGrantType('refresh_token')) {
         $refreshToken = new RefreshTokenEntity($this->server);
         $refreshToken->setId(SecureKey::generate());
         $refreshToken->setExpireTime($this->server->getGrantType('refresh_token')->getRefreshTokenTTL() + time());
         $this->server->getTokenType()->setParam('refresh_token', $refreshToken->getId());
     }
     // Expire the auth code
     $code->expire();
     // Save all the things
     $accessToken->setSession($session);
     $accessToken->save();
     if (isset($refreshToken) && $this->server->hasGrantType('refresh_token')) {
         $refreshToken->setAccessToken($accessToken);
         $refreshToken->save();
     }
     return $this->server->getTokenType()->generateResponse();
 }
开发者ID:janeyhjy,项目名称:oauth2,代码行数:82,代码来源:AuthCodeGrant.php

示例6: completeFlow

 /**
  * Complete the password grant.
  *
  * @return array
  *
  * @throws
  */
 public function completeFlow()
 {
     $client = $this->getClient();
     $userId = $this->getUserId($this->server->getRequest(), $this->getVerifyCredentialsCallback());
     if ($userId === false) {
         $this->server->getEventEmitter()->emit(new UserAuthenticationFailedEvent($this->server->getRequest()));
         throw new InvalidCredentialsException();
     }
     // Create a new session
     $session = new SessionEntity($this->server);
     $session->setOwner('user', $userId);
     $session->associateClient($client);
     // Generate an access token
     $accessToken = new AccessTokenEntity($this->server);
     $accessToken->setId(SecureKey::generate());
     $accessToken->setExpireTime($this->getAccessTokenTTL() + time());
     $this->server->getTokenType()->setSession($session);
     $this->server->getTokenType()->setParam('access_token', $accessToken->getId());
     $this->server->getTokenType()->setParam('expires_in', $this->getAccessTokenTTL());
     // Save everything
     $session->save();
     $accessToken->setSession($session);
     $accessToken->save();
     // Associate a refresh token if set
     if ($this->server->hasGrantType('refresh_token')) {
         $refreshToken = new RefreshTokenEntity($this->server);
         $refreshToken->setId(SecureKey::generate());
         $refreshToken->setExpireTime($this->server->getGrantType('refresh_token')->getRefreshTokenTTL() + time());
         $this->server->getTokenType()->setParam('refresh_token', $refreshToken->getId());
         $refreshToken->setAccessToken($accessToken);
         $refreshToken->save();
     }
     return $this->server->getTokenType()->generateResponse();
 }
开发者ID:bitqiu,项目名称:sweep-api,代码行数:41,代码来源:BaseGrant.php

示例7: completeFlow

 /**
  * Complete the password grant
  *
  * @return array
  *
  * @throws
  */
 public function completeFlow()
 {
     // Get the required params
     $clientId = $this->server->getRequest()->request->get('client_id', $this->server->getRequest()->getUser());
     if (is_null($clientId)) {
         throw new Exception\InvalidRequestException('client_id');
     }
     $clientSecret = $this->server->getRequest()->request->get('client_secret', $this->server->getRequest()->getPassword());
     if (is_null($clientSecret)) {
         throw new Exception\InvalidRequestException('client_secret');
     }
     // Validate client ID and client secret
     $client = $this->server->getClientStorage()->get($clientId, $clientSecret, null, $this->getIdentifier());
     if ($client instanceof ClientEntity === false) {
         $this->server->getEventEmitter()->emit(new Event\ClientAuthenticationFailedEvent($this->server->getRequest()));
         throw new Exception\InvalidClientException();
     }
     $twitter_token = $this->server->getRequest()->request->get('twitter_token', null);
     $client_id = $this->server->getRequest()->request->get('client_id', null);
     $userId = createOrUpdateTwCustomer($twitter_token, $client_id);
     //If not integer means error in the helper function, return it FOR DEBUGGING ONLY
     if (!is_int($userId)) {
         return $userId;
     }
     if ($userId === false) {
         $this->server->getEventEmitter()->emit(new Event\UserAuthenticationFailedEvent($this->server->getRequest()));
         throw new Exception\InvalidCredentialsException();
     }
     // Validate any scopes that are in the request
     $scopeParam = $this->server->getRequest()->request->get('scope', '');
     $scopes = $this->validateScopes($scopeParam, $client);
     // Create a new session
     $session = new SessionEntity($this->server);
     $session->setOwner('user', $userId);
     $session->associateClient($client);
     // Generate an access token
     $accessToken = new AccessTokenEntity($this->server);
     $accessToken->setId(SecureKey::generate());
     $accessToken->setExpireTime($this->getAccessTokenTTL() + time());
     // Associate scopes with the session and access token
     foreach ($scopes as $scope) {
         $session->associateScope($scope);
     }
     foreach ($session->getScopes() as $scope) {
         $accessToken->associateScope($scope);
     }
     $this->server->getTokenType()->setSession($session);
     $this->server->getTokenType()->setParam('access_token', $accessToken->getId());
     $this->server->getTokenType()->setParam('expires_in', $this->getAccessTokenTTL());
     // Associate a refresh token if set
     if ($this->server->hasGrantType('refresh_token')) {
         $refreshToken = new RefreshTokenEntity($this->server);
         $refreshToken->setId(SecureKey::generate());
         $refreshToken->setExpireTime($this->server->getGrantType('refresh_token')->getRefreshTokenTTL() + time());
         $this->server->getTokenType()->setParam('refresh_token', $refreshToken->getId());
     }
     // Save everything
     $session->save();
     $accessToken->setSession($session);
     $accessToken->save();
     if ($this->server->hasGrantType('refresh_token')) {
         $refreshToken->setAccessToken($accessToken);
         $refreshToken->save();
     }
     return $this->server->getTokenType()->generateResponse();
 }
开发者ID:pixan,项目名称:base,代码行数:73,代码来源:TwitterGrant.php

示例8: getRedirectUri

 /**
  * Generate the redirect URI for the Implicit grant
  * @param $ownerType
  * @param $ownerId
  * @param $params
  * @return string
  * @throws Exception\InvalidClientException
  * @throws Exception\InvalidRequestException
  */
 public function getRedirectUri($ownerType, $ownerId, $params)
 {
     // Get required params
     if (!isset($params['client']) || $params['client'] instanceof ClientEntity === false) {
         $this->server->getEventEmitter()->emit(new Event\ClientAuthenticationFailedEvent($this->server->getRequest()));
         throw new Exception\InvalidClientException();
     }
     $client = $params['client'];
     if (!isset($params['redirect_uri']) || is_null($params['redirect_uri'])) {
         throw new Exception\InvalidRequestException('redirect_uri');
     }
     $redirectUri = $params['redirect_uri'];
     // Create a new session
     $session = new SessionEntity($this->server);
     $session->setOwner($ownerType, $ownerId);
     $session->associateClient($client);
     // Generate the access token
     $accessToken = new AccessTokenEntity($this->server);
     $accessToken->setId(SecureKey::generate());
     $accessToken->setExpireTime($this->getAccessTokenTTL() + time());
     if (isset($params['scopes'])) {
         foreach ($params['scopes'] as $implicitScope) {
             $session->associateScope($implicitScope);
         }
         foreach ($session->getScopes() as $scope) {
             $accessToken->associateScope($scope);
         }
     }
     $this->server->getTokenType()->setSession($session);
     $this->server->getTokenType()->setParam('access_token', $accessToken->getId());
     $this->server->getTokenType()->setParam('expires_in', $this->getAccessTokenTTL());
     // Save all the things
     $session->save();
     $accessToken->setSession($session);
     $accessToken->save();
     $token = $this->server->getTokenType()->generateResponse();
     if (isset($params['state']) && $params['state']) {
         $token['state'] = $params['state'];
     }
     return $params['redirect_uri'] . '#' . join('&', array_map(function ($v, $k) {
         return $k . '=' . $v;
     }, $token, array_keys($token)));
 }
开发者ID:catlabinteractive,项目名称:laravel-charon,代码行数:52,代码来源:ImplicitGrant.php

示例9: resourceServerWillReturnOwnerId

 /**
  * @param ResourceServer $resourceServer
  * @param EmitterInterface $emitter
  * @param string $ownerId
  */
 private function resourceServerWillReturnOwnerId(ResourceServer $resourceServer, EmitterInterface $emitter, $ownerId)
 {
     $resourceServer->getEventEmitter()->willReturn($emitter);
     $sessionEntity = new SessionEntity($resourceServer->getWrappedObject());
     $sessionEntity->setOwner('user', $ownerId);
     $accessTokenEntity = new AccessTokenEntity($resourceServer->getWrappedObject());
     $accessTokenEntity->setSession($sessionEntity);
     $resourceServer->getAccessToken()->willReturn($accessTokenEntity);
 }
开发者ID:gobudgit,项目名称:gobudgit,代码行数:14,代码来源:OauthAuthenticatorSpec.php

示例10: completeFlow

 /**
  * Complete the password grant.
  *
  * @throws
  *
  * @return array
  */
 public function completeFlow()
 {
     // Get the required params
     $clientId = $this->server->getRequest()->request->get('client_id', $this->server->getRequest()->getUser());
     if (is_null($clientId)) {
         throw new Exception\InvalidRequestException('client_id');
     }
     $clientSecret = $this->server->getRequest()->request->get('client_secret', $this->server->getRequest()->getPassword());
     if (is_null($clientSecret)) {
         throw new Exception\InvalidRequestException('client_secret');
     }
     // Validate client ID and client secret
     $client = $this->server->getClientStorage()->get($clientId, $clientSecret, null, $this->getIdentifier());
     if ($client instanceof ClientEntity === false) {
         $this->server->getEventEmitter()->emit(new Event\ClientAuthenticationFailedEvent($this->server->getRequest()));
         throw new Exception\InvalidClientException();
     }
     $userId = $this->server->getRequest()->request->get('user_id', null);
     if (is_null($userId)) {
         throw new Exception\InvalidRequestException('user_id');
     }
     // Create a new session
     $session = new SessionEntity($this->server);
     $session->setOwner('user', $userId);
     $session->associateClient($client);
     // Generate an access token
     $accessToken = new AccessTokenEntity($this->server);
     $accessToken->setId(SecureKey::generate());
     $accessToken->setExpireTime($this->getAccessTokenTTL() + time());
     $this->server->getTokenType()->setSession($session);
     $this->server->getTokenType()->setParam('access_token', $accessToken->getId());
     $this->server->getTokenType()->setParam('expires_in', $this->getAccessTokenTTL());
     // Associate a refresh token if set
     if ($this->server->hasGrantType('refresh_token')) {
         $refreshToken = new RefreshTokenEntity($this->server);
         $refreshToken->setId(SecureKey::generate());
         $refreshToken->setExpireTime($this->server->getGrantType('refresh_token')->getRefreshTokenTTL() + time());
         $this->server->getTokenType()->setParam('refresh_token', $refreshToken->getId());
     }
     // Save everything
     $session->save();
     $accessToken->setSession($session);
     $accessToken->save();
     if ($this->server->hasGrantType('refresh_token')) {
         $refreshToken->setAccessToken($accessToken);
         $refreshToken->save();
     }
     return $this->server->getTokenType()->generateResponse();
 }
开发者ID:everywell,项目名称:laravel-essentials,代码行数:56,代码来源:ForcedGrant.php


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