0

我有一个 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
                           }
                       }  
            }

我正在使用这些信息和邮递员的请求和令牌返回。

在此处输入图像描述

但我通过 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);
                }
            );
        }
    }
]);

{“错误”:“无效客户端”}

4

1 回答 1

0

您的数据是 json 格式,因此您应该将内容类型更改为application/json或将数据格式更改为username=muser&password=password&...

希望这可以帮助。

于 2016-11-15T09:13:09.337 回答