free2er/jwt-authenticator-bundle

2.0.1 2019-11-28 19:29 UTC

This package is auto-updated.

Last update: 2024-08-29 05:12:32 UTC


README

JWT 验证器组件

安装

该组件可以通过 Composer 依赖管理器进行安装。

  1. 安装 Composer

  2. 将组件作为项目依赖项安装

     composer require free2er/jwt-authenticator-bundle
    
  3. 启用组件

<?php

// config/bundles.php
return [
    // ...
    Free2er\Jwt\JwtAuthenticatorBundle::class => ['all' => true],
    // ...
];
  1. 配置公钥路径
# config/packages/jwt_authenticator.yaml
jwt_authenticator:
    key: file://%kernel.project_dir%/path/to/public.key
  1. 配置防火墙
# config/packages/security.yaml
security:
    providers:
        jwt:
            id: Free2er\Jwt\Service\UserProvider
    firewalls:
        # ...
        main:
            pattern: ^/api
            stateless: true
            provider: jwt
            guard:
                authenticators:
                    - Free2er\Jwt\Service\Authenticator
        # ...
  1. 完成!