Skip to content

Commit

Permalink
Fix bugs token class
Browse files Browse the repository at this point in the history
  • Loading branch information
achmadhadikurnia committed Sep 18, 2023
1 parent 9085269 commit 2aaae07
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
18 changes: 16 additions & 2 deletions src/Credentials/Token.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Kanekescom\Siasn\Api\Credentials;

use Kanekescom\Siasn\Api\Exceptions\InvalidSsoCredentialsException;
use Kanekescom\Siasn\Api\Exceptions\InvalidWsCredentialsException;
use Kanekescom\Siasn\Api\SiasnConfig;

class Token
Expand All @@ -12,7 +14,13 @@ class Token
public static function getSsoToken()
{
return cache()->remember('sso-token', SiasnConfig::getSsoTokenAge(), function () {
return Sso::getToken()->object();
$ssoToken = Sso::getToken()->object();

if (blank(optional($ssoToken)->token_type) || blank(optional($ssoToken)->access_token)) {
throw new InvalidSsoCredentialsException('Invalid SSO user credentials.');
}

return $ssoToken;
});
}

Expand All @@ -22,7 +30,13 @@ public static function getSsoToken()
public static function getWsToken()
{
return cache()->remember('ws-token', SiasnConfig::getWsTokenAge(), function () {
return Ws::getToken()->object();
$wsToken = Ws::getToken()->object();

if (blank(optional($wsToken)->access_token)) {
throw new InvalidWsCredentialsException('Invalid WS user credentials.');
}

return $wsToken;
});
}
}
2 changes: 1 addition & 1 deletion tests/CommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,6 @@ public function can_forget_token()
/** @test */
public function can_get_data()
{
$this->artisan('siasn:get ' . env('SIASN_GET_ENDPOINT_TEST'))->assertSuccessful();
$this->artisan('siasn:get '.env('SIASN_GET_ENDPOINT_TEST'))->assertSuccessful();
}
}

0 comments on commit 2aaae07

Please sign in to comment.