lexik / LexikJWTAuthenticationBundle

JWT authentication for your Symfony API
MIT License
2.53k stars 610 forks source link

mongodb with symfony 6 is not passing authentication header #1086

Open bocek opened 1 year ago

bocek commented 1 year ago

Hi guys

I am trying to use mongodb as provider and i can successfully login and get a token, however when i try to fetch a protected url it seems authorization header not getting passed ( i checked nginx etc to make sure authorization header not dismissed) so when i call /api/investment it gives the error {"message": "JWT Token not found"}

Here is my security conf,

security: enable_authenticator_manager: true

https://symfony.com/doc/current/security.html#registering-the-user-hashing-passwords

password_hashers:
    Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface: 'auto'
# https://symfony.com/doc/current/security.html#loading-the-user-the-user-provider
providers:
    cucu_mongo:
        mongodb: { class: App\Document\User, property: email }

firewalls:
    dev:
        pattern: ^/(_(profiler|wdt)|css|images|js)/
        security: false

    login:
        pattern: ^/api/login
        provider: cucu_mongo
        stateless: true
        json_login:
            check_path: /api/login
            success_handler: lexik_jwt_authentication.handler.authentication_success
            failure_handler: lexik_jwt_authentication.handler.authentication_failure

    register:
        pattern: ^/api/user/register
        stateless: true

    investment:
        pattern: ^/api/investment
        stateless: true
        provider: cucu_mongo
        jwt: ~

        # 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: ^/api/investment, roles: ROLE_USER }
    # - { path: ^/profile, roles: ROLE_USER }

when@test: security: password_hashers: Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface: algorithm: auto cost: 4 # Lowest possible value for bcrypt time_cost: 3 # Lowest possible value for argon memory_cost: 10 # Lowest possible value for argon

chalasr commented 1 year ago

Did you see https://symfony.com/bundles/LexikJWTAuthenticationBundle/current/index.html#important-note-for-apache-users?

sayou commented 1 year ago

Solution:

https://stackoverflow.com/questions/74830559/unrecognized-option-api-platform-under-lexik-jwt-authentication