From 64a6666661dc6e4fdcdf92f9138e8ce7eb478522 Mon Sep 17 00:00:00 2001 From: Rutger Hertogh Date: Tue, 26 Mar 2024 01:47:35 +0100 Subject: [PATCH] #388 Processed PR feedback --- src/OAuth2.php | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/OAuth2.php b/src/OAuth2.php index 9366449..f2c0240 100644 --- a/src/OAuth2.php +++ b/src/OAuth2.php @@ -86,8 +86,8 @@ abstract class OAuth2 extends BaseOAuth /** * @var string The location of the access token when it is applied to the request. - * NOTE: According to the OAuth2 specification this should be de `header` by default, - * however, for Backwards compatibility the default value used here is `body`. + * NOTE: According to the OAuth2 specification this should be `header` by default, + * however, for backwards compatibility the default value used here is `body`. * @since 2.2.16 * * @see https://datatracker.ietf.org/doc/html/rfc6749#section-7 @@ -193,14 +193,17 @@ public function fetchAccessToken($authCode, array $params = []) */ public function applyAccessTokenToRequest($request, $accessToken) { - if ($this->accessTokenLocation === self::ACCESS_TOKEN_LOCATION_BODY) { - $data = $request->getData(); - $data['access_token'] = $accessToken->getToken(); - $request->setData($data); - } elseif ($this->accessTokenLocation === self::ACCESS_TOKEN_LOCATION_HEADER) { - $request->getHeaders()->set('Authorization', 'Bearer ' . $accessToken->getToken()); - } else { - throw new InvalidConfigException('Unknown access token location: ' . $this->accessTokenLocation); + switch($this->accessTokenLocation) { + case self::ACCESS_TOKEN_LOCATION_BODY: + $data = $request->getData(); + $data['access_token'] = $accessToken->getToken(); + $request->setData($data); + break; + case self::ACCESS_TOKEN_LOCATION_HEADER: + $request->getHeaders()->set('Authorization', 'Bearer ' . $accessToken->getToken()); + break; + default: + throw new InvalidConfigException('Unknown access token location: ' . $this->accessTokenLocation); } }