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的一个很 ...
随机推荐
- OO第十五次作业
一.测试与正确性论证的效果差异 测试和正确性论证分别是从理论和实践两个角度去规范程序的正确性的,我认为其主要的区别在于对于程序透明度的需求上, 测试作为一种实践手段,他的实施的要求是比较低的:在完全了 ...
- 【转】如何用Eclispe调试java -jar xxx.jar 方式执行的jar包
原文地址:https://www.cnblogs.com/zzpbuaa/p/5443269.html 有时候,我们经常会需要调试 java -jar xxx.jar方式运行的代码,而不是必须在Ecl ...
- 查询Oracle版本
服务器端 Oracle: 1)select* from v$version; 2)select * from product_component_version; 3)set serveroutput ...
- Python txt文件读取写入字典的方法(json、eval)
link:https://blog.csdn.net/li532331251/article/details/78203438 一.使用json转换方法 1.字典写入txt import json d ...
- Maven中聚合与集成的区别
如test-parent是一个聚合工程,打包方式为pom.xml test-a是test-parent的一个moudle模块,打包方式为jar,并且继承自test-parent: test-b是tes ...
- 基于WebGL架构的3D可视化平台—实现小车行走路线演示
小车行走路线演示New VS Old 刚接触ThingJS的时候,写的一个小车开进小区的演示,今天又看了教程中有movePath这个方法就重新写了一遍,其中也遇到了一些问题,尤其突出的问题就是小车过弯 ...
- Linux中 ./configure --prefix命令
源码的安装一般由3个步骤组成:配置(configure).编译(make).安装(make install),具体的安装方法一般作者都会给出文档,这里主要讨论配置(configure).Configu ...
- TOMCAT程序的层级目录
web | |---------js,jsp,html,css(资源文件在web根目录下面 可以被浏览器直接访问) |---------WEB-INF(配置文件web.xml lib---jar ...
- @ControllerAdvice详解
@ControllerAdvice,是Spring3.2提供的新注解,从名字上可以看出大体意思是控制器增强.让我们先看看@ControllerAdvice的实现: package org.spri ...
- python--第二十天总结(Django的一些注意)
关闭Django模板的自动转义 Django的模板中会对HTML标签和JS等语法标签进行自动转义,原因显而易见,这样是为了安全.但是有的时候我们可能不希望这些HTML元素 被转义,比如我们做一个内容管 ...