2016-02-23 03:19:46 +05:30
|
|
|
<?php
|
2019-09-22 02:47:21 +05:30
|
|
|
declare(strict_types=1);
|
|
|
|
|
2019-02-21 01:28:52 +05:30
|
|
|
namespace api\tests\functional\oauth;
|
2016-02-23 03:19:46 +05:30
|
|
|
|
2019-02-21 01:28:52 +05:30
|
|
|
use api\tests\functional\_steps\OauthSteps;
|
2019-09-23 03:23:13 +05:30
|
|
|
use api\tests\FunctionalTester;
|
2016-02-23 03:19:46 +05:30
|
|
|
|
2017-06-12 17:04:39 +05:30
|
|
|
class RefreshTokenCest {
|
2016-02-23 03:19:46 +05:30
|
|
|
|
2024-12-02 15:40:55 +05:30
|
|
|
public function refreshToken(OauthSteps $I): void {
|
2019-09-22 02:47:21 +05:30
|
|
|
$I->wantTo('refresh token without passing the desired scopes');
|
2016-02-23 03:19:46 +05:30
|
|
|
$refreshToken = $I->getRefreshToken();
|
2019-09-22 02:47:21 +05:30
|
|
|
$I->sendPOST('/api/oauth2/v1/token', [
|
|
|
|
'grant_type' => 'refresh_token',
|
|
|
|
'refresh_token' => $refreshToken,
|
|
|
|
'client_id' => 'ely',
|
|
|
|
'client_secret' => 'ZuM1vGchJz-9_UZ5HC3H3Z9Hg5PzdbkM',
|
|
|
|
]);
|
2016-11-29 04:27:58 +05:30
|
|
|
$this->canSeeRefreshTokenSuccess($I);
|
2016-02-23 03:19:46 +05:30
|
|
|
}
|
|
|
|
|
2024-12-02 15:40:55 +05:30
|
|
|
public function refreshTokenWithSameScopes(OauthSteps $I): void {
|
2019-09-22 02:47:21 +05:30
|
|
|
$refreshToken = $I->getRefreshToken(['minecraft_server_session']);
|
|
|
|
$I->sendPOST('/api/oauth2/v1/token', [
|
|
|
|
'grant_type' => 'refresh_token',
|
|
|
|
'refresh_token' => $refreshToken,
|
|
|
|
'client_id' => 'ely',
|
|
|
|
'client_secret' => 'ZuM1vGchJz-9_UZ5HC3H3Z9Hg5PzdbkM',
|
2019-12-09 22:01:54 +05:30
|
|
|
'scope' => 'minecraft_server_session',
|
2019-09-22 02:47:21 +05:30
|
|
|
]);
|
2016-11-29 04:27:58 +05:30
|
|
|
$this->canSeeRefreshTokenSuccess($I);
|
|
|
|
}
|
|
|
|
|
2024-12-02 15:40:55 +05:30
|
|
|
public function refreshTokenTwice(OauthSteps $I): void {
|
2019-09-22 02:47:21 +05:30
|
|
|
$I->wantTo('refresh token two times in a row and ensure, that token isn\'t rotating');
|
|
|
|
$refreshToken = $I->getRefreshToken(['minecraft_server_session']);
|
|
|
|
$I->sendPOST('/api/oauth2/v1/token', [
|
|
|
|
'grant_type' => 'refresh_token',
|
|
|
|
'refresh_token' => $refreshToken,
|
|
|
|
'client_id' => 'ely',
|
|
|
|
'client_secret' => 'ZuM1vGchJz-9_UZ5HC3H3Z9Hg5PzdbkM',
|
|
|
|
'scope' => 'minecraft_server_session',
|
|
|
|
]);
|
2016-11-29 04:27:58 +05:30
|
|
|
$this->canSeeRefreshTokenSuccess($I);
|
|
|
|
|
2019-09-22 02:47:21 +05:30
|
|
|
$I->sendPOST('/api/oauth2/v1/token', [
|
|
|
|
'grant_type' => 'refresh_token',
|
|
|
|
'refresh_token' => $refreshToken,
|
|
|
|
'client_id' => 'ely',
|
|
|
|
'client_secret' => 'ZuM1vGchJz-9_UZ5HC3H3Z9Hg5PzdbkM',
|
|
|
|
'scope' => 'minecraft_server_session',
|
|
|
|
]);
|
2016-11-29 04:27:58 +05:30
|
|
|
$this->canSeeRefreshTokenSuccess($I);
|
2016-02-23 03:19:46 +05:30
|
|
|
}
|
|
|
|
|
2024-12-02 15:40:55 +05:30
|
|
|
public function refreshTokenUsingLegacyToken(FunctionalTester $I): void {
|
2019-09-23 03:23:13 +05:30
|
|
|
$I->wantTo('refresh token using the legacy token');
|
|
|
|
$I->sendPOST('/api/oauth2/v1/token', [
|
|
|
|
'grant_type' => 'refresh_token',
|
|
|
|
'refresh_token' => 'op7kPGAgHlsXRBJtkFg7wKOTpodvtHVW5NxR7Tjr',
|
|
|
|
'client_id' => 'test1',
|
|
|
|
'client_secret' => 'eEvrKHF47sqiaX94HsX-xXzdGiz3mcsq',
|
|
|
|
'scope' => 'minecraft_server_session account_info',
|
|
|
|
]);
|
|
|
|
$this->canSeeRefreshTokenSuccess($I);
|
|
|
|
}
|
|
|
|
|
2024-12-02 15:40:55 +05:30
|
|
|
public function passInvalidRefreshToken(OauthSteps $I): void {
|
2019-09-22 02:47:21 +05:30
|
|
|
$I->wantToTest('behaviour of the server when invalid refresh token passed');
|
|
|
|
$I->sendPOST('/api/oauth2/v1/token', [
|
|
|
|
'grant_type' => 'refresh_token',
|
|
|
|
'refresh_token' => 'some-invalid-refresh-token',
|
|
|
|
'client_id' => 'ely',
|
|
|
|
'client_secret' => 'ZuM1vGchJz-9_UZ5HC3H3Z9Hg5PzdbkM',
|
|
|
|
]);
|
2024-12-02 15:40:55 +05:30
|
|
|
$I->canSeeResponseCodeIs(400);
|
2019-09-22 02:47:21 +05:30
|
|
|
$I->canSeeResponseContainsJson([
|
2024-12-02 15:40:55 +05:30
|
|
|
'error' => 'invalid_grant',
|
2019-09-22 02:47:21 +05:30
|
|
|
'message' => 'The refresh token is invalid.',
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2024-12-02 15:40:55 +05:30
|
|
|
public function requireNewScopes(OauthSteps $I): void {
|
2019-09-22 02:47:21 +05:30
|
|
|
$I->wantToTest('behavior when required the new scope that was not issued with original token');
|
|
|
|
$refreshToken = $I->getRefreshToken(['minecraft_server_session']);
|
|
|
|
$I->sendPOST('/api/oauth2/v1/token', [
|
|
|
|
'grant_type' => 'refresh_token',
|
|
|
|
'refresh_token' => $refreshToken,
|
|
|
|
'client_id' => 'ely',
|
|
|
|
'client_secret' => 'ZuM1vGchJz-9_UZ5HC3H3Z9Hg5PzdbkM',
|
|
|
|
'scope' => 'minecraft_server_session account_email',
|
|
|
|
]);
|
2016-02-23 03:19:46 +05:30
|
|
|
$I->canSeeResponseCodeIs(400);
|
|
|
|
$I->canSeeResponseIsJson();
|
|
|
|
$I->canSeeResponseContainsJson([
|
|
|
|
'error' => 'invalid_scope',
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2024-12-02 15:40:55 +05:30
|
|
|
private function canSeeRefreshTokenSuccess(FunctionalTester $I): void {
|
2016-11-29 04:27:58 +05:30
|
|
|
$I->canSeeResponseCodeIs(200);
|
|
|
|
$I->canSeeResponseContainsJson([
|
|
|
|
'token_type' => 'Bearer',
|
|
|
|
]);
|
|
|
|
$I->canSeeResponseJsonMatchesJsonPath('$.access_token');
|
|
|
|
$I->canSeeResponseJsonMatchesJsonPath('$.expires_in');
|
|
|
|
$I->cantSeeResponseJsonMatchesJsonPath('$.refresh_token');
|
|
|
|
}
|
|
|
|
|
2016-02-23 03:19:46 +05:30
|
|
|
}
|