bookmarker bookmarker - 25 days ago 6
Javascript Question

IdentityServer3 ResourceOwner Angular request returns 400 Bad request

I have an identityServer3 example application.

public static IEnumerable<Client> GetClients()
{
return new[]
{
new Client
{
Enabled = true,
ClientId = "manager",
ClientName = "ManagerIdentity",
Flow = Flows.ResourceOwner,
ClientSecrets = new List<Secret>
{
new Secret("secret".Sha256())
},
AllowedScopes = new List<string>
{
Constants.StandardScopes.OpenId
},
AllowAccessTokensViaBrowser = true,
AllowedCorsOrigins = new List<string>{
"http://localhost:24678/" // angular application uri
}
}
}


I am using this informations and request by Postman and token returns.

enter image description here

But I send same request via angularjs javascript application it returns 400 bad request.

angular.module("app").controller("ROPCController", [
"$scope","$http",
function($scope,$http) {

$scope.login = function() {


var options = {
"url": "http://localhost:4751/connect/token",
"method": "POST",
"data": {
"username": "muser",
"password": "password",
"grant_type": "password",
"client_id": "manager",
"client_secret": "secret",
"scope":"openid"
},
"headers": {
"Content-Type": "application/x-www-form-urlencoded"
}
};

$http(options).then(
function(response) {
console.log(response.data);
},
function(error) {
console.log(error);
}
);
}
}
]);



{"error":"invalid_client"}

Answer

Your data is in json format so your should change the content-type to application/json or change the format of your data to username=muser&password=password&...

Hope this helps.