-
-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #242 from Sammyjo20/feature/allow-oauth-requests-t…
…o-be-overwritten Feature | Ability to overwrite OAuth2 request classes
- Loading branch information
Showing
10 changed files
with
248 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
tests/Fixtures/Connectors/CustomRequestClientCredentialsConnector.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Saloon\Tests\Fixtures\Connectors; | ||
|
||
use Saloon\Contracts\Request; | ||
use Saloon\Helpers\OAuth2\OAuthConfig; | ||
use Saloon\Tests\Fixtures\Requests\OAuth\CustomClientCredentialsAccessTokenRequest; | ||
|
||
class CustomRequestClientCredentialsConnector extends ClientCredentialsConnector | ||
|
||
/** | ||
* Resolve the access token request | ||
* | ||
* @param OAuthConfig $oauthConfig | ||
* @param array $scopes | ||
* @param string $scopeSeparator | ||
* @return Request | ||
*/ | ||
{ | ||
protected function resolveAccessTokenRequest(OAuthConfig $oauthConfig, array $scopes = [], string $scopeSeparator = ' '): Request | ||
{ | ||
return new CustomClientCredentialsAccessTokenRequest($oauthConfig, $scopes, $scopeSeparator); | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
tests/Fixtures/Connectors/CustomRequestOAuth2Connector.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Saloon\Tests\Fixtures\Connectors; | ||
|
||
use Saloon\Http\Connector; | ||
use Saloon\Contracts\Request; | ||
use Saloon\Helpers\OAuth2\OAuthConfig; | ||
use Saloon\Traits\OAuth2\AuthorizationCodeGrant; | ||
use Saloon\Tests\Fixtures\Requests\OAuth\CustomOAuthUserRequest; | ||
use Saloon\Tests\Fixtures\Requests\OAuth\CustomAccessTokenRequest; | ||
use Saloon\Tests\Fixtures\Requests\OAuth\CustomRefreshTokenRequest; | ||
|
||
class CustomRequestOAuth2Connector extends Connector | ||
{ | ||
use AuthorizationCodeGrant; | ||
|
||
/** | ||
* Define the base URL. | ||
* | ||
* @return string | ||
*/ | ||
public function resolveBaseUrl(): string | ||
{ | ||
return 'https://oauth.saloon.dev'; | ||
} | ||
|
||
/** | ||
* Define default Oauth config. | ||
* | ||
* @return OAuthConfig | ||
*/ | ||
protected function defaultOauthConfig(): OAuthConfig | ||
{ | ||
return OAuthConfig::make() | ||
->setClientId('client-id') | ||
->setClientSecret('client-secret') | ||
->setRedirectUri('https://my-app.saloon.dev/auth/callback'); | ||
} | ||
|
||
/** | ||
* Resolve the access token request | ||
* | ||
* @param string $code | ||
* @param OAuthConfig $oauthConfig | ||
* @return Request | ||
*/ | ||
protected function resolveAccessTokenRequest(string $code, OAuthConfig $oauthConfig): Request | ||
{ | ||
return new CustomAccessTokenRequest($code, $oauthConfig); | ||
} | ||
|
||
/** | ||
* Resolve the refresh token request | ||
* | ||
* @param OAuthConfig $oauthConfig | ||
* @param string $refreshToken | ||
* @return Request | ||
*/ | ||
protected function resolveRefreshTokenRequest(OAuthConfig $oauthConfig, string $refreshToken): Request | ||
{ | ||
return new CustomRefreshTokenRequest($oauthConfig, $refreshToken); | ||
} | ||
|
||
/** | ||
* Resolve the user request | ||
* | ||
* @param OAuthConfig $oauthConfig | ||
* @return Request | ||
*/ | ||
protected function resolveUserRequest(OAuthConfig $oauthConfig): Request | ||
{ | ||
return new CustomOAuthUserRequest($oauthConfig); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
tests/Fixtures/Requests/OAuth/CustomAccessTokenRequest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Saloon\Tests\Fixtures\Requests\OAuth; | ||
|
||
use Saloon\Http\OAuth2\GetAccessTokenRequest; | ||
|
||
class CustomAccessTokenRequest extends GetAccessTokenRequest | ||
{ | ||
// | ||
} |
12 changes: 12 additions & 0 deletions
12
tests/Fixtures/Requests/OAuth/CustomClientCredentialsAccessTokenRequest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Saloon\Tests\Fixtures\Requests\OAuth; | ||
|
||
use Saloon\Http\OAuth2\GetClientCredentialsTokenRequest; | ||
|
||
class CustomClientCredentialsAccessTokenRequest extends GetClientCredentialsTokenRequest | ||
{ | ||
// | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Saloon\Tests\Fixtures\Requests\OAuth; | ||
|
||
use Saloon\Http\OAuth2\GetUserRequest; | ||
|
||
class CustomOAuthUserRequest extends GetUserRequest | ||
{ | ||
// | ||
} |
12 changes: 12 additions & 0 deletions
12
tests/Fixtures/Requests/OAuth/CustomRefreshTokenRequest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Saloon\Tests\Fixtures\Requests\OAuth; | ||
|
||
use Saloon\Http\OAuth2\GetRefreshTokenRequest; | ||
|
||
class CustomRefreshTokenRequest extends GetRefreshTokenRequest | ||
{ | ||
// | ||
} |