.net5 使用IdentityServer4和Ocelot 问题记录(.netcore2.1升级问题)

使用IdentityServer4和Ocelot 自己core2.1时以前框架搭建并正常配置后出现了几个出现的问题,花了一些时间查到记录下

问题1.invalid_client

检查自己的ClientId和ClientSecret的是否正确

问题2. ocelot服务任何接口都返回404 NotFound

正确配置如下:主要原因:注意: ocelot16.x版本之后的配置节点写为Routes,而非ReRoutes

问题3:请求identityserver4出现异常invalid_scope

IdentityServer4 4.x版本跟老版本有些区别,可能你的学习资料还是老的

.AddInMemoryApiScopes(Config.ApiScopes) //这个方法是新加的

 services.AddIdentityServer()
               .AddDeveloperSigningCredential()
               .AddInMemoryApiResources(Config.GetResource())
               .AddInMemoryClients(Config.GetClients())
               .AddInMemoryApiScopes(Config.ApiScopes) //这个方法是新加的
               .AddTestUsers(Config.GetTestUsers());`

问题4:accesstoken正常返回就是请求api或者ocelot 返回:Unauthorized

感谢:.Net Core WebApi(三)--使用 IdentityServer4 4.1.1 踩坑记录 - C余L小R鱼 - 博客园

在identityserver4配置ApiResources时, 以前的版本可以直接一个new ApiResource("invoice", "Invoice API"),但是新版本需要以组合scope组合配置  如下图

//调取时 将多个scope的Name加参时 可能会很长很长 为了方便 我们将scope 进行分组 后期可直接调用**统称** 这里分成两组
public static readonly IEnumerable<ApiResource> GetApiResources()
{
    return new List<ApiResource>
    {
        new ApiResource("invoice", "Invoice API")//设置每组scopes的统称
        {
            Scopes = { "invoice.read", "invoice.pay", "manage" }//设置每组scope具体名称
        },

        new ApiResource("customer", "Customer API")
        {
            Scopes = { "customer.read", "customer.contact", "manage" }
        }
    };
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值