首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >未找到jwt lexik JWT自述

未找到jwt lexik JWT自述
EN

Stack Overflow用户
提问于 2022-05-13 23:15:52
回答 1查看 531关注 0票数 0

我已经寻找了一段时间的解决方案。所有身份验证系统都已经就绪,我得到了令牌,但是当我使用它检索数据时,我得到了一个404 jwt。

我在这个项目上有紧急情况,一个帮助会对我有很大帮助。

这是我的security.yaml:

代码语言:javascript
复制
app_user_provider:
        entity:
            class: App\Entity\User
            property: email
firewalls:
    dev:
        pattern: ^/(_(profiler|wdt)|css|images|js)/
        security: false

    login:
        pattern: ^/api/login
        stateless: true
        json_login:
            check_path: /api/login_check # or api_login_check as defined in config/routes.yaml
            success_handler: lexik_jwt_authentication.handler.authentication_success
            failure_handler: lexik_jwt_authentication.handler.authentication_failure
    api:
        pattern:   ^/api
        stateless: true
        guard:
            authenticators:
                - lexik_jwt_authentication.jwt_token_authenticator
    

    main:
        lazy: true
        provider: app_user_provider

        # activate different ways to authenticate
        # https://symfony.com/doc/current/security.html#the-firewall

        # https://symfony.com/doc/current/security/impersonating_user.html
        # switch_user: true

# Easy way to control access for large sections of your site
# Note: Only the *first* access control that matches will be used
access_control:
    # - { path: ^/admin, roles: ROLE_ADMIN }
    # - { path: ^/profile, roles: ROLE_USER }
    - { path: ^/api/login, roles: PUBLIC_ACCESS }
    - { path: ^/api,       roles: IS_AUTHENTICATED_FULLY }

Pour声明du控制器:

代码语言:javascript
复制
api_login_check:
  path: /api/login_check
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-07-14 00:59:03

您必须执行以下操作:转到/config/packages/lexik_jwt_authentication.yaml

代码语言:javascript
复制
lexik_jwt_authentication:
    secret_key: '%env(resolve:JWT_SECRET_KEY)%'
    public_key: '%env(resolve:JWT_PUBLIC_KEY)%'
    pass_phrase: '%env(JWT_PASSPHRASE)%'

    token_extractors:
        authorization_header:
                        enabled: true
                        prefix:  Bearer
                        name:    Authorization
        cookie: // if you are using cookie
                enabled: true
                name: cookie_name // set the cookie name

如果您正在使用httpClient;那么您可以授权:标题中的“承载者”.$token,如下所示;

代码语言:javascript
复制
 $headers = [
            'Authorization' => 'Bearer '.$token,
            'Content-Type' => 'application/json',
        ];

注意:确保您有jwt目录,其中有私钥和公钥。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72236185

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档