You may create your own auth client for any external auth provider, which supports OpenId or OAuth protocol. To do so, first of all, you need to find out which protocol is supported by the external auth provider, this will give you the name of the base class for your extension:
At this stage you can determine auth client default name, title and view options, declaring corresponding methods:
use yii\authclient\OAuth2;
class MyAuthClient extends OAuth2
{
protected function defaultName()
{
return 'my_auth_client';
}
protected function defaultTitle()
{
return 'My Auth Client';
}
protected function defaultViewOptions()
{
return [
'popupWidth' => 800,
'popupHeight' => 500,
];
}
}
Depending on actual base class, you will need to redeclare different fields and methods.
All you need is to specify auth URL, by redeclaring authUrl field. You may also setup default required and/or optional attributes. For example:
use yii\authclient\OpenId;
class MyAuthClient extends OpenId
{
public $authUrl = 'https://www.my.com/openid/';
public $requiredAttributes = [
'contact/email',
];
public $optionalAttributes = [
'namePerson/first',
'namePerson/last',
];
}
You will need to specify:
For example:
use yii\authclient\OAuth2;
class MyAuthClient extends OAuth2
{
public $authUrl = 'https://www.my.com/oauth2/auth';
public $tokenUrl = 'https://www.my.com/oauth2/token';
public $apiBaseUrl = 'https://www.my.com/apis/oauth2/v1';
protected function initUserAttributes()
{
return $this->api('userinfo', 'GET');
}
}
You may also specify default auth scopes.
Note: Some OAuth providers may not follow OAuth standards clearly, introducing differences, and may require additional efforts to implement clients for.
You will need to specify:
For example:
use yii\authclient\OAuth1;
class MyAuthClient extends OAuth1
{
public $authUrl = 'https://www.my.com/oauth/auth';
public $requestTokenUrl = 'https://www.my.com/oauth/request_token';
public $accessTokenUrl = 'https://www.my.com/oauth/access_token';
public $apiBaseUrl = 'https://www.my.com/apis/oauth/v1';
protected function initUserAttributes()
{
return $this->api('userinfo', 'GET');
}
}
You may also specify default auth scopes.
Note: Some OAuth providers may not follow OAuth standards clearly, introducing differences, and may require additional efforts to implement clients for.