Class yii\authclient\OpenIdConnect
Inheritance | yii\authclient\OpenIdConnect » yii\authclient\OAuth2 » yii\authclient\BaseOAuth » yii\authclient\BaseClient » yii\base\Component » yii\base\BaseObject |
---|---|
Implements | yii\authclient\ClientInterface, yii\base\Configurable |
Available since version | 2.1.3 |
Source Code | https://github.com/yiisoft/yii2-authclient/blob/master/OpenIdConnect.php |
OpenIdConnect serves as a client for the OpenIdConnect flow.
Application configuration example:
'components' => [
'authClientCollection' => [
'class' => 'yii\authclient\Collection',
'clients' => [
'google' => [
'class' => 'yii\authclient\OpenIdConnect',
'issuerUrl' => 'https://accounts.google.com',
'clientId' => 'google_client_id',
'clientSecret' => 'google_client_secret',
'name' => 'google',
'title' => 'Google OpenID Connect',
],
],
]
// ...
]
This class requires web-token/jwt-checker
,web-token/jwt-key-mgmt
, web-token/jwt-signature
, web-token/jwt-signature-algorithm-hmac
,
web-token/jwt-signature-algorithm-ecdsa
and web-token/jwt-signature-algorithm-rsa
libraries to be installed for
JWS verification. This can be done via composer:
composer require --prefer-dist "web-token/jwt-checker:>=1.0 <3.0" "web-token/jwt-signature:>=1.0 <3.0"
"web-token/jwt-signature:>=1.0 <3.0" "web-token/jwt-signature-algorithm-hmac:>=1.0 <3.0"
"web-token/jwt-signature-algorithm-ecdsa:>=1.0 <3.0" "web-token/jwt-signature-algorithm-rsa:>=1.0 <3.0"
Note: if you are using well-trusted OpenIdConnect provider, you may disable $validateJws, making installation of
web-token
library redundant, however it is not recommended as it violates the protocol specification.
See also:
Public Properties
Property | Type | Description | Defined By |
---|---|---|---|
$allowedJwsAlgorithms | array | JWS algorithms, which are allowed to be used. | yii\authclient\OpenIdConnect |
$apiBaseUrl | string | API base URL. | yii\authclient\BaseOAuth |
$authUrl | string | Authorize URL. | yii\authclient\BaseOAuth |
$autoRefreshAccessToken | boolean | Whether to automatically perform 'refresh access token' request on expired access token. | yii\authclient\BaseOAuth |
$clientId | string | OAuth client ID. | yii\authclient\OAuth2 |
$clientSecret | string | OAuth client secret. | yii\authclient\OAuth2 |
$configParamsCacheKeyPrefix | string | The prefix for the key used to store \yii\authclient\configParams data in cache. | yii\authclient\OpenIdConnect |
$issuerUrl | string | OpenID Issuer (provider) base URL, e.g. `https://example. | yii\authclient\OpenIdConnect |
$parametersToKeepInReturnUrl | array | List of the parameters to keep in default return url. | yii\authclient\BaseOAuth |
$scope | {@inheritdoc} | yii\authclient\OpenIdConnect | |
$tokenUrl | string | Token request URL endpoint. | yii\authclient\OAuth2 |
$validateAuthState | boolean | Whether to use and validate auth 'state' parameter in authentication flow. | yii\authclient\OAuth2 |
$validateJws | boolean | Whether to validate/decrypt JWS received with Auth token. | yii\authclient\OpenIdConnect |
$version | string | Protocol version. | yii\authclient\BaseOAuth |
Public Methods
Protected Methods
Property Details
JWS algorithms, which are allowed to be used.
These are used by web-token
library for JWS validation/decryption.
Make sure to install web-token/jwt-signature-algorithm-hmac
, web-token/jwt-signature-algorithm-ecdsa
and web-token/jwt-signature-algorithm-rsa
packages that support the particular algorithm before adding it here.
The prefix for the key used to store \yii\authclient\configParams data in cache. Actual cache key will be formed addition \yii\authclient\id value to it.
See also \yii\authclient\cache.
OpenID Issuer (provider) base URL, e.g. https://example.com
.
Whether to validate/decrypt JWS received with Auth token.
Note: this functionality requires web-token/jwt-checker
, web-token/jwt-key-mgmt
, web-token/jwt-signature
composer package to be installed. You can disable this option in case of usage of trusted OpenIDConnect provider,
however this violates the protocol rules, so you are doing it on your own risk.
Method Details
{@inheritdoc}
public void applyAccessTokenToRequest ( $request, $accessToken ) | ||
$request | ||
$accessToken |
{@inheritdoc}
protected void applyClientCredentialsToRequest ( $request ) | ||
$request |
{@inheritdoc}
public void buildAuthUrl ( array $params = [] ) | ||
$params |
{@inheritdoc}
protected void createToken ( array $tokenConfig = [] ) | ||
$tokenConfig |
Discovers OpenID Provider configuration parameters.
protected array discoverConfig ( ) | ||
return | array | OpenID Provider configuration parameters. |
---|---|---|
throws | yii\authclient\InvalidResponseException | on failure. |
{@inheritdoc}
public void fetchAccessToken ( $authCode, array $params = [] ) | ||
$authCode | ||
$params |
Generates the auth nonce value.
protected string generateAuthNonce ( ) | ||
return | string | Auth nonce value. |
---|
public yii\caching\Cache|null getCache ( ) | ||
return | yii\caching\Cache|null | The cache object, |
---|
Returns particular configuration parameter value.
public mixed getConfigParam ( $name ) | ||
$name | string | Configuration parameter name. |
return | mixed | Configuration parameter value. |
---|
public array getConfigParams ( ) | ||
return | array | OpenID provider configuration parameters. |
---|
Return JwkSet, returning related data.
protected \yii\authclient\JWKSet getJwkSet ( ) | ||
return | \yii\authclient\JWKSet | Object represents a key set. |
---|---|---|
throws | yii\authclient\InvalidResponseException | on failure. |
Return JWSLoader that validate the JWS token.
protected \Jose\Component\Signature\JWSLoader getJwsLoader ( ) | ||
return | \Jose\Component\Signature\JWSLoader | To do token validation. |
---|---|---|
throws | yii\base\InvalidConfigException | on invalid algorithm provide in configuration. |
public boolean getValidateAuthNonce ( ) | ||
return | boolean | Whether to use and validate auth 'nonce' parameter in authentication flow. |
---|
{@inheritdoc}
protected void initUserAttributes ( ) |
Decrypts/validates JWS, returning related data.
protected array loadJws ( $jws ) | ||
$jws | string | Raw JWS input. |
return | array | JWS underlying data. |
---|---|---|
throws | yii\web\HttpException | on invalid JWS signature. |
{@inheritdoc}
public void refreshAccessToken ( yii\authclient\OAuthToken $token ) | ||
$token |
Sets up a component to be used for caching.
This can be one of the following:
- an application component ID (e.g.
cache
) - a configuration array
- a yii\caching\Cache object
When null
is passed, it means caching is not enabled.
public void setCache ( $cache ) | ||
$cache | yii\caching\Cache|array|string|null | The cache object or the ID of the cache application component. |
public void setValidateAuthNonce ( $validateAuthNonce ) | ||
$validateAuthNonce | boolean | Whether to use and validate auth 'nonce' parameter in authentication flow. |
Validates the claims data received from OpenID provider.
protected void validateClaims ( array $claims ) | ||
$claims | array | Claims data. |
throws | yii\web\HttpException | on invalid claims. |
---|