Пример #1
0
 /**
  * Prepare the actual HttpResponse for the token
  *
  * @param  AccessToken       $accessToken
  * @param  RefreshToken|null $refreshToken
  * @param  bool              $useRefreshTokenScopes
  * @return ResponseInterface
  */
 protected function prepareTokenResponse(AccessToken $accessToken, RefreshToken $refreshToken = null, $useRefreshTokenScopes = false)
 {
     $owner = $accessToken->getOwner();
     $scopes = $useRefreshTokenScopes ? $refreshToken->getScopes() : $accessToken->getScopes();
     $responseBody = ['access_token' => $accessToken->getToken(), 'token_type' => 'Bearer', 'expires_in' => $accessToken->getExpiresIn(), 'scope' => implode(' ', $scopes), 'owner_id' => $owner ? $owner->getTokenOwnerId() : null];
     if (null !== $refreshToken) {
         $responseBody['refresh_token'] = $refreshToken->getToken();
     }
     return new Response\JsonResponse(array_filter($responseBody));
 }
Пример #2
0
 public function testGettersAndSetters()
 {
     $owner = $this->getMock(TokenOwnerInterface::class);
     $client = new Client();
     $expiresAt = new DateTime();
     $accessToken = new AccessToken();
     $accessToken->setToken('token');
     $accessToken->setScopes(['scope1', 'scope2']);
     $accessToken->setClient($client);
     $accessToken->setExpiresAt($expiresAt);
     $accessToken->setOwner($owner);
     $this->assertEquals('token', $accessToken->getToken());
     $this->assertCount(2, $accessToken->getScopes());
     $this->assertTrue($accessToken->matchScopes('scope1'));
     $this->assertFalse($accessToken->matchScopes('scope3'));
     $this->assertSame($client, $accessToken->getClient());
     $this->assertEquals($expiresAt, $accessToken->getExpiresAt());
     $this->assertSame($owner, $accessToken->getOwner());
 }