Skip to content

Commit

Permalink
Add sandbox capability to OAuthJWT (#333)
Browse files Browse the repository at this point in the history
Thanks @patricknomad! Sorry for taking a while to get this merged in
  • Loading branch information
patricknomad authored Mar 13, 2024
1 parent b21046c commit 96cbd60
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/Omniphx/Forrest/Authentications/OAuthJWT.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,24 @@ public static function getJWT($iss, $aud, $sub, $privateKey)
return JWT::encode($payload, $privateKey, 'RS256');
}

public function authenticate($url = null)
public function authenticate($fullInstanceUrl = null)
{
$domain = $url ?? $this->credentials['loginURL'] . '/services/oauth2/token';
$username = $this->credentials['username'];
// OAuth Client ID
$fullInstanceUrl = $fullInstanceUrl ?? $this->getInstanceURL() . '/services/oauth2/token';

$consumerKey = $this->credentials['consumerKey'];
// Private Key
$loginUrl = $this->credentials['loginURL'];
$username = $this->credentials['username'];
$privateKey = $this->credentials['privateKey'];

// Generate the form parameters
$assertion = static::getJWT($consumerKey, $domain, $username, $privateKey);
$assertion = static::getJWT($consumerKey, $loginUrl, $username, $privateKey);
$parameters = [
'grant_type' => 'urn:ietf:params:oauth:grant-type:jwt-bearer',
'assertion' => $assertion
];

// \Psr\Http\Message\ResponseInterface
$response = $this->httpClient->request('post', $domain, ['form_params' => $parameters]);
$response = $this->httpClient->request('post', $fullInstanceUrl, ['form_params' => $parameters]);

$authToken = json_decode($response->getBody()->getContents(), true);

Expand Down

0 comments on commit 96cbd60

Please sign in to comment.