代码之家  ›  专栏  ›  技术社区  ›  Achraf

api平台:LexikJWTAuthenticationBundle无法加载私钥

  •  2
  • Achraf  · 技术社区  · 7 年前

    我使用api paltform创建一个认证api,遵循那里的教程。 https://api-platform.com/docs/core/jwt

    无法加载私钥

    安全.yml

    security:
    encoders:
        FOS\UserBundle\Model\UserInterface: bcrypt
    
    
    providers:
        fos_userbundle:
            id: fos_user.user_provider.username
    
    firewalls:
        login:
            pattern:  ^/login
            stateless: true
            anonymous: true
            provider: fos_userbundle
            form_login:
                check_path: /login_check
                username_parameter: _username
                password_parameter: _password
                success_handler: lexik_jwt_authentication.handler.authentication_success
                failure_handler: lexik_jwt_authentication.handler.authentication_failure
                require_previous_session: false
    
        main:
            pattern:   ^/
            provider: fos_userbundle
            stateless: true
            anonymous: true
            lexik_jwt: ~
    
        dev:
            pattern:  ^/(_(profiler|wdt)|css|images|js)/
            security: false
    
    access_control:
        - { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/, roles: IS_AUTHENTICATED_FULLY }
    

    imports:
    - { resource: parameters.yml }
    - { resource: security.yml }
    - { resource: services.yml }
    
    # Put parameters here that don't need to change on each machine where the 
    app  is deployed
    # http://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
    parameters:
         locale: en
    
    framework:
        #esi:             ~
        #translator:      { fallbacks: ["%locale%"] }
        secret:          "%secret%"
        router:
            resource: "%kernel.root_dir%/config/routing.yml"
            strict_requirements: ~
        form:            ~
        csrf_protection: ~
        validation:      { enable_annotations: true }
        serializer:      { enable_annotations: true }
        templating:
            engines: ['twig']
        default_locale:  "%locale%"
        trusted_hosts:   ~
        trusted_proxies: ~
        session:
             # http://symfony.com/doc/current/reference/configuration/framework.html#handler-id
            handler_id:  session.handler.native_file
            save_path:   "%kernel.root_dir%/../var/sessions/%kernel.environment%"
        fragments:       ~
        http_method_override: true
        assets: ~
        php_errors:
            log: true
    
    # Twig Configuration
    twig:
        debug:            "%kernel.debug%"
        strict_variables: "%kernel.debug%"
    
    # Doctrine Configuration
    doctrine:
        dbal:
            driver:   pdo_mysql
            host:     "%database_host%"
            port:     "%database_port%"
            dbname:   "%database_name%"
            user:     "%database_user%"
            password: "%database_password%"
            charset:  UTF8
        # if using pdo_sqlite as your database driver:
        #   1. add the path in parameters.yml
        #     e.g. database_path: "%kernel.root_dir%/data/data.db3"
        #   2. Uncomment database_path in parameters.yml.dist
        #   3. Uncomment next line:
        #     path:     "%database_path%"
    
        orm:
            auto_generate_proxy_classes: "%kernel.debug%"
            naming_strategy: doctrine.orm.naming_strategy.underscore
            auto_mapping: true
    
    # Swiftmailer Configuration
    swiftmailer:
        transport: "%mailer_transport%"
        host:      "%mailer_host%"
        username:  "%mailer_user%"
        password:  "%mailer_password%"
        spool:     { type: memory }
    
    # Nelmio CORS
    nelmio_cors:
        defaults:
            allow_origin:   ["%cors_allow_origin%"]
            allow_methods:  ["POST", "PUT", "GET", "DELETE", "OPTIONS"]
            allow_headers:  ["content-type", "authorization"]
            expose_headers: ["link"]
            max_age:        3600
        paths:
            '^/': ~
    
    fos_user:
        db_driver: orm # other valid values are 'mongodb' and 'couchdb'
        firewall_name: main
        user_class: AppBundle\Entity\User
        from_email:
            address: noreplay@noreplay.com
            sender_name: noreplay
    
    lexik_jwt_authentication:
        private_key_path: '%jwt_private_key_path%'
        public_key_path:  '%jwt_public_key_path%'
        pass_phrase:      '%jwt_key_pass_phrase%'
        token_ttl:        '%jwt_token_ttl%'
    

    路由.yml

    api:
        resource: '.'
        type:     'api_platform'
    
    app:
        resource: '@AppBundle/Action/'
        type:     'annotation'
    
    fos_user:
        resource: "@FOSUserBundle/Resources/config/routing/all.xml"
    
    login_check:
        path: /login_check
    
    2 回复  |  直到 7 年前
        1
  •  4
  •   Alessandro Minoccheri    7 年前

    $ openssl genrsa -out var/jwt/private.pem -aes256 4096
    $ openssl rsa -pubout -in var/jwt/private.pem -out var/jwt/public.pem
    

    您需要插入密码并将其添加到 parameters.yml jwt_key_pass_phrase

    这样地:

    jwt_key_pass_phrase: ''
    
        2
  •  0
  •   Hamza Amrouche    7 年前

    你应该直接查看 LexikJWTAuthenticationBundle

    这可能意味着私钥错误。