Skip to content

Commit

Permalink
update jwt encode/decode
Browse files Browse the repository at this point in the history
Signed-off-by: envoyr <[email protected]>
  • Loading branch information
envoyr committed Feb 20, 2023
1 parent aea65e0 commit f175197
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/Accounts/ApiTokenCookieFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,6 @@ protected function createToken($userId, string $csrfToken, Carbon $expiration):
'sub' => $userId,
'csrf' => $csrfToken,
'expiry' => $expiration->getTimestamp(),
], $this->encrypter->getKey());
], $this->encrypter->getKey(), 'RS256');
}
}
7 changes: 5 additions & 2 deletions src/Accounts/Auth/TokenGuard.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Bitinflow\Accounts\Traits\HasBitinflowTokens;
use Exception;
use Firebase\JWT\JWT;
use Firebase\JWT\Key;
use Illuminate\Auth\AuthenticationException;
use Illuminate\Auth\GuardHelpers;
use Illuminate\Container\Container;
Expand Down Expand Up @@ -181,8 +182,10 @@ protected function decodeJwtTokenCookie(Request $request): array
{
return (array)JWT::decode(
CookieValuePrefix::remove($this->encrypter->decrypt($request->cookie(BitinflowAccounts::cookie()), BitinflowAccounts::$unserializesCookies)),
$this->encrypter->getKey(),
['HS256']
new Key(
$this->encrypter->getKey(),
'RS256'
)
);
}

Expand Down
6 changes: 2 additions & 4 deletions src/Accounts/Helpers/JwtParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@


use Firebase\JWT\JWT;
use Firebase\JWT\Key;
use Illuminate\Auth\AuthenticationException;
use Illuminate\Http\Request;
use stdClass;
use Throwable;

class JwtParser
{
public const ALLOWED_ALGORITHMS = ['RS256'];

/**
* @param Request $request
* @return stdClass
Expand All @@ -26,8 +25,7 @@ public function decode(Request $request): stdClass
try {
return JWT::decode(
$request->bearerToken(),
$this->getOauthPublicKey(),
self::ALLOWED_ALGORITHMS
new Key($this->getOauthPublicKey(),'RS256')
);
} catch (Throwable $exception) {
throw (new AuthenticationException());
Expand Down

0 comments on commit f175197

Please sign in to comment.