baywa-re-lusy/jwt-authentication

BayWa r.e. LUSY JWT身份验证

3.0.1 2024-06-21 07:29 UTC

This package is auto-updated.

Last update: 2024-10-01 00:17:00 UTC


README

CircleCI

安装

要安装JWT身份验证服务,您需要在项目中安装Composer

composer require baywa-re-lusy/jwt-authentication

Laminas项目使用示例代码

Module.php

use BayWaReLusy\JwtAuthentication\TokenService;
use Laminas\Cache\Psr\CacheItemPool\CacheItemPoolDecorator;
use BayWaReLusy\JwtAuthentication\Token;

public function onAuthentication(MvcAuthEvent $e): IdentityInterface
{
    $jwt                          = ...; // The JSON Web Token
    $laminasCacheStorageInterface = ...; // Instance of Laminas\Cache\Storage\StorageInterface
    $jwksUrl                      = ...; // URL from where to get JWKs
    $cache                        = new CacheItemPoolDecorator($laminasCacheStorageInterface);
    
    $tokenService = new TokenService();
    
    try {
        $token = $tokenService->validateToken($jwt, $cache, $jwksUrl);
    } catch (\BayWaReLusy\JwtAuthentication\InvalidTokenException $e) {
        return new GuestIdentity();
    }
    
    ...
}