Skip to content

Commit

Permalink
Add region support for /me (#26)
Browse files Browse the repository at this point in the history
* RELEASE

* added region support

* added changes

* revert changes
  • Loading branch information
gaokevin1 authored Jul 26, 2024
1 parent 4c2ec31 commit 643fbb2
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 10 deletions.
2 changes: 0 additions & 2 deletions sample/callback.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
]);

if (isset($_POST["sessionToken"]) && $descopeSDK->verify($_POST["sessionToken"])) {
session_start()

$_SESSION["user"] = json_decode($_POST["userDetails"], true);
$_SESSION["sessionToken"] = $_POST["sessionToken"];

Expand Down
1 change: 0 additions & 1 deletion sample/login.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ function sendFormData(sessionToken, userDetails) {
if (validRefreshToken) {
console.log("Valid refresh token found. Logging in...");
sdk.refresh();
const user = getUserDetails().then((user) => {
const sessionToken = sdk.getSessionToken();
sendFormData(sessionToken, user.data);
Expand Down
7 changes: 6 additions & 1 deletion src/SDK/Configuration/SDKConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
use GuzzleHttp\Client;
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Psr7\Request;
use Descope\SDK\EndpointsV2;
use Descope\SDK\API;

final class SDKConfig
{
Expand All @@ -18,6 +20,8 @@ public function __construct(array $config)
$this->client = new Client();
$this->projectId = $config['projectId'];
$this->managementKey = $config['managementKey'] ?? '';

EndpointsV2::setBaseUrl($config['projectId']);

$this->jwkSets = $this->getJWKSets();
}
Expand All @@ -28,8 +32,9 @@ public function __construct(array $config)
private function getJWKSets()
{
try {
$url = EndpointsV2::getPublicKeyPath();

// Fetch JWK public key from Descope API
$url = 'https://api.descope.com/v2/keys/' . $this->projectId;
$res = $this->client->request('GET', $url);
$jwkSets = json_decode($res->getBody(), true);
return $jwkSets;
Expand Down
6 changes: 2 additions & 4 deletions src/SDK/DescopeSDK.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ class DescopeSDK
public Management $management;
public API $api;

public string $baseUrl;

/**
* Constructor for DescopeSDK class.
*
Expand All @@ -35,11 +33,11 @@ public function __construct(array $config)
throw new \InvalidArgumentException('Please add a Descope Project ID to your .ENV file.');
}

$this->config = new SDKConfig($config);

EndpointsV1::setBaseUrl($config['projectId']);
EndpointsV2::setBaseUrl($config['projectId']);

$this->config = new SDKConfig($config);

$this->api = new API($config['projectId'], $config['managementKey'] ?? '');
// If OPTIONAL management key was provided in $config
if (!empty($config['managementKey'])) {
Expand Down
1 change: 0 additions & 1 deletion src/SDK/Management/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,6 @@ public function searchAll(
}

$jsonBody = json_encode($body);
print($jsonBody);

try {
$response = $this->api->doPost(
Expand Down
2 changes: 1 addition & 1 deletion src/SDK/Token/Extractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function getUserDetails($refreshToken)
{
$client = $this->config->client;
try {
$url = 'https://api.descope.com/v1/auth/me';
$url = EndpointsV1::$ME_PATH;
$header = 'Bearer ' . $this->config->projectId . ":" . $refreshToken;
$res = $client->request(
'GET',
Expand Down

0 comments on commit 643fbb2

Please sign in to comment.