Example #1
0
 /**
  * @param \League\OAuth2\Client\Token\AccessToken $accessToken
  * @return boolean
  */
 public static function storeAccessToken(\League\OAuth2\Client\Token\AccessToken $accessToken)
 {
     $result = file_put_contents(self::TOKENS_FILE_PATH, json_encode($accessToken->jsonSerialize()) . "\n", FILE_APPEND);
     if (!$result) {
         throw new \RuntimeException(sprintf("Could not store token into file %s - check file permissions", self::TOKENS_FILE_PATH));
     }
     return $result;
 }
Example #2
0
 /**
  * Sets an access token and adds it to `AuthMiddleware` so the application
  * can make authenticated requests.
  *
  * @param AccessToken $token
  *
  * @return  void
  *
  * @codeCoverageIgnore
  */
 public function setAccessToken(AccessToken $token)
 {
     $this->container->get('config')->set('access_token', json_encode($token->jsonSerialize()));
 }
 /**
  * Process the successful return of the user - pass the $_GET['code'] (or equiv) in to extract the access token
  * @event Sabre\Event obtain-token Fires on token received - you need to capture this
  * @param $code $_GET['code'] from user return
  */
 public function handleAuthResponse($code)
 {
     $this->access_token = $this->provider->getAccessToken('authorization_code', ['code' => $code]);
     $this->emit('obtain-token', [$this->access_token->jsonSerialize()]);
 }
Example #4
0
 public function refreshAccessToken(AccessToken $oldAccessToken)
 {
     $newAccessToken = $this->getAccessToken('refresh_token', ['refresh_token' => $oldAccessToken->getRefreshToken()]);
     //Add old resource owner id to new token (because resource owner id is not returned on token refresh)
     $newAccessToken = new AccessToken(['resource_owner_id' => $oldAccessToken->getResourceOwnerId()] + $newAccessToken->jsonSerialize());
     return $newAccessToken;
 }