IdnetityServer4密码授予JavaScript 400错误请求

时间:2018-07-19 09:27:42

标签: identityserver4

我使用javascript发送请求:

        var settings = {
            method: "POST",
            url: tokenEndPoint.concat("/connect/token"),
            data: {
                username: "username",
                password: "password",
                grant_type: "password",
                client_id: "webui",
                client_secret: "32c8e1f3-594d-406a-8e33-644cfa7959c5",
                scope: "openid profile webui"
            },
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded'
            }
        };

        function onGetTokenSuccess(response) {
            return response.data;
        }

        function onGetTokenFailed(error) {
            logger.error('XHR Failed for token request.' + error);
        }

        $http(settings).then(onGetTokenSuccess).catch(onGetTokenFailed);

我的这个javascript请求给出了Http 400 Bad request错误。我的日志是这样的:

[12:20:22 Information] IdentityServer4.Hosting.IdentityServerMiddleware
Invoking IdentityServer endpoint: IdentityServer4.Endpoints.TokenEndpoint for /connect/token

[12:20:22 Information] IdentityServer4.Validation.TokenRequestValidator
User authentication failed: Invalid username or password.

但是此参数可以使用邮递员正常工作。

我的客户端设置在这里:

  {
    "Enabled": "true",
    "ClientId": "webui",
    "ClientName": "Web UI",
    "ClientSecrets": [
      {
        "Description": "32c8e1f3-594d-406a-8e33-644cfa7959c5",
        "Expiration": "",
        "Type": "SharedSecret",
        "Value": "Q3ADcd+nptsnMpvXvCMvquwFd8i26ImBsncNGg/UG/w="
      }
    ],
    "UserClaims": [
      "role"
    ],
    "AllowedGrantTypes": [
      "password"
    ],
    "AllowedScopes": [
      "openid",
      "profile",
      "webui"
    ]
  }  

0 个答案:

没有答案
相关问题