I'm working with symfont and JSON Web Token and Symfony.
I'm trying to get jwt with ajax, but I get 401 (Unauthorized) The problem is with ajax, because i try with postman and I can get the token.
here is my security.yaml
security:
encoders:
App\Entity\Users:
algorithm: bcrypt
providers:
users:
entity:
class: App\Entity\Users
property: email
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
login_app_manager:
pattern: ^/user/login
stateless: true
anonymous: true
provider: users
json_login:
check_path: /user/login
username_path: email
password_path: password
success_handler: lexik_jwt_authentication.handler.authentication_success
failure_handler: lexik_jwt_authentication.handler.authentication_failure
require_previous_session: false
app_api_manager:
pattern: ^/mngr/api
stateless: true
anonymous: false
provider: users
guard:
authenticators:
- lexik_jwt_authentication.jwt_token_authenticator
access_control:
- { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/register, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/api, roles: IS_AUTHENTICATED_FULLY }
here is my ajax
var data = {
'email':email,
'password':password
};
$.ajax({
type: "POST",
url: "/user/login",
contentType: "application/json",
data: JSON.stringify(data),
success: function(response) {
console.log(response);
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
console.log('Error : ' + errorThrown);
}
});
please help me, thank you
access_controlsection in path^/user/logininstead of ^/login