You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
899 B
PHTML
38 lines
899 B
PHTML
|
2 months ago
|
<?php
|
||
|
|
|
||
|
|
namespace App\Services;
|
||
|
|
|
||
|
|
use Firebase\JWT\JWT as JwtClient;
|
||
|
|
use Firebase\JWT\Key;
|
||
|
|
|
||
|
|
class Jwt
|
||
|
|
{
|
||
|
|
private static function getKey()
|
||
|
|
{
|
||
|
|
return Config::get('key');
|
||
|
|
}
|
||
|
|
|
||
|
|
private static function getSigningKey()
|
||
|
|
{
|
||
|
|
$key = (string) self::getKey();
|
||
|
|
return strlen($key) >= 32 ? $key : hash('sha256', $key, true);
|
||
|
|
}
|
||
|
|
|
||
|
|
public static function encode($input)
|
||
|
|
{
|
||
|
|
return JwtClient::encode($input, self::getSigningKey(), 'HS256');
|
||
|
|
}
|
||
|
|
|
||
|
|
public static function encode_withkey($input, $key)
|
||
|
|
{
|
||
|
|
$signingKey = strlen((string) $key) >= 32 ? (string) $key : hash('sha256', (string) $key, true);
|
||
|
|
return JwtClient::encode($input, $signingKey, 'HS256');
|
||
|
|
}
|
||
|
|
|
||
|
|
public static function decodeArray($input)
|
||
|
|
{
|
||
|
|
$decoded = JwtClient::decode($input, new Key(self::getSigningKey(), 'HS256'));
|
||
|
|
return $decoded;
|
||
|
|
}
|
||
|
|
}
|