Request a token using jQuery from the web API

I am making an ajax request in Javascript to get the JWT from my WebAPI AuthenticationProvider. This is my js function:

function authenticateUser(credentials) { var body = { grant_type: 'password', client_id: 'myClientId', client_secret: 'myClientSecret', username: credentials.name, password: credentials.password }; $.ajax({ url: 'http://localhost:9000/token', type: 'POST', dataType: 'json', contentType: 'application/x-www-form-urlencoded; charset=UTF-8', /* data: JSON.stringify(body), /* wrong */ data: body, /* right */ complete: function(result) { //called when complete alert(result); }, success: function(result) { //called when successful alert(result); }, error: function(result) { //called when there is an error alert(result); }, }); session.isAuthenticated(true); return true; } 

Although the content was sent correctly in my eyes, the OAuthValidateClientAuthenticationContext has only null values.

My form Data copied from the console:

{"grant_type": "password", "client_id": "myClientId", "client_secret": "myClientSecret", "name": "demo", "password": "123"}

+5
source share
1 answer

It looks like you may have already decided this, but this is what I did for me. Using the above and setting up the body for this worked.

 var body = { grant_type: 'password', username: credentials.name, password: credentials.password }; 
+2
source

All Articles