Home > Mobile >  Unrecognized option "api_platform" under "lexik_jwt_authentication"
Unrecognized option "api_platform" under "lexik_jwt_authentication"

Time:12-19

I am currently working on programming a website using Symfony version 6.2 and API Platform in addition to MongoDB in the database and a work environment on Docker.

I am trying to add the feature of connecting through JWT (LexikJWTAuthenticationBundle), and I was able to log in successfully and get the token, but when I try to use the token to get access to the rest of the pages, the response is always as follows:

{
    "code": 401,
    "message": "JWT Token not found"
}

I searched for the cause of the following problem in the search engines, and the solutions presented were numerous (although unfortunately, they are absent in everything related to the latest version of Symfony), most notably modifying the environment and adding the following code:

SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1

Honestly, I didn't know exactly how to change this command in the Docker environment, but when I use the following code on the index page to check that the token is being sent, I get the correct answer and that the token is being sent

$token = getallheaders()['Authorization'];

print_r($token);
exit;

My vhost.conf on Docker:

<VirtualHost *:80>
    ServerName localhost
 
    DocumentRoot /var/www/project/public
    DirectoryIndex /index.php
 
    <Directory /var/www/project/public>
        AllowOverride None
        Order Allow,Deny
        Allow from All
 
        FallbackResource /index.php
    </Directory>
 
    # uncomment the following lines if you install assets as symlinks
    # or run into problems when compiling LESS/Sass/CoffeeScript assets
    # <Directory /var/www/project>
    #     Options FollowSymlinks
    # </Directory>
 
    # optionally disable the fallback resource for the asset directories
    # which will allow Apache to return a 404 error when files are
    # not found instead of passing the request to Symfony
    <Directory /var/www/project/public/bundles>
        FallbackResource disabled
    </Directory>
    ErrorLog /var/log/apache2/project_error.log
    CustomLog /var/log/apache2/project_access.log combined
 
    # optionally set the value of the environment variables used in the application
    #SetEnv APP_ENV prod
    #SetEnv APP_SECRET <app-secret-id>
    #SetEnv DATABASE_URL "mysql://db_user:db_pass@host:3306/db_name"
</VirtualHost>

I went to the official documentation for the used bundle (LexikJWTAuthenticationBundle), but unfortunately, when I do the next step:

# config/packages/lexik_jwt_authentication.yaml
lexik_jwt_authentication:
    # ...
    api_platform:
        check_path: /api/login_check

I get the following error:

Unrecognized option "api_platform" under "lexik_jwt_authentication". Available options are "additional_public_keys", "allow_no_expiration", "clock_skew", "encoder", "pass_phrase", "private_key_path", "public_key", "public_key_path", "remove_token_from_body_when_cookies_used", "secret_key", "set_cookies", "token_extractors", "token_ttl", "user_id_claim", "user_identity_field".

Is there a solution to that?

CodePudding user response:

Immediately after adding my vhost code to the question, I was able to figure out the answer, as I had to add the following edit here:

# optionally set the value of the environment variables used in the application
    #SetEnv APP_ENV prod
    #SetEnv APP_SECRET <app-secret-id>
    #SetEnv DATABASE_URL "mysql://db_user:db_pass@host:3306/db_name"
    SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
</VirtualHost>

The problem has been resolved successfully

  • Related