简体   繁体   English

IdentityServer3 ResourceOwner Angular请求返回400错误请求

[英]IdentityServer3 ResourceOwner Angular request returns 400 Bad request

I have an identityServer3 example application. 我有一个identityServer3示例应用程序。

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. 我正在使用这些信息,并要求邮递员和代币退还。

在此处输入图片说明

But I send same request via angularjs javascript application it returns 400 bad request. 但是我通过angularjs javascript应用程序发送了相同的请求,它返回了400错误的请求。

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"} {“错误”:“ invalid_client”}

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&... 您的数据为json格式,因此您应将content-type更改为application/json或将数据的格式更改为username=muser&password=password&...

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM