网络营销教程,同桌的你mp3下载,河南豫剧抬花轿
添加用户
添加测试用户,也可以从数据库查
public static list<testuser> gettestuser() { return new list<testuser>() { new testuser(){ subjectid = "1", username ="zps", password = "zps", claims = new list<claim>(){ new claim("role","zps"), new claim("aaa","asdasdsd"), } }, new testuser(){ subjectid = "2", username ="admin", password = "admin", claims = new list<claim>(){ new claim("role","admin") } } }; }
添加api资源
添加api资源 ,api的key要和注册的client的api要匹配
public static ienumerable<apiresource> getresource() { return new list<apiresource>(){ new apiresource("api","my api") }; }
添加客户端
授权码模式和mvc模式的时候 这两个模式先不管
//请求确认
requireconsent = false, 这个属性要注意 如果是true 会先跳转到确认页面 然后再跳转到redirecturis
public static ienumerable<client> getclients() { return new list<client>(){ new client(){ clientid="client", //客户端模式 allowedgranttypes=granttypes.clientcredentials, clientsecrets={new secret("secret".sha256())}, allowedscopes={"api"} }, new client(){ clientid="pwdclient", //oauth密码模式 allowedgranttypes=granttypes.resourceownerpassword, clientsecrets={new secret("secret".sha256())}, allowedscopes={"api"} }, new client { clientid = "mvc", clientname = "mvc client", allowedgranttypes = granttypes.hybrid, clientsecrets = { new secret("secret".sha256()) }, // where to redirect to after login redirecturis = { "http://localhost:5001/signin-oidc" }, requireconsent = false, allowofflineaccess = true, // where to redirect to after logout postlogoutredirecturis = { "http://localhost:5001/signout-callback-oidc" }, allowedscopes = new list<string> { identityserverconstants.standardscopes.openid, identityserverconstants.standardscopes.profile, } }, new client { clientid = "js", clientname = "javascript client", allowedgranttypes = granttypes.code, requirepkce = true, requireclientsecret = false, redirecturis = { "http://localhost:5003/callback.html" }, postlogoutredirecturis = { "http://localhost:5003/" }, allowedcorsorigins = { "http://localhost:5003" }, requireconsent = false, allowedscopes = { identityserverconstants.standardscopes.openid, identityserverconstants.standardscopes.profile, "api" } } }; }
添加identityserver 保护的资源
可以自定义claim
public static ienumerable<identityresource> getidentityresources() { return new identityresource[] { new identityresources.openid(), new identityresources.profile(), }; }
把identityserver注入到容器
.adddevelopersigningcredential() 生成token 需要的密钥和公钥 正式环境需要换成正经的
o.userinteraction.loginurl = "/auth/login";
o.userinteraction.logouturl = "/auth/logout";
o.userinteraction.errorurl = "/auth/error";
这三个是混合模式需要的 登录的地址 登出的地址 授权失败的地址
services.addidentityserver(o => { o.userinteraction.loginurl = "/auth/login"; o.userinteraction.logouturl = "/auth/logout"; o.userinteraction.errorurl = "/auth/error"; }) .addinmemoryidentityresources(config.getidentityresources()) .adddevelopersigningcredential() .addinmemoryclients(config.getclients()) .addinmemoryapiresources(config.getresource()) .addtestusers(config.gettestuser());
configure把中间件加到netcore中
app.useidentityserver();
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
Blazor server side 自家的一些开源的, 实用型项目的进度之 CEF客户端
.NET IoC模式依赖反转(DIP)、控制反转(Ioc)、依赖注入(DI)
vue+.netcore可支持业务代码扩展的开发框架 VOL.Vue 2.0版本发布
网友评论