mirror of
https://github.com/anikeen-com/id.git
synced 2026-05-09 23:29:02 +00:00
first commit
This commit is contained in:
35
src/Id/Helpers/JwtParser.php
Normal file
35
src/Id/Helpers/JwtParser.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace Anikeen\Id\Helpers;
|
||||
|
||||
use Firebase\JWT\JWT;
|
||||
use Firebase\JWT\Key;
|
||||
use Illuminate\Auth\AuthenticationException;
|
||||
use Illuminate\Http\Request;
|
||||
use stdClass;
|
||||
use Throwable;
|
||||
|
||||
class JwtParser
|
||||
{
|
||||
/**
|
||||
* @throws AuthenticationException
|
||||
*/
|
||||
public function decode(Request $request): stdClass
|
||||
{
|
||||
JWT::$leeway = 60;
|
||||
|
||||
try {
|
||||
return JWT::decode(
|
||||
$request->bearerToken(),
|
||||
new Key($this->getOauthPublicKey(), 'RS256')
|
||||
);
|
||||
} catch (Throwable $exception) {
|
||||
throw (new AuthenticationException());
|
||||
}
|
||||
}
|
||||
|
||||
private function getOauthPublicKey(): bool|string
|
||||
{
|
||||
return file_get_contents(dirname(__DIR__, 3) . '/oauth-public.key');
|
||||
}
|
||||
}
|
||||
76
src/Id/Helpers/Paginator.php
Normal file
76
src/Id/Helpers/Paginator.php
Normal file
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
namespace Anikeen\Id\Helpers;
|
||||
|
||||
use Anikeen\Id\Result;
|
||||
use stdClass;
|
||||
|
||||
class Paginator
|
||||
{
|
||||
|
||||
/**
|
||||
* Next desired action (first, after, before).
|
||||
*/
|
||||
public ?string $action = null;
|
||||
|
||||
/**
|
||||
* AnikeenId response pagination cursor.
|
||||
*/
|
||||
private ?stdClass $pagination;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param null|stdClass $pagination AnikeenId response pagination cursor
|
||||
*/
|
||||
public function __construct(?stdClass $pagination = null)
|
||||
{
|
||||
$this->pagination = $pagination;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create Paginator from Result object.
|
||||
*/
|
||||
public static function from(Result $result): self
|
||||
{
|
||||
return new self($result->pagination);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the current active cursor.
|
||||
*/
|
||||
public function cursor(): string
|
||||
{
|
||||
return $this->pagination->cursor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Paginator to fetch the next set of results.
|
||||
*/
|
||||
public function first(): self
|
||||
{
|
||||
$this->action = 'first';
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Paginator to fetch the first set of results.
|
||||
*/
|
||||
public function next(): self
|
||||
{
|
||||
$this->action = 'after';
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Paginator to fetch the last set of results.
|
||||
*/
|
||||
public function back(): self
|
||||
{
|
||||
$this->action = 'before';
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user