Loading src/Annotation/Oauth2Client.php +17 −0 Original line number Diff line number Diff line Loading @@ -53,6 +53,9 @@ class Oauth2Client extends Plugin { /** * The resource endpoint of the OAuth2 Server. * * @deprecated in oauth2_client:3.1 and is removed from oauth2_client:4.0. Use * the new request options parameter in this annotation instead. * * @var string */ public $resource_uri; Loading Loading @@ -82,6 +85,20 @@ class Oauth2Client extends Plugin { */ public $scope_separator = ','; /** * An optional set of additional parameters on the token request. * * OPTIONAL. * The array key will be used as the request parameter: * * request_options = { * "parameter" = "value", * }, * * @var array */ public $request_options = []; /** * A flag that may be used by Oauth2ClientPluginInterface::storeAccessToken. * Loading src/Plugin/Oauth2Client/Oauth2ClientPluginBase.php +17 −8 Original line number Diff line number Diff line Loading @@ -392,11 +392,7 @@ abstract class Oauth2ClientPluginBase extends PluginBase implements Oauth2Client * {@inheritdoc} */ public function getScopes() { if (!isset($this->pluginDefinition['scopes'])) { return []; } return $this->pluginDefinition['scopes'] ?: []; return $this->pluginDefinition['scopes'] ?? NULL; } /** Loading Loading @@ -433,13 +429,26 @@ abstract class Oauth2ClientPluginBase extends PluginBase implements Oauth2Client * {@inheritdoc} */ public function getScopeSeparator() { if (!isset($this->pluginDefinition['scope_separator'])) { return ','; } $this->checkKeyDefined('scope_separator'); return $this->pluginDefinition['scope_separator']; } /** * {@inheritdoc} */ public function getRequestOptions(array $additionalOptions = []) { try { $this->checkKeyDefined('request_options'); $options = $this->pluginDefinition['request_options']; } catch (Oauth2ClientPluginMissingKeyException $e) { $options = []; } return array_merge($options, $additionalOptions); } /** * Check that a key is defined when requested. Throw an exception if not. * Loading src/Plugin/Oauth2Client/Oauth2ClientPluginInterface.php +15 −1 Original line number Diff line number Diff line Loading @@ -82,13 +82,27 @@ interface Oauth2ClientPluginInterface extends PluginInspectionInterface, Contain public function getTokenUri(); /** * Retrieves the resource_uri of the OAuth2 server. * Retrieves the resource owner uri of the OAuth2 server. * * @return string * The resource_uri of the OAuth2 server. */ public function getResourceUri(); /** * Get an array of additional request parameters on the token request. * * Merges the request_options parameter from the plugin definition with * any passed in options, such as 'code', '`username' or 'password'. * * @param array $additionalOptions * An array of additional options to merge with request options. * * @return array * The associative array of parameters. */ public function getRequestOptions(array $additionalOptions = []); /** * Get the set of scopes for the provider to use by default. * Loading src/Service/Grant/AuthorizationCodeGrantService.php +5 −3 Original line number Diff line number Diff line Loading @@ -86,12 +86,14 @@ class AuthorizationCodeGrantService extends Oauth2ClientGrantServiceBase { * Exception thrown when trying to retrieve a non-existent OAuth2 Client. */ public function requestAccessToken($pluginId, $code) { $client = $this->getClient($pluginId); $provider = $this->getProvider($pluginId); // There should not be a 'code' key in the options, ensure the parameter // value is used. $options = $client->getRequestOptions(['code' => $code]); // Try to get an access token using the authorization code grant. try { $accessToken = $provider->getAccessToken('authorization_code', [ 'code' => $code, ]); $accessToken = $provider->getAccessToken('authorization_code', $options); if ($accessToken instanceof AccessTokenInterface) { $this->storeAccessToken($pluginId, $accessToken); return TRUE; Loading src/Service/Grant/ClientCredentialsGrantService.php +2 −1 Original line number Diff line number Diff line Loading @@ -14,6 +14,7 @@ class ClientCredentialsGrantService extends Oauth2ClientGrantServiceBase { * {@inheritdoc} */ public function getAccessToken($pluginId) { $client = $this->getClient($pluginId); $provider = $this->getProvider($pluginId); $optionProvider = $provider->getOptionProvider(); // If the provider was just created, our OptionProvder must be set. Loading @@ -23,7 +24,7 @@ class ClientCredentialsGrantService extends Oauth2ClientGrantServiceBase { } try { $accessToken = $provider->getAccessToken('client_credentials'); $accessToken = $provider->getAccessToken('client_credentials', $client->getRequestOptions()); $this->storeAccessToken($pluginId, $accessToken); } Loading Loading
src/Annotation/Oauth2Client.php +17 −0 Original line number Diff line number Diff line Loading @@ -53,6 +53,9 @@ class Oauth2Client extends Plugin { /** * The resource endpoint of the OAuth2 Server. * * @deprecated in oauth2_client:3.1 and is removed from oauth2_client:4.0. Use * the new request options parameter in this annotation instead. * * @var string */ public $resource_uri; Loading Loading @@ -82,6 +85,20 @@ class Oauth2Client extends Plugin { */ public $scope_separator = ','; /** * An optional set of additional parameters on the token request. * * OPTIONAL. * The array key will be used as the request parameter: * * request_options = { * "parameter" = "value", * }, * * @var array */ public $request_options = []; /** * A flag that may be used by Oauth2ClientPluginInterface::storeAccessToken. * Loading
src/Plugin/Oauth2Client/Oauth2ClientPluginBase.php +17 −8 Original line number Diff line number Diff line Loading @@ -392,11 +392,7 @@ abstract class Oauth2ClientPluginBase extends PluginBase implements Oauth2Client * {@inheritdoc} */ public function getScopes() { if (!isset($this->pluginDefinition['scopes'])) { return []; } return $this->pluginDefinition['scopes'] ?: []; return $this->pluginDefinition['scopes'] ?? NULL; } /** Loading Loading @@ -433,13 +429,26 @@ abstract class Oauth2ClientPluginBase extends PluginBase implements Oauth2Client * {@inheritdoc} */ public function getScopeSeparator() { if (!isset($this->pluginDefinition['scope_separator'])) { return ','; } $this->checkKeyDefined('scope_separator'); return $this->pluginDefinition['scope_separator']; } /** * {@inheritdoc} */ public function getRequestOptions(array $additionalOptions = []) { try { $this->checkKeyDefined('request_options'); $options = $this->pluginDefinition['request_options']; } catch (Oauth2ClientPluginMissingKeyException $e) { $options = []; } return array_merge($options, $additionalOptions); } /** * Check that a key is defined when requested. Throw an exception if not. * Loading
src/Plugin/Oauth2Client/Oauth2ClientPluginInterface.php +15 −1 Original line number Diff line number Diff line Loading @@ -82,13 +82,27 @@ interface Oauth2ClientPluginInterface extends PluginInspectionInterface, Contain public function getTokenUri(); /** * Retrieves the resource_uri of the OAuth2 server. * Retrieves the resource owner uri of the OAuth2 server. * * @return string * The resource_uri of the OAuth2 server. */ public function getResourceUri(); /** * Get an array of additional request parameters on the token request. * * Merges the request_options parameter from the plugin definition with * any passed in options, such as 'code', '`username' or 'password'. * * @param array $additionalOptions * An array of additional options to merge with request options. * * @return array * The associative array of parameters. */ public function getRequestOptions(array $additionalOptions = []); /** * Get the set of scopes for the provider to use by default. * Loading
src/Service/Grant/AuthorizationCodeGrantService.php +5 −3 Original line number Diff line number Diff line Loading @@ -86,12 +86,14 @@ class AuthorizationCodeGrantService extends Oauth2ClientGrantServiceBase { * Exception thrown when trying to retrieve a non-existent OAuth2 Client. */ public function requestAccessToken($pluginId, $code) { $client = $this->getClient($pluginId); $provider = $this->getProvider($pluginId); // There should not be a 'code' key in the options, ensure the parameter // value is used. $options = $client->getRequestOptions(['code' => $code]); // Try to get an access token using the authorization code grant. try { $accessToken = $provider->getAccessToken('authorization_code', [ 'code' => $code, ]); $accessToken = $provider->getAccessToken('authorization_code', $options); if ($accessToken instanceof AccessTokenInterface) { $this->storeAccessToken($pluginId, $accessToken); return TRUE; Loading
src/Service/Grant/ClientCredentialsGrantService.php +2 −1 Original line number Diff line number Diff line Loading @@ -14,6 +14,7 @@ class ClientCredentialsGrantService extends Oauth2ClientGrantServiceBase { * {@inheritdoc} */ public function getAccessToken($pluginId) { $client = $this->getClient($pluginId); $provider = $this->getProvider($pluginId); $optionProvider = $provider->getOptionProvider(); // If the provider was just created, our OptionProvder must be set. Loading @@ -23,7 +24,7 @@ class ClientCredentialsGrantService extends Oauth2ClientGrantServiceBase { } try { $accessToken = $provider->getAccessToken('client_credentials'); $accessToken = $provider->getAccessToken('client_credentials', $client->getRequestOptions()); $this->storeAccessToken($pluginId, $accessToken); } Loading