IdentityServer-Setup and Overview
2017-06-06 13:38
169 查看
设置和概述
有两种方式创建一个IdentityServer 项目:从零开始
使用Visual Studio的ASP.NET Identity模板
如果是从零开始,我们提供一序列的帮助及内存存储,所以一开始不需要担心持久化问题。
如果是从ASP.NET Identity开始, 我们提供很方便的集成.
快速入门为各种identityserver使用场景提供一步一步的说明. 从最基本的到复杂的场景 - 建议安装顺序来学习.
每个快速入门都有一个对应的解决方案 - 可以在 IdentityServer4.Samples 的 quickstarts 文件夹内找到对应的源码.
基本设置
截图显示的是使用Visual Studio - 但这不是必须的.创建一个IdentityServer快速入门
新建一个ASP.NET Core 项目.
选择 “Empty Web” 选项.
注意
IdentityServer 目前只支持 ASP.NET Core 1.1.
下一步, 添加 IdentityServer4 nuget 包:
也可以通过包管理控制台使用以下命令来添加依赖项:
“Install-Package IdentityServer4”
IdentityServer 使用通用的格式对ASP.NET Core host配置和添加服务. 在
ConfigureServices中将必要的服务配置和添加到依赖注入系统. 在
Configure 中将中间件添加到HTTP 管道.
修改
Startup.cs文件:
public class Startup { public void ConfigureServices(IServiceCollection services) { services.AddIdentityServer() .AddTemporarySigningCredential(); } public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory) { loggerFactory.AddConsole(LogLevel.Debug); app.UseDeveloperExceptionPage(); app.UseIdentityServer(); } }
AddIdentityServer在 DI中注册IdentityServer 服务. 同时注册了一个运行时内存存储. 这对应开发场景是很有用的. 在实际生产场景中需要一个类似数据库的可持久化机制. 更多信息参考 EntityFramework 快速入门.
AddTemporarySigningCredential扩展方法为每次启动创建一个临时的密钥. 同样是应用于开发, 需要在生产场景中替换成可持久化的. 更多信息参考 cryptography docs .
注意
IdentityServer 现在还不能启动. 事实上,如果启动, 会抛出服务缺失的异常. 我们将在下面的快速入门中添加这些服务.
修改hosting
Visual Studio 默认使用 IIS Express 来承载 web 项目. 这当然没问题, 但这样就不能再控制台看到实时日志输出了.不论是针对UI的“可见“错误消息还是返回给客户的模糊处理消息.IdentityServer 对日志进行了很方便的扩展.
推荐使用控制台来承载 IdentityServer . 可以在 Visual Studio 切换配置. 也可以不用每次运行 IdentityServer都打开浏览器 - 同样可以关闭:
当切换到自动宿主, 服务器默认端口是5000. 可以通过上图配置, 也可以在
Program.cs 中编码- 我们在快速入门中使用以下IdentityServer 宿主配置:
public class Program { public static void Main(string[] args) { Console.Title = "IdentityServer"; var host = new WebHostBuilder() .UseKestrel() .UseUrls("http://localhost:5000") .UseContentRoot(Directory.GetCurrentDirectory()) .UseIISIntegration() .UseStartup<Startup>() .Build(); host.Run(); } }
注意
建议在IIS Express 和self-hosting中使用相同的端口配置. 这样在两种方式切换的时候不需要改动客户端配置.
怎么运行快速入门
上面提到的每个快速入门都有一个对应的解决方案 - 可以在IdentityServer4.Samples 的quickstarts 文件夹中找到.最方便的方法是 右键选择解决方案属性并选择“启动项目”.设置启动项目为 “当前选定内容”:
先启动IdentityServer, 然后启动 API, 最后是 client. 只有在需要调试的时候启动F5调试. 其他情况使用 Ctrl+F5 是运行项目的最佳方式.
相关文章推荐
- Alternatives to @@IDENTITY in SQL Server 2000
- setup lamp server
- ArcGIS Server9.3打开Services Directory报错“Identity Error: Server could not authenticate the supplied identity“ (转)
- How to Insert Values into an Identity Column in SQL Server
- ASP.NET Core的身份认证框架IdentityServer4(5)- 包和构建
- Establishing SSL connection without server's identity verification is not recommended. According to
- Setup Git Server in CentOS 6.3
- .NET开源OpenID和OAuth解决方案Thinktecture IdentityServer
- ambari-server setup过程
- LINUX server common setup for ChinaCache ...
- ubuntu svn server setup
- Setup PXE Server
- Setup SQL Server 2008 Maintenance Plan Email Notifications
- IdentityServer Topics(5)- 使用第三方登录
- Setup VSFTPD Server with Virtual Users On CentOS, RHEL, Scientific Linux 6.5/6.4/6.3
- IdentityServer4 中文文档 -2- (简介)相关术语
- 利用ArcGIS API For Flex+ImageServer实现Identity影像服务的值
- Building a Jabber Client for iOS: Server Setup
- WARN: Establishing SSL connection without server's identity verification is not recommended.
- IdentityServer3——入门教程:.NET开源OpenID Connect 和OAuth解决方案IdentityServer v3 术语