首页 文章

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

提问于
浏览
1

尝试使用带有 ResourceOwnerPassword grant类型的 IdentityServer4 对用户进行身份验证 .

我的应用程序看起来非常类似于Angular SPA Web API - Explanation . 问题是 - 每当我向 http://localhost:49950/connect/token 发出 POST 请求令牌时,我都会得到一个 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

...

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

...

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

...

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

...

Invalid HTTP request for token endpoint

IdentityServer4.Endpoints.TokenEndpoint:警告:令牌 endpoints 的无效HTTP请求Application Insights遥测(未配置):{“name”:“Microsoft.ApplicationInsights.Dev.Message”,“time”:“2017-07-27T09:05:22.8471704 Z “ ”标签“:{ ”ai.operation.id“: ”0HL6KPQE44JVG“, ”ai.cloud.roleInstance“: ”XE0806001077“, ”ai.internal.sdkVersion“: ”aspnet5c:2.0.0“,” AI .application.ver“:”1.0.0.0“,”ai.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”,“”:“调用结果:”,“AspNetCoreEnvironment”:“开发”,“CategoryName”:“IdentityServer4.Hosting.IdentityServerMiddleware ”, “类型”: “IdentityServer4.Endpoints.Results.TokenErrorResult”}}}}

Invalid HTTP request for token endpoint 是什么意思?

这是一个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

    你所展示的请求没有任何内容 . 有人被送了吗?

    ROPC请求应如下所示:

    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
    

    Authorization 标头是您的客户端凭据(客户端ID和密码),而不是用户的用户名和密码

相关问题