-
-
Notifications
You must be signed in to change notification settings - Fork 246
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #388: Added support to configure the OAuth2 access token location…
… in requests and added a generic OAuth2 client
- Loading branch information
Showing
18 changed files
with
391 additions
and
41 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
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,55 @@ | ||
<?php | ||
/** | ||
* @link https://www.yiiframework.com/ | ||
* @copyright Copyright (c) 2008 Yii Software LLC | ||
* @license https://www.yiiframework.com/license/ | ||
*/ | ||
|
||
namespace yii\authclient\clients; | ||
|
||
use yii\authclient\OAuth2; | ||
|
||
/** | ||
* Generic client that allows authentication via OAuth 2.0. | ||
* | ||
* Example application configuration: | ||
* | ||
* ```php | ||
* 'components' => [ | ||
* 'authClientCollection' => [ | ||
* 'class' => 'yii\authclient\Collection', | ||
* 'clients' => [ | ||
* 'oauth2' => [ | ||
* 'class' => 'yii\authclient\clients\Oauth2Client', | ||
* 'authUrl' => 'https://oauth2service.com/oauth2/authorize', | ||
* 'tokenUrl' => 'https://oauth2service.com/oauth2/authorize', | ||
* 'apiBaseUrl' => 'https://oauth2service.com/api', | ||
* 'clientId' => 'your_app_client_id', | ||
* 'clientSecret' => 'your_app_client_secret', | ||
* 'name' => 'custom name', | ||
* 'title' => 'custom title' | ||
* ], | ||
* ], | ||
* ] | ||
* // ... | ||
* ] | ||
* ``` | ||
* | ||
* @since 2.2.16 | ||
*/ | ||
class Oauth2Client extends OAuth2 | ||
{ | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public $accessTokenLocation = self::ACCESS_TOKEN_LOCATION_HEADER; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function initUserAttributes() | ||
{ | ||
return []; // Plain Oauth 2.0 doesn't specify user attributes. | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
namespace yiiunit\extensions\authclient\clients; | ||
|
||
use yii\authclient\clients\Facebook; | ||
use yii\authclient\OAuth2; | ||
use yiiunit\extensions\authclient\clients\base\BaseOauth2ClientTestCase; | ||
|
||
class FacebookTest extends BaseOauth2ClientTestCase | ||
{ | ||
protected function createClient() | ||
{ | ||
return new Facebook(); | ||
} | ||
|
||
protected function getExpectedTokenLocation() | ||
{ | ||
return OAuth2::ACCESS_TOKEN_LOCATION_BODY; | ||
} | ||
} |
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,25 @@ | ||
<?php | ||
|
||
namespace yiiunit\extensions\authclient\clients; | ||
|
||
use yii\authclient\clients\GitHub; | ||
use yii\authclient\OAuth2; | ||
use yiiunit\extensions\authclient\clients\base\BaseOauth2ClientTestCase; | ||
|
||
class GitHubTest extends BaseOauth2ClientTestCase | ||
{ | ||
protected function createClient() | ||
{ | ||
return new GitHub(); | ||
} | ||
|
||
protected function getExpectedTokenLocation() | ||
{ | ||
return OAuth2::ACCESS_TOKEN_LOCATION_HEADER; | ||
} | ||
|
||
protected function getAccessTokenHeaderTypeName() | ||
{ | ||
return 'token'; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace yiiunit\extensions\authclient\clients; | ||
|
||
use yii\authclient\clients\LinkedIn; | ||
use yii\authclient\OAuth2; | ||
use yiiunit\extensions\authclient\clients\base\BaseOauth2ClientTestCase; | ||
|
||
class LinkedInTest extends BaseOauth2ClientTestCase | ||
{ | ||
protected function createClient() | ||
{ | ||
return new LinkedIn(); | ||
} | ||
|
||
protected function getExpectedTokenLocation() | ||
{ | ||
return OAuth2::ACCESS_TOKEN_LOCATION_BODY; | ||
} | ||
|
||
protected function getAccessTokenBodyParamName() | ||
{ | ||
return 'oauth2_access_token'; | ||
} | ||
} |
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,20 @@ | ||
<?php | ||
|
||
namespace yiiunit\extensions\authclient\clients; | ||
|
||
use yii\authclient\clients\Live; | ||
use yii\authclient\OAuth2; | ||
use yiiunit\extensions\authclient\clients\base\BaseOauth2ClientTestCase; | ||
|
||
class LiveTest extends BaseOauth2ClientTestCase | ||
{ | ||
protected function createClient() | ||
{ | ||
return new Live(); | ||
} | ||
|
||
protected function getExpectedTokenLocation() | ||
{ | ||
return OAuth2::ACCESS_TOKEN_LOCATION_BODY; | ||
} | ||
} |
Oops, something went wrong.