I'm doing an ajax-request in Javascript to obtain a 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 is sent the right way 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","username":"demo","password":"123"}
Looks like you may have already solved it but, this is what did it for me. Using the above and setting body to this worked.
var body = {
grant_type: 'password',
username: credentials.name,
password: credentials.password
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With