2017-11-09 13 views
1

JWTとPHPでいくつかの実験をしようとしていますが、LexikJWTAuthenticationBundleを動作させることはできません。LexikJWTAuthenticationBundle - "api_login_check"の設定を読み込める拡張子がありません

私はその後、私はGitHubのプロジェクト(https://github.com/lexik/LexikJWTAuthenticationBundle/blob/master/Resources/doc/index.md#getting-started)からスタートしたが、私は、アプリケーションを実行しようとすると、私はこのエラーメッセージましガイドに従う作曲composer create-project symfony/skeleton my_projectを使用してsymfonyプロジェクトを作成し、symfonyのフレックスcomposer req jwt-auth でLexikJWTAuthenticationBundleをインストールします。

[Symfony\Component\Config\Exception\FileLoaderLoadException] 
There is no extension able to load the configuration for "api_login_check" (in /home/alan/Desktop/auth/config/packages/routing.yaml). Looked for namespace "api_login_check", found "framework", "security", "lexik_jwt_authentication" in /home/alan/Desktop/auth/config/packages/routing.yaml (which is loaded in resource "/home/alan/Desktop/auth/config/packages/routing.yaml"). 

[Symfony\Component\DependencyInjection\Exception\InvalidArgumentException] 
There is no extension able to load the configuration for "api_login_check" (in /home/alan/Desktop/auth/config/packages/routing.yaml). Looked for namespace "api_login_check", found "framework", "security", "lexik_jwt_authentication" 

私は誰かが私に私が間違っているの何いくつかのヒントを与えてもらえますか?エラー https://github.com/alanoliveira/jwt_auth_test

を取得しているコードをgithubのリポジトリを作成しましたか

+0

で他の誰かを助けることができると思います

はappKernel.phpにバンドルを登録しましたか? – Mz1907

+0

あなたのconfig.ymlファイルを表示できますか? – Boulboulouboule

+0

プロジェクトをgithubにアップロードしましたので、コードを確認するのが簡単です。https://github.com/alanoliveira/jwt_auth_test –

答えて

2

解決策が見つかりました!

まず、security.confに我々はメインファイアウォールの前ログインAPIファイアウォールを追加する必要があります。

# config/packages/security.yaml 
security: 
    # https://symfony.com/doc/current/book/security.html#where-do-users-come-from-user-providers 
    providers: 
     in_memory: { memory: ~ } 
    firewalls: 
     login: 
      pattern: ^/api/login 
      stateless: true 
      anonymous: true 
      form_login: 
       check_path:    /api/login_check 
       success_handler:   lexik_jwt_authentication.handler.authentication_success 
       failure_handler:   lexik_jwt_authentication.handler.authentication_failure 
       require_previous_session: false 

     api: 
      pattern: ^/api 
      stateless: true 
      guard: 
       authenticators: 
        - lexik_jwt_authentication.jwt_token_authenticator 

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

      # activate different ways to authenticate 

      # http_basic: ~ 
      # https://symfony.com/doc/current/book/security.html#a-configuring-how-your-users-will-authenticate 

      # form_login: ~ 
      # https://symfony.com/doc/current/cookbook/security/form_login_setup.html 

    access_control: 
     - { path: ^/api/login, roles: IS_AUTHENTICATED_ANONYMOUSLY } 
     - { path: ^/api,  roles: IS_AUTHENTICATED_FULLY } 

次にルートの設定は、routes.yamlで定義する必要があり、かつrouting.yaml

# config/routes.yaml 
api_login_check: 
    path: /api/login_check 

で最後に我々は、セッションの行のコメントを削除する必要はありませんframework.yaml

# config/packages/framework.yaml 
framework: 
    secret: '%env(APP_SECRET)%' 
    #default_locale: en 
    #csrf_protection: ~ 
    #http_method_override: true 
    #trusted_hosts: ~ 
    # https://symfony.com/doc/current/reference/configuration/framework.html#handler-id 
    session: 
     # The native PHP session handler will be used 
     handler_id: ~ 
    #esi: ~ 
    #fragments: ~ 
    php_errors: 
     log: true 

それ笙uldは仕事をする!私はそれが同じ問題

1

このルートをrouting.ymlファイルに追加しましたか? :

api_login_check: 
path: /api/login_check 
+0

routing.yamlからroutes.yamlにコードを移動すると、プロジェクトが実行されますが、404 'curl -X POST http:// localhost:8000/api/login_check -d _username = johndoe -d _password = test'を呼び出そうとするとエラーが発生する –

+0

これは最後の動作よりも優れた動作です! – Boulboulouboule

関連する問題