Angular 4无法使用IdentityServer4进行身份验证

时间:2017-07-27 09:18:38

标签: angular identityserver4

尝试使用IdentityServer4授权类型ResourceOwnerPassword对用户进行身份验证。

我的应用程序与Angular SPA Web API - Explanation非常相似。问题是 - 每当我向POST发出http://localhost:49950/connect/token请求请求令牌时,我都会得到400 Bad Request

在IdentityServer4日志中,我看到:

请求启动HTTP / 1.1 POST http://localhost:49950/connect/token application / x-www-form-urlencode 166 Microsoft.AspNetCore.Hosting.Internal.WebHost:信息:请求启动HTTP / 1.1 POST http://localhost:49950/connect/token application / x-www-form-urlencode 166

...

...

对路径的CORS请求:来自原点的/ connect / token:http://localhost:5000

...

选中客户列表并且来源:http://localhost:5000是允许的

...

CorsPolicyService允许来源:http://localhost:5000

...

请求路径/连接/令牌与端点类型令牌匹配

...

为端点找到的映射:令牌,创建处理程序:IdentityServer4.Endpoints.TokenEndpoint

...

调用IdentityServer端点:/ connect / token的IdentityServer4.Endpoints.TokenEndpoint

...

令牌端点的HTTP请求无效

IdentityServer4.Endpoints.TokenEndpoint:警告:令牌端点的HTTP请求无效 应用程序见解遥测(未配置):{“name”:“Microsoft.ApplicationInsights.Dev.Message”,“time”:“2017-07-27T09:05:22.8471704Z”,“tags”:{“ai.operation.id “:” 0HL6KPQE44JVG “ ”ai.cloud.roleInstance“: ”XE0806001077“, ”ai.internal.sdkVersion“: ”aspnet5c:2.0.0“, ”ai.application.ver“: ”1.0.0.0“,” 艾.operation.name“:”POST /connect/token","ai.internal.nodeName":"XE0806001077","ai.location.ip":"::1"},"data":{"baseType“: “MessageData”,“baseData”:{“ver”:2,“message”:“调用结果:IdentityServer4.Endpoints.Results.TokenErrorResult”,“severityLevel”:“详细”,“属性”:{“DeveloperMode”:“ true“,”{OriginalFormat}“:”调用结果:{type}“,”AspNetCoreEnvironment“:”Development“,”CategoryName“:”IdentityServer4.Hosting.IdentityServerMiddleware“,”type“:”IdentityServer4.Endpoints.Results.TokenErrorResult “}}}}

这是什么意思令牌端点的HTTP请求无效

这是一个POST请求:

POST /connect/token HTTP/1.1
Host: localhost:49950
Connection: keep-alive
Content-Length: 166
Pragma: no-cache
Cache-Control: no-cache
Authorization: Basic YWxleDp0ZXN0UGFzc3dvcmQ=
Origin: http://localhost:5000
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36
Content-Type: application/x-www-form-urlencode
Accept: application/json, text/plain, */*
Referer: http://localhost:5000/dashboard
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.8,he;q=0.6,ru;q=0.4

我应该在ASP Core上的Angular端或IdentityServer4上更改哪些内容以允许令牌请求? 注意:Postman在请求body中使用相同的用户详细信息正确地工作 - 我在Angular中做的同样的事情但得到Invalid HTTP request for token endpoint :(

1 个答案:

答案 0 :(得分:1)

您所显示的请求没有任何内容。有人被送了吗?

ROPC请求应如下所示:

>> Y(2,3,1,2,sub{1}(2,3,1,2),sub{2}(2,3,1,2),sub{3}(2,3,1,2))
ans =
    0.9011

POST /connect/token HTTP/1.1 Host: localhost:49950 Authorization: Basic czZCaGRSa3F0MzpnWDFmQmF0M2JW Content-Type: application/x-www-form-urlencoded grant_type=password&username=johndoe&password=A3ddj3w 标头是您的客户端凭据(客户端ID和密码),而不是用户的用户名&密码