最近在看腾飞大佬的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 请求:
identityServer4 最新版本的 需要配置APISCOPE,老版本 只需要配置APIResource即可。不知道你有没有配。
详细可见 is4 文档 Resource章节
确实,我没注意看最新的官方文档,谢谢老哥!
下面贴上官方最新文档及博客园上的最新配置Scope的正确姿势的文档
官方文档:https://identityserver4.readthedocs.io/en/latest/topics/resources.html
博客园:https://www.cnblogs.com/xhznl/p/13223964.html
下面贴上我最新配置方式:
Client,ApiResource,ApiScope配置方式如下方便大家参考:
在ASP.NET Core中使用Ocelot
https://www.52interview.com/book/20
谢谢大佬给的文档,我对照您给的地址和ocelot最新文档对比了下,ocelot已经更新了关键代码
我猜测应该是我请求的时候哪里有问题,如果是配置有问题的话网关那个服务应该就不会启动起来我把授权部分代码去掉再次请求下游api/user 是可以请求成功的呢