Skip to content

Commit

Permalink
#388 Processed PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
rhertogh committed Mar 26, 2024
1 parent 156fd25 commit 64a6666
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/OAuth2.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}

Expand Down

0 comments on commit 64a6666

Please sign in to comment.