随笔分类 - IdentityServer
摘要:首先声明一下,我是按照下面的教程来进行操作的: .NET 6 集成 IdentityServer4+AspNetCore Identity 读取本地数据表用户 - 董川民 (dongchuanmin.com) 具体步骤记录如下: 一、新建空白项目 1、选择Asp.net Core Api项目,如下图
阅读全文
摘要:背景:前面尝试了用https的方式解决,但是需要有域名申请的证书,否则被他保护的api被别人调用时报错(没找到解决方法) 尝试:放弃https的方式,还用原来的http的方式,解决Correlation failed. Unknown location的问题,找到这个文章,asp.net core
阅读全文
摘要:1、添加apiresource[下面标红的那一行] public static IEnumerable<ApiResource> GetApis() { var apiClients = SysCore.ConfigHelper.GetSectionApiSites(); List<ApiResou
阅读全文
摘要:private readonly UserManager<IdentityUser> _userManager; private readonly RoleManager<IdentityRole> _roleManager; public HomeController(IIdentityServe
阅读全文
摘要:添加角色: public string AddRole(string roleName) { if (_roleManager.FindByNameAsync(roleName).Result == null) { var role = new IdentityRole { Name = roleN
阅读全文
摘要:服务器端配置: Client oneResult = new Client { ClientId = client.ClientId, ClientName = client.ClientName, AllowedGrantTypes = GrantTypes.ResourceOwnerPasswo
阅读全文
摘要:服务器端配置: Client oneResult = new Client { ClientId = "localHtml", ClientName = "test", AllowedGrantTypes = GrantTypes.ResourceOwnerPassword, ClientSecre
阅读全文
摘要:1、添加nuget引用 IdentityModel IdentityServer4.AccessTokenValidation Microsoft.AspNetCore.Authentication.Cookies Microsoft.AspNetCore.Authentication.OpenId
阅读全文
摘要:错误 NU1605: 检测到包降级: System.Runtime.InteropServices 从 4.3.0 降级到 4.1.0。直接从项目引用包以选择不同版本等 发布时出现了特别多类似于这样很奇怪的问题 结果更新了一下log4net的版本解决了,奇怪。
阅读全文
摘要:一、根据账号取出来当前用户的实体 var userMgr = scope.ServiceProvider.GetRequiredService<UserManager<ApplicationUser>>(); var userModel = userMgr.FindByNameAsync(accou
阅读全文
摘要:一、添加用户 public ReturnResult Add(JObject jo) { var returnResult = new ReturnResult(); string userId = jo.GetValue("Id").ToString(); string account = jo.
阅读全文
摘要:一、添加引用 1、添加owin引用 版本:1.0.0.02、添加 Microsoft.Owin.Security.Cookies 版本:4.1.0 3、添加System.IdentityModel.Tokens.Jwt 版本:5.6.04、添加Microsoft.Owin.Security.Open
阅读全文
摘要:dotnet应用用IdentityServer4做了登陆的功能,本地运行没有问题,部署到服务器上面就出现上面的问题,打开服务器的日志记录开关,获取到下面的异常信息。原来是 通过分析日志信息,发现报错的原因是因为IdentityServer4的加密签名导致的。 IS4中如果token的类型是JWT,则
阅读全文
摘要:续上篇 二、API资源端 1、新建项目 ApiReSource 用来存放需要被保护的API,如下图 2、引用nuget里的 IdentityServer4.AccessTokenValidation类库 3、新增一个Controller名叫 TestController 内容如下: 4、修改Star
阅读全文
摘要:目录 一、认证服务端 二、API资源端 三、调用客户端 详细步骤 一、认证服务端 1、新建一个名为“CertifiedCenter”的 asp.net core web应用程序,如下图 2、添加IdentityServer4的2个引用 IdentityServer4 和 IdentityServer
阅读全文
摘要:var httpClient = new HttpClient(); var disco = httpClient.GetDiscoveryDocumentAsync(new DiscoveryDocumentRequest { Address = "http://localhost:5000", Policy = { RequireHttps=false } }).Result; if (dis
阅读全文