Skip to content

Commit

Permalink
added TokenValidator class
Browse files Browse the repository at this point in the history
  • Loading branch information
gaokevin1 committed Jan 2, 2025
1 parent 134de0e commit a117f32
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 54 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:

strategy:
matrix:
php-version: [8.1, 7.3]
php-version: [8.1, 7.4]

steps:
- uses: actions/checkout@v2
Expand Down
92 changes: 46 additions & 46 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 8 additions & 7 deletions src/SDK/DescopeSDK.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Descope\SDK\EndpointsV1;
use Descope\SDK\EndpointsV2;
use Descope\SDK\Exception\AuthException;
use Descope\SDK\Exception\ValidateException;

use Descope\SDK\Management\MgmtV1;

Expand Down Expand Up @@ -66,7 +67,7 @@ public function verify($sessionToken = null): bool
$sessionToken = $sessionToken ?? $_COOKIE[EndpointsV1::$SESSION_COOKIE_NAME] ?? null;

if (!$sessionToken) {
throw new \InvalidArgumentException('Session token cannot be null or empty.');
throw ValidationException::forMissingSessionToken();
}

$verifier = new Verifier($this->config, $this->api);
Expand All @@ -85,7 +86,7 @@ public function refreshSession($refreshToken = null): array
$refreshToken = $refreshToken ?? $_COOKIE[EndpointsV1::$REFRESH_COOKIE_NAME] ?? null;

if (empty($refreshToken)) {
throw new \InvalidArgumentException('Refresh token cannot be null or empty.');
throw ValidationException::forMissingRefreshToken();
}

try {
Expand Down Expand Up @@ -116,7 +117,7 @@ public function verifyAndRefreshSession($sessionToken = null, $refreshToken = nu
$refreshToken = $refreshToken ?? $_COOKIE[EndpointsV1::$REFRESH_COOKIE_NAME] ?? null;

if (empty($sessionToken) || empty($refreshToken)) {
throw new \InvalidArgumentException('Session or refresh token cannot be null or empty.');
throw new ValidateException('Session or refresh token cannot be null or empty.');
}

try {
Expand All @@ -139,7 +140,7 @@ public function getClaims($token = null): array
$token = $token ?? $_COOKIE[EndpointsV1::$SESSION_COOKIE_NAME] ?? null;

if (!$token) {
throw new \InvalidArgumentException('Session token cannot be null or empty.');
throw ValidationException::forMissingSessionToken();
}

$extractor = new Extractor($this->config);
Expand All @@ -158,7 +159,7 @@ public function getUserDetails(string $refreshToken = null): array
$refreshToken = $refreshToken ?? $_COOKIE[EndpointsV1::$REFRESH_COOKIE_NAME] ?? null;

if (!$refreshToken) {
throw new \InvalidArgumentException('Refresh token cannot be null or empty.');
throw ValidationException::forMissingRefreshToken();
}

try {
Expand Down Expand Up @@ -186,7 +187,7 @@ public function logout(string $refreshToken = null): void
$refreshToken = $refreshToken ?? $_COOKIE[EndpointsV1::$REFRESH_COOKIE_NAME] ?? null;

if (!$refreshToken) {
throw new \InvalidArgumentException('Refresh token cannot be null or empty.');
throw ValidationException::forMissingRefreshToken();
}

try {
Expand Down Expand Up @@ -216,7 +217,7 @@ public function logoutAll(string $refreshToken = null): void
$refreshToken = $refreshToken ?? $_COOKIE[EndpointsV1::$REFRESH_COOKIE_NAME] ?? null;

if (!$refreshToken) {
throw new \InvalidArgumentException('Refresh token cannot be null or empty.');
throw ValidationException::forMissingRefreshToken();
}

try {
Expand Down
Loading

0 comments on commit a117f32

Please sign in to comment.