在上一篇中配置一个基础的idrserver服务端

这篇文章将对服务端做一些变化,这里我先贴一下上一章中的代码

证书:

  static class Certificate
{
public static X509Certificate2 Get()
{
var assembly = typeof(Certificate).Assembly;
using (var stream = assembly.GetManifestResourceStream("OAuthWeb.IdrConfig.idsrv3test.pfx"))
{
return new X509Certificate2(ReadStream(stream), "idsrv3test");
}
} private static byte[] ReadStream(Stream input)
{
byte[] buffer = new byte[ * ];
using (MemoryStream ms = new MemoryStream())
{
int read;
while ((read = input.Read(buffer, , buffer.Length)) > )
{
ms.Write(buffer, , read);
}
return ms.ToArray();
}
}
}

Clients:

 public class Clients
{
public static IEnumerable<Client> Get()
{
return new[]
{
//js客户端
new Client
{
Enabled = true,
ClientName = "JS Client",
ClientId = "js",
Flow = Flows.Implicit, RedirectUris = new List<string>
{
"http://192.168.0.42:44319/Home/Contact"
}, AllowedCorsOrigins = new List<string>
{
"http://localhost:20241"
}, AllowAccessToAllScopes = true
},
//客户端模式(client credentials)
new Client
{
ClientName = "Silicon-only Client",
ClientId = "silicon",
Enabled = true,
AccessTokenType = AccessTokenType.Reference, Flow = Flows.ClientCredentials, ClientSecrets = new List<Secret>
{
new Secret("F621F470-9731-4A25-80EF-67A6F7C5F4B8".Sha256())
}, //指明该注册client允许的scopes
AllowedScopes = new List<string>
{
"api1"
}
},
//密码模式(resource owner password credentials)
new Client
{
ClientName = "Silicon on behalf of Carbon Client",
ClientId = "carbon",
Enabled = true,
AccessTokenType = AccessTokenType.Reference, Flow = Flows.ResourceOwner, ClientSecrets = new List<Secret>
{
new Secret("21B5F798-BE55-42BC-8AA8-0025B903DC3B".Sha256())
}, AllowedScopes = new List<string>
{
"api1"
}
},
//简化模式(implicit)
new Client
{
Enabled = true,
ClientName = "SSO",
ClientId = "mvc",
Flow = Flows.Implicit,
RequireConsent=false,
ClientSecrets=new List<Secret> {
new Secret("21B5F798-BE55-42BC-8AA8-0025B903DC3B".Sha256())
}, AllowedScopes = new List<string> {
Constants.StandardScopes.OpenId,
Constants.StandardScopes.Profile
}
} };
}
}

Scopes:

 public class Scopes
{
public static List<Scope> Get()
{
return new List<Scope>
{
IdentityServer3.Core.Models.StandardScopes.OpenId,
IdentityServer3.Core.Models.StandardScopes.Profile, //注册一个新的scope,在注册client时会指明只允许这个api1的scope,客户端在请求token的时候会指明申请的scope
new Scope
{
Name = "api1"
}
};
}
}

users:

 public class Users
{
public static List<InMemoryUser> Get()
{
return new List<InMemoryUser>
{
new InMemoryUser
{
Username = "bob",
Password = "secret",
Subject = "", Claims = new[]
{
new Claim(Constants.ClaimTypes.GivenName, "Bob"),
new Claim(Constants.ClaimTypes.FamilyName, "Smith"),
new Claim(Constants.ClaimTypes.Email, "bob.smith@email.com")
}
},
new InMemoryUser
{
Username = "alice",
Password = "secret",
Subject = ""
}
};
}
}

结合上一章节贴了一些代码,代码中略有删减

有了这个idrserver 怎么来做自己的SSO呢?

如我有一个网站A   需要IdrServer提供认证, 现在涉及到了OpenID

新建一个站点A 添加nuget包

Microsoft.Owin.Security.Cookies;
Microsoft.Owin.Security.OpenIdConnect;

Microsoft.Owin.Host.SystemWeb;

 app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = "Cookies",
});
app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions
{
Authority = "http://192.168.0.42:10011/lym", //这里写你idrserver的地址
ClientId = "mvc", //Client 要对应
Scope = "openid profile",//Client 要对应
RedirectUri = "http://192.168.0.42:44319/", //登陆成功后的跳转地址,要对应
PostLogoutRedirectUri = "http://192.168.0.42:44319/", //如上
ClientSecret = "21B5F798-BE55-42BC-8AA8-0025B903DC3B",
ResponseType = "id_token token", //参考配置说明 还有授权码 code
SignInAsAuthenticationType = "Cookies"
});

访问站点A 就会转到SSO登陆页面如下图:

我这里自己定义的登陆界面,可以修改成自己的样式,风格,能看到登陆界面 说明这一步成功了,下一篇文章将介绍自定义登陆页面的操作

一步一步学习IdentityServer3 (3)的更多相关文章

  1. 一步一步学习IdentityServer3 (1)

    学习之初: IdentityServer3我自己最开始了解到的就是做一个SSO单点登录,后面发现还有单独的认证服务功能,其实它还可以做APIs的访问控制,资源授权,另外还可以为提供第三方登录,其他的自 ...

  2. 一步一步学习IdentityServer3 (2)

    下面就来做一个例子:IdentityServer3服务端的配置 VS2015创建一个MVC项目 IdrOAuth 用来授权的认证的站点

  3. 一步一步学习IdentityServer3 (4)

    其实上述例子 很多都很找到 但是在实际生态环境中给例子有很多不一样的地方 比如自定已登录界面怎么做? 怎么访问自己的用户数据库实现登录? 怎么在接口中使用,在接口中又怎么实现与Idr3结合授权? 等等 ...

  4. 12.Linux软件安装 (一步一步学习大数据系列之 Linux)

    1.如何上传安装包到服务器 有三种方式: 1.1使用图形化工具,如: filezilla 如何使用FileZilla上传和下载文件 1.2使用 sftp 工具: 在 windows下使用CRT 软件 ...

  5. (转) 一步一步学习ASP.NET 5 (四)- ASP.NET MVC 6四大特性

    转发:微软MVP 卢建晖 的文章,希望对大家有帮助.原文:http://blog.csdn.net/kinfey/article/details/44459625 编者语 : 昨晚写好的文章居然csd ...

  6. (转) 一步一步学习ASP.NET 5 (二)- 通过命令行和sublime创建项目

    转发:微软MVP 卢建晖 的文章,希望对大家有帮助. 注:昨天转发之后很多朋友指出了vNext的命名问题,原文作者已经做出了修改,后面的标题都适用 asp.net 5这个名称. 编者语 : 昨天发了第 ...

  7. 一步一步学习SignalR进行实时通信_1_简单介绍

    一步一步学习SignalR进行实时通信\_1_简单介绍 SignalR 一步一步学习SignalR进行实时通信_1_简单介绍 前言 SignalR介绍 支持的平台 相关说明 OWIN 结束语 参考文献 ...

  8. 一步一步学习SignalR进行实时通信_8_案例2

    原文:一步一步学习SignalR进行实时通信_8_案例2 一步一步学习SignalR进行实时通信\_8_案例2 SignalR 一步一步学习SignalR进行实时通信_8_案例2 前言 配置Hub 建 ...

  9. 一步一步学习SignalR进行实时通信_9_托管在非Web应用程序

    原文:一步一步学习SignalR进行实时通信_9_托管在非Web应用程序 一步一步学习SignalR进行实时通信\_9_托管在非Web应用程序 一步一步学习SignalR进行实时通信_9_托管在非We ...

  10. 一步一步学习SignalR进行实时通信_7_非代理

    原文:一步一步学习SignalR进行实时通信_7_非代理 一步一步学习SignalR进行实时通信\_7_非代理 SignalR 一步一步学习SignalR进行实时通信_7_非代理 前言 代理与非代理 ...

随机推荐

  1. C#小技巧

    1.将字符串转换成大写ToUpper string a="zxc"; a.ToUpper()  输出结果ZXC; a.ToUpper().Contains("Z" ...

  2. Hello 2019 自闭记

    A:8min才过??? #include<iostream> #include<cstdio> #include<cmath> #include<cstdli ...

  3. BZOJ2753 SCOI2012滑雪与时间胶囊(最小生成树)

    首先显然可以把所有能到的点拎出来建个新图,这样第一问也就做好了. 剩下的部分似乎是一个裸的最小树形图.但显然这个东西是没什么学的必要的并且不太能跑过去. 考虑建出来的图有什么性质.可以发现如果没有高度 ...

  4. python--inspect模块

    inspect模块主要提供了四种用处: 1.对是否是模块.框架.函数进行类型检查 2.获取源码 3.获取类或者函数的参数信息 4.解析堆栈 一.type and members 1. inspect. ...

  5. css 2D转换总结

    CSS中2D转换的形式是这样的: 选择器{ transform:转换函数(参数,参数): } 其中transform(是transform 不是transfrom)定义元素的2D或者3D转换: 2D转 ...

  6. 【uoj228】 基础数据结构练习题

    http://uoj.ac/problem/228 (题目链接) 题意 给出一个序列,维护区间加法,区间开根,区间求和 Solution 线段树.考虑区间开根怎么做.当区间的最大值与最小值相等时,我们 ...

  7. DynamicSegmentTree

    最近尝试了一下动态开点线段树,英文直译就是Dynamic Open Point Segment Tree,太SB了. 就跟之前的主席树写法差不多. if(!x || x == y) { x = ++t ...

  8. 人生效率手册:如何卓有成效地过好每一天--By张萌姐姐--读书笔记

    读书笔记:<人生效率手册>:如何卓有成效地过好每一天--By张萌姐姐... 整本书看完的感受: 这本书主要讲的是生活中我们需要给自己一个目标,然后通过自己的努力去实现这个目标,书中说的很多 ...

  9. 在CentOS上导出JVM内存信息

    首先看下Tomcat的进程Id: [root@iZ25Z ~]# ps aux | grep java www 2111 4.0 23.5 1637648 452756 ? Sl 10:12 4:35 ...

  10. html5 canvas在线文本第二步设置(字体边框)等我全部写完,我会写在页面底部

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...