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

news/2024/5/19 23:39:57 标签: .netcore, identityserver4, ocelot

使用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" }
        }
    };
}


http://www.niftyadmin.cn/n/791080.html

相关文章

C++ writestring 为什么不能写进中文 CStdioFile向无法向文本中写入中文【一】

以下代码文件以CStdioFile向无法向文本中写入中文&#xff08;用notepad.exe查看不到写入的中文&#xff09;CStdioFile file;file.Open(…);file.WriteString(_T("abc你好"));//只能写入abc解决办法&#xff1a;使用setlocale语句设定区域#include <locale>//…

GeckoWebBrowser 想使用jquery 但是目标网页没有加载jquery (Winfrom Gecko动态附加jqueryjs)

本人测试了3种方法&#xff0c;只有第三种有效&#xff08;间接append) 注&#xff1a;皆在Gecko_DocumentCompleted 中使用第一种(无效&#xff0c;直接报document is not defined) 估计是加载问题 try {using (AutoJSContext context new AutoJSContext(browser.Window.JSC…

Python标准库08 多线程与同步 (threading包)(转载)

Python标准库08 多线程与同步 (threading包) 作者&#xff1a;Vamei 出处&#xff1a;http://www.cnblogs.com/vamei 欢迎转载&#xff0c;也请保留这段声明。谢谢&#xff01; Python主要通过标准库中的threading包来实现多线程。在当今网络时代&#xff0c;每个服务器都会接收…

源码源码,你不要睡着啦。

都知道源码是好东西&#xff0c;一头扎进去往往容易淹死&#xff0c;楼主扔几个救生圈&#xff0c;剩下的看你们造化了。 问题&#xff1a; 1.为什么默认自定义View经常占满全屏&#xff08;无论是设置wrap_content还是match_parent&#xff09;&#xff1f; 2.为什么说view的…

JCheckBox使用示例

// 初始化 JCheckBox chknew JCheckBox("XXX");// 选择 chk.setSelected(true);// 判断选择状态 chk.isSelected() 转载于:https://www.cnblogs.com/xiandedanteng/p/3704062.html

SwipeRefreshLayout的用法

https://github.com/hanks-zyh/SwipeRefreshLayout

傅立叶变换在图像处理中的作用

傅立叶变换在图像处理中有非常非常的作用。因为不仅傅立叶分析涉及图像处理的很多方面&#xff0c;傅立叶的改进算法&#xff0c; 比如离散余弦变换&#xff0c;gabor与小波在图像处理中也有重要的分量。 印象中&#xff0c;傅立叶变换在图像处理以下几个话题都有重要作用&am…

Linux 进程管理工具 supervisord 安装及使用

Supervisor是用Python实现的一款非常实用的进程管理工具1、安装过程非常简单安装python安装meld3-0.6.8.tar.gz安装supervisor-3.0a12.tar.gz可参照:http://ydt619.blog.51cto.com/316163/10553342、配置supervisor# Web管理界面设定[inet_http_server]port0.0.0.0:9001usernam…