Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get a 401 when i tried to obtain the token #84

Closed
AnasOuahidi opened this issue Aug 7, 2015 · 2 comments
Closed

get a 401 when i tried to obtain the token #84

AnasOuahidi opened this issue Aug 7, 2015 · 2 comments

Comments

@AnasOuahidi
Copy link

Hi,

I'm new with symfony, and i have a problem with the framework, I'm using the LexikJWTAuthenticationBundle with the fosuserbundle, and when I try to get the token via the curl -X POST curl -X POST http://test2.local/api/login_check -d _username=anas -d _password=anas or when I try to login via the form I get this json :

{"code":401,"message":"Bad credentials"}

When it works good with the fosuserbundle alone but when i added the LexikJWTAuthenticationBundle, it returns the 401 code.

I think it's due to some bad configuration in my config file so here is my config file:

app/config/config.yml

fos_user:
db_driver: orm # other valid values are 'mongodb', 'couchdb' and 'propel'
firewall_name: api
user_class: StageOCP\UserBundle\Entity\User
registration:
form:
type: acme_user_registration
confirmation:
from_email:
address: ---
sender_name: ---
enabled: true
resetting:
email:
from_email: # Use this node only if you don't want the global email address for the resetting email
address: ---
sender_name: ---
service:
mailer: fos_user.mailer.twig_swift

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%

and here is my routing file:

app/config/routing.yml

fos_user:
resource: "@FOSUserBundle/Resources/config/routing/all.xml"

fos_user_security_check:
path: /api/login_check
defaults: { _controller: FOSUserBundle:Security:check }

fos_js_routing:
resource: "@FOSJsRoutingBundle/Resources/config/routing/routing.xml"

api_login_check:
path: /api/login_check

and here is my security file:

app/config/security.yml

security:
encoders:
FOS\UserBundle\Model\UserInterface: sha512

role_hierarchy:
    ROLE_ADMIN:       ROLE_USER
    ROLE_SUPER_ADMIN: ROLE_ADMIN

providers:
    fos_userbundle:
                id: fos_user.user_provider.username
    in_memory:
        memory: ~

firewalls:
    login:
        pattern:  ^/login|^/api/login
        provider:  fos_userbundle
        stateless: true
        anonymous: true
        form_login:
            login_path:               fos_user_security_login
            check_path:               fos_user_security_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
    api:
        pattern:   ^/api
        provider:  fos_userbundle
        stateless: true
        anonymous: true
        lexik_jwt:
            authorization_header:
                enabled: true
                prefix:  Bearer
            query_parameter:
                enabled: true
                name:    bearer
    dev:
        pattern: ^/(_(profiler|wdt)|css|images|js)/
        security: false

    main:
        pattern: ^/
        form_login:
            provider: fos_userbundle
            csrf_provider: security.csrf.token_manager # Use form.csrf_provider instead for Symfony <2.4
        logout:       true
        anonymous:    true
        remember_me:
            key:      "%secret%"
            lifetime: 31536000 # 365 jours en secondes

access_control:
    - { path: ^/api/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/api, roles: IS_AUTHENTICATED_FULLY }

and here is my vhost conf :

<VirtualHost *:80>
RewriteEngine On
RewriteCond %{HTTP:Authorization} ^(.)
RewriteRule .
- [e=HTTP_AUTHORIZATION:%1]
DocumentRoot "C:\wamp\www\Test2\web"
ServerName test2.local
ServerAlias test2.local
ErrorLog "logs/siteA.localhost-error.log"
CustomLog "logs/siteA.localhost-access.log" common
Alias /sf C:\wamp\www\Test2\lib\vendor\symfony\data\web\sf

@AnasOuahidi
Copy link
Author

Thanks for your help, and sorry that i have to bother you

@AnasOuahidi
Copy link
Author

it works now :) sorry for the trouble :/ i just send a bad request

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant