首页 新闻 会员 周边 捐助

dotnet core3.1 ocleot集成IdentityServer4 error:" Client has NOT been authenticated for /user and pipeline error set."

0
悬赏园豆:80 [已解决问题] 解决于 2020-09-25 14:04

最近在看腾飞大佬的asp.net core 微服务实战遇到了ocelot集成identity server4认证时一直给报错:

warn: Ocelot.Authentication.Middleware.AuthenticationMiddleware[0]
      requestId: 0HM2ME7808IH4:00000009, previousRequestId: no previous request id, message: Client has NOT been authenticated for /user and pipeline error set. Request for authenticated route /user by  was unauthenticated
warn: Ocelot.Responder.Middleware.ResponderMiddleware[0]
      requestId: 0HM2ME7808IH4:00000009, previousRequestId: no previous request id, message: Error Code: UnauthenticatedError Message: Request for authenticated route /user by  was unauthenticated errors found in ResponderMiddleware. Setting error response for request path:/user, request method: GET

一直不知道问题出来哪里,小弟请求园子里各位大佬给指点一下

首先给出错误:

项目结构如下:

【Gateway.API】中Ocelot.json配置如下:

{
  "Routes": [
    {
      "DownstreamPathTemplate": "/api/user",
      "DownstreamScheme": "http",
      "DownstreamHostAndPorts": [
        {
          "Host": "localhost",
          "Port": 5001
        }
      ],
      "UpstreamPathTemplate": "/user",
      "UpstreamHttpMethod": [ "Get" ],
      "AuthenticationOptions": {
        "AuthenticationProviderKey": "finbook",
        "AllowedScopes": []
      }
    }
  ],
  "GlobalConfiguration": {
    "BaseUrl": "http://localhost:5000"
  }
}

【Gateway.API】中Startup.cs配置如下:

PostMan 请求:

无敌土豆的主页 无敌土豆 | 初学一级 | 园豆:80
提问于:2020-09-12 01:06
< >
分享
最佳答案
0

identityServer4 最新版本的 需要配置APISCOPE,老版本 只需要配置APIResource即可。不知道你有没有配。
详细可见 is4 文档 Resource章节

收获园豆:50
gt1987 | 小虾三级 |园豆:1150 | 2020-09-14 09:18

确实,我没注意看最新的官方文档,谢谢老哥!
下面贴上官方最新文档及博客园上的最新配置Scope的正确姿势的文档
官方文档:https://identityserver4.readthedocs.io/en/latest/topics/resources.html
博客园:https://www.cnblogs.com/xhznl/p/13223964.html

下面贴上我最新配置方式:
Client,ApiResource,ApiScope配置方式如下方便大家参考:

无敌土豆 | 园豆:80 (初学一级) | 2020-09-25 13:56
其他回答(1)
0

在ASP.NET Core中使用Ocelot
https://www.52interview.com/book/20

收获园豆:30
楠木大叔 | 园豆:2083 (老鸟四级) | 2020-09-12 17:22

谢谢大佬给的文档,我对照您给的地址和ocelot最新文档对比了下,ocelot已经更新了关键代码

我猜测应该是我请求的时候哪里有问题,如果是配置有问题的话网关那个服务应该就不会启动起来我把授权部分代码去掉再次请求下游api/user 是可以请求成功的呢

支持(0) 反对(0) 无敌土豆 | 园豆:80 (初学一级) | 2020-09-12 18:13
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册