AspNetCore OpenId
1 Server端
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
} public IConfiguration Configuration { get; } // This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddIdentityServer()
.AddDeveloperSigningCredential()
.AddInMemoryClients(Config.GetClients())
.AddInMemoryApiResources(Config.GetResource())
.AddInMemoryIdentityResources(Config.GetIdentityResource())
.AddTestUsers(Config.GetUsers()); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
} // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseIdentityServer();
app.UseMvcWithDefaultRoute();
}
} public class Config
{
public static List<ApiResource> GetResource()
{
return new List<ApiResource>
{
new ApiResource("api1","Api Application "),
};
}
public static List<IdentityResource> GetIdentityResource()
{
return new List<IdentityResource>
{
new IdentityResources.OpenId(),
new IdentityResources.Profile(),
new IdentityResources.Email(),
};
}
public static List<Client> GetClients()
{
return new List<Client>
{
//客户端模式
//new Client{
// ClientId="client",
// AllowedGrantTypes = GrantTypes.ClientCredentials,
// ClientSecrets = {
// new Secret("secret".Sha256())
// },
// AllowedScopes={ "api"},
// }, ////密码模式
// new Client{
// ClientId="pwdclient",
// AllowedGrantTypes = GrantTypes.ResourceOwnerPassword,
// ClientSecrets = {
// new Secret("secret".Sha256())
// },
// AllowedScopes={ "api"},
// }, //隐式模式
new Client{
ClientId="mvc",
AllowedGrantTypes = GrantTypes.Implicit,
ClientSecrets = {
new Secret("secret".Sha256())
},
//是否需要用户点击按钮
RequireConsent=false,
RedirectUris={ "http://localhost:5003/signin-oidc"},
PostLogoutRedirectUris={ "http://localhost:5003/signout-callback-oidc"},
AllowedScopes={
IdentityServerConstants.StandardScopes.Profile,
IdentityServerConstants.StandardScopes.OpenId,
},
},
};
} public static List<TestUser> GetUsers()
{
return new List<TestUser>
{
new TestUser{SubjectId="10000",Username="yan",Password="123123" },
};
}
}
2 客户端
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
} public IConfiguration Configuration { get; } // This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddAuthentication(option =>
{
option.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
option.DefaultChallengeScheme = "oidc";
})
.AddCookie(CookieAuthenticationDefaults.AuthenticationScheme)
.AddOpenIdConnect("oidc", options =>
{
options.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.Authority = "http://localhost:5000";
options.RequireHttpsMetadata = false;
options.ClientId = "mvc";
options.ClientSecret = "secret";
options.SaveTokens = true;
});
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
} // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
}
app.UseStaticFiles();
app.UseAuthentication();
app.UseMvcWithDefaultRoute();
}
}
3 客户端加Authorize标记
AspNetCore OpenId的更多相关文章
- IdentityServer4 使用OpenID Connect添加用户身份验证
使用IdentityServer4 实现OpenID Connect服务端,添加用户身份验证.客户端调用,实现授权. IdentityServer4 目前已更新至1.0 版,在之前的文章中有所介绍.I ...
- IdentityServer4 简单使用,包括api访问控制,openid的授权登录,js访问
写在前面 先分享一首数摇:http://music.163.com/m/song?id=36089751&userid=52749763 其次是:对于identityServer理解并不是特别 ...
- IdentityServer4 实现 OpenID Connect 和 OAuth 2.0
关于 OAuth 2.0 的相关内容,点击查看:ASP.NET WebApi OWIN 实现 OAuth 2.0 OpenID 是一个去中心化的网上身份认证系统.对于支持 OpenID 的网站,用户不 ...
- ASP.NET Core 认证与授权[3]:OAuth & OpenID Connect认证
在上一章中,我们了解到,Cookie认证是一种本地认证方式,通常认证与授权都在同一个服务中,也可以使用Cookie共享的方式分开部署,但局限性较大,而如今随着微服务的流行,更加偏向于将以前的单体应用拆 ...
- ASP.NET Core的身份认证框架IdentityServer4(9)-使用OpenID Connect添加用户认证
OpenID Connect OpenID Connect 1.0是OAuth 2.0协议之上的一个简单的身份层. 它允许客户端基于授权服务器执行的身份验证来验证最终用户的身份,以及以可互操作和类似R ...
- 【转载】IdentityServer4 使用OpenID Connect添加用户身份验证
使用IdentityServer4 实现OpenID Connect服务端,添加用户身份验证.客户端调用,实现授权. IdentityServer4 目前已更新至1.0 版,在之前的文章中有所介绍.I ...
- .NET Core IdentityServer4实战 第二章-OpenID Connect添加用户认证
内容:本文带大家使用IdentityServer4进行使用OpenID Connect添加用户认证 作者:zara(张子浩) 欢迎分享,但需在文章鲜明处留下原文地址. 在这一篇文章中我们希望使用Ope ...
- asp.net core系列 56 IS4使用OpenID Connect添加用户认证
一.概述 在前二篇中讲到了客户端授权的二种方式: GrantTypes.ClientCredentials凭据授权和GrantTypes.ResourceOwnerPassword密码授权,都是OAu ...
- [OIDC in Action] 3. 基于OIDC(OpenID Connect)的SSO(添加Github OAuth 2.0的支持)
在上上一篇基于OIDC的SSO的登录页面的截图中有出现QQ登录的地方.这个其实是通过扩展OIDC的OpenID Provider来实现的,OpenID Provider简称OP,OP是OIDC的一个很 ...
随机推荐
- 今日、本周、本月时间列表 python方法
def get_time(self): ''' @author : Cong @Email : 624420781@qq.com @描 述 : 生产时间列表 ''' # 生成本日时间列表 i = da ...
- C++builder Tokyo 调用com 不正确的变量类型
C++builder Tokyo 调用com 不正确的变量类型 tt.OleFunction("interface_call","MS01",&erro ...
- 在Linux机器上安装MySQL
在Linux机器上安装MySQL,仔细认真些就没有问题. CentOS 7下MySQL 5.7安装.配置与应用_数据库技术_Linux公社-Linux系统门户网站 搞不定的话,直接删掉这个MySQL, ...
- UI设计篇·入门篇·绘制简单自定义矩形图/设置按钮按下弹起颜色变化/设置图形旋转
Android的基本控件和图形有限,难以满足所有的实际需要和设计需求,好在Android给出了相对完善的图形绘制和自定义控件的API,利用这些API,可以基本满足设计的需求. 自定义图像和控件的方法: ...
- cxgrid主从表的从表数据小于主表总数的问题
当从表的数据移动需要和数据源记录同步时,会发生一现象:从表中设定的keyfield记录不连续,显示就会中断. 这样要设置从表的排序,按照主表的关联键在内存表里进行排序 indexFieldNames设 ...
- CountDownLatch原理及使用场景
CountDownLatch是通过一个计数器来实现的,计数器的初始值为线程的数量.每当一个线程完成了自己的任务后,计数器的值就会减1.当计数器值到达0时,它表示所有的线程已经完成了任务,然后在闭锁 上 ...
- js 监听手机端键盘弹出和收起事件
//这里区分不同系统,可以参考之前的文档记录 https://www.cnblogs.com/wind-wang/p/10737110.html const ua = typeof window == ...
- mybatis调用存储过程并且有多个返回output值
mapperxml配置 配置时需要注意 parameterMap在mybatis3.2.6版本已经不再用了,而是使用 parameterType <select id="callget ...
- Fragment传参
1. 封装基类 /** * Created by chenhaibin * Time 18/1/20 * Email chenhaibin415@163.com * Description:封装代码的 ...
- EOS
1.移植性特别差,例如用Eclipse,idea,等其他集成工具开发之后的项目,难以快速的搭建到EOS集成工具中(例如逻辑流,数据结构等)2.项目框架的局限性大,底层封装的框架或者组件迭代性较差,很难 ...