首页 > 其他分享 >Duende.IdentityServer

Duende.IdentityServer

时间:2024-10-17 16:01:33浏览次数:1  
标签:package new IdentityResources IdentityServer Duende options oidc

服务端安装 install-package Duende.IdentityServer

客户端 install-package IdentityModel

webapi  基于jwt 需要安装 install-package Microsoft.AspNetCore.Authentication.JwtBearer

 

在 IdentityServer 中启用OIDC需要

  • 交互式用户界面 dotnet new isui
  • OIDC范围的配置

    public static IEnumerable<IdentityResource> IdentityResources => new IdentityResource[]
    {
    // 创建一个IdentityResources.OpenId类型的IdentityResource对象
    new IdentityResources.OpenId(),
    // 创建一个IdentityResources.Profile类型的IdentityResource对象
    new IdentityResources.Profile(),
    };

  • OIDC客户端的配置

    new Client
    {
    ClientId = "web",
    ClientSecrets = {new Secret("secret".Sha256())},
    AllowedGrantTypes = GrantTypes.Code,
    RedirectUris = { "https://localhost:5002/signin-oidc" },
    PostLogoutRedirectUris = { "https://localhost:5002/signout-callback-oidc" },
    AllowedScopes = new List<string>
    {
    IdentityServerConstants.StandardScopes.OpenId,
    IdentityServerConstants.StandardScopes.Profile
    }
    }

  • 要登录的用户

    public static List<TestUser> TestUsers => new List<TestUser>
    {
    // 创建一个TestUser对象,并设置其属性
    new TestUser
    {
    SubjectId = "1", // 设置SubjectId属性为"1"
    Username = "admin", // 设置Username属性为"admin"
    Password = "123456" // 设置Password属性为"123456"
    }
    };

创建OIDC客户端

dotnet add package Microsoft.AspNetCore.Authentication.OpenIdConnect

配置身份验证服务

builder.Services.AddAuthentication(options =>
{
options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = "oidc";
}).AddCookie(CookieAuthenticationDefaults.AuthenticationScheme)
.AddOpenIdConnect("oidc", options =>
{
options.Authority = "https://localhost:5001";
options.ClientId = "web";
options.ClientSecret = "secret";
options.ResponseType = "code";
options.Scope.Clear();
options.Scope.Add("openid");
options.Scope.Add("profile");
options.MapInboundClaims = false;
options.SaveTokens = true;
});

 

标签:package,new,IdentityResources,IdentityServer,Duende,options,oidc
From: https://www.cnblogs.com/yangchaonet/p/18472489

相关文章

  • IdentityServer4取消使用HTTPS问题
    //Copyright(c)BrockAllen&DominickBaier.Allrightsreserved.//LicensedundertheApacheLicense,Version2.0.SeeLICENSEintheprojectrootforlicenseinformation.usingIdentityModel.Client;usingNewtonsoft.Json.Linq;usingSystem;usin......
  • 在IdentityServer4生成的JWT中添加一个自定义的Claim,用于ABP框架中要用到的token信息
    用过IdentityServer4或者熟悉ASP.NETCore认证的都应该知道有Claim,如何理解ids4中的Claim?这里可以理解为声明,我们每个用户都有多个Claim,每个Claim声明了用户的某个信息比如:Role=Admin,UserID=1000等等,这里Role,UserID每个都是用户的Claim,都是表示用户信息的单元 ,我们不妨把它称为......
  • Java SpringBoot 如何使用 IdentityServer4 作为验证服务器学习笔记
    作者:https://www.cnblogs.com/BeautifulBoy1301/p/11193488.html https://github.com/Danni-Ke/SpringBootDemo  JavaSpringBoot如何使用IdentityServer4作为验证服务器学习笔记 这边记录下如何使用IdentityServer4作为JavaSpringBoot的认证服务器和令牌颁......
  • identityserver4使用
    参考网站https://blog.csdn.net/weixin_43847283/article/details/125708613请求路径请求参数client_id:simple_clientclient_secret:simple_client_secretgrant_type:client_credentials源码https://pan.baidu.com/s/1aWXzzl2fJ9ZeqAdXQfRCBA提取码:r6ef......
  • Net8微服务之Consul、Ocelot、IdentityServer4
    前言情绪的尽头是沉默1.微服务概念1.1微服务发展分布式解决性能问题,微服务解决维护性、扩展性、灵活性。1.2微服务概念微服务(或称微服务架构),是一种现代化的软件架构方法,它将一个应用程序分解为多个小型、独立的服务单元,每个服务都负责特定的业务功能,并且可以独立开发、测......
  • NetCore Identityserver4 客户端配置
    1.客户端模式varclient=newHttpClient();varresponse=client.RequestClientCredentialsTokenAsync(newClientCredentialsTokenRequest{Address="http://localhost:5000/connect/token",......
  • Scope api1 not found in store. IdentityServer4.Validation.TokenRequestValidator:
    看明白了这个报错,说是scopeapi在授权服务器没有定义,但是一直不知道哪出错,我寻思也定义了这个资源来着但其实并没有,说的是scope不是说的resource,所以需要再定义一个Scope  ......
  • identityserver4 刷新token接口返回空
    如题,查看日志发现错误信息:Nosigningcredentialforalgorithms(rs256)registered而客户端的配置里的“身份令牌算法”没有rs256于是加上就ok了。 ......
  • IdentityServer4: 配置项持久化
    IdentityServer4:配置项持久化  目录IdentityServer4配置项持久化创建IdentityServer4项目添加依赖包添加QuickstartUI数据库迁移ConfigurationDbContextPersistedGrantDbContext查看迁移结果生成初始化数据严重BUG集成IdentityServer4......
  • IdentityServer4: 使用固定证书
    IdentityServer4:使用固定证书  目录固定证书简介生产环境生成证书下载OpenSSL工具设置环境变量生成KEY合并成.pfx文件使用证书配置证书加载证书验证AccessToken 固定证书本节可基于 IdentityServer4:配置项持久化 一节的代码基础......