public function OAuth2ServerTestCase::testJwtBearerGrantType in OAuth2 Server 7
Tests the "JWT bearer" grant type.
File
- tests/
oauth2_server.test, line 296 - OAuth2 tests.
Class
- OAuth2ServerTestCase
- Test basic API.
Code
public function testJwtBearerGrantType() {
$jwt_util = new OAuth2\Encryption\Jwt();
$user = $this
->drupalCreateUser(array(
'use oauth2 server',
));
$this
->drupalLogin($user);
$token_url = url('oauth2/token', array(
'absolute' => TRUE,
));
$jwt_data = array(
'iss' => $this->client_key,
'exp' => time() + 1000,
'iat' => time(),
'sub' => $user->uid,
'aud' => $token_url,
'jti' => '123456',
);
$data = array(
'grant_type' => 'urn:ietf:params:oauth:grant-type:jwt-bearer',
'assertion' => $jwt_util
->encode($jwt_data, $this->private_key, 'RS256'),
);
$options = array(
'method' => 'POST',
'data' => http_build_query($data),
'headers' => array(
'Content-Type' => 'application/x-www-form-urlencoded',
),
);
$result = $this
->httpRequest($token_url, $options);
$this
->assertEqual($result->code, 200, 'The token request completed successfully');
$response = json_decode($result->data);
$this
->assertTokenResponse($response, FALSE);
}