高清电影免费下载,熟男有感,北京unihub公司
前言
oauth 2.0默认四种授权模式(granttype)
本章主要介绍简化模式(implicit)
,不通过第三方应用程序的服务器,直接在浏览器中向认证服务器申请令牌,跳过了"授权码"这个步骤,因此得名。所有步骤在浏览器中完成,令牌对访问者是可见的,且客户端不需要认证。
认证步骤
配置认证授权服务器
pm> install-package identityserver4 -version 2.5.3
创建一个类config(配置要保护的资源,和可以访问的api的客户端服务器)
public class config { /// <summary> /// 定义身份资源 /// </summary> /// <returns></returns> public static ienumerable<identityresource> getidentityresources() { return new list<identityresource> { new identityresources.openid(), new identityresources.profile(), new identityresources.email() }; } /// <summary> /// 定义授权客户端 /// </summary> /// <returns></returns> public static ienumerable<client> getclients() { return new list<client> { new client{ clientid="mvc", clientname="myclient", allowedgranttypes=granttypes.implicit, redirecturis = { "http://localhost:5003/signin-oidc" },//跳转登录到的客户端的地址 postlogoutredirecturis = { "http://localhost:5003/signout-callback-oidc" },//跳转登出到的客户端的地址 allowedscopes = new list<string> { identityserverconstants.standardscopes.openid, identityserverconstants.standardscopes.profile, identityserverconstants.standardscopes.email }, requireconsent=false } }; } }
再走到configureservices方法注入identityserver4服务
services.addidentityserver() .adddevelopersigningcredential() .addinmemoryidentityresources(config.getidentityresources()) .addinmemoryclients(config.getclients()) .addtestusers(testusers.users);
在configure方法中添加identityserver4服务中间件
app.useidentityserver();
新建客户端
再走到configureservices方法注入identityserver4服务
jwtsecuritytokenhandler.defaultinboundclaimtypemap.clear(); services.addauthentication(options => { options.defaultscheme = "cookies"; options.defaultchallengescheme = "oidc"; }) .addcookie("cookies") .addopenidconnect("oidc", options => { options.authority = "http://localhost:5004"; options.requirehttpsmetadata = false; options.clientid = "mvc"; options.savetokens = true; options.getclaimsfromuserinfoendpoint = true; });
在configure方法中添加认证服务中间件
app.useauthentication();
run
添加第三方快捷登录(github)
在授权服务器configureservices注入
直接贴代码吧
public void configureservices(iservicecollection services) { services.addmvc(); services.addidentityserver() .adddevelopersigningcredential() .addinmemoryidentityresources(config.getidentityresources()) .addinmemoryclients(config.getclients()) .addtestusers(testusers.users); services.addauthentication().addgithub(options => { options.signinscheme = identityserverconstants.externalcookieauthenticationscheme; options.clientid = "your client"; options.clientsecret = "your secret"; }); }
run
登录成功后可以获取到声明的claimsidentity
页面大家可以通过 https://github.com/identityserver/identityserver4.templates进行下载
,或者通过命令dotnet new -i identityserver4.templates
进行下载
github 可以到
注册完应用就会有应用编码和密钥了
概要
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
Blazor server side 自家的一些开源的, 实用型项目的进度之 CEF客户端
.NET IoC模式依赖反转(DIP)、控制反转(Ioc)、依赖注入(DI)
vue+.netcore可支持业务代码扩展的开发框架 VOL.Vue 2.0版本发布
网友评论