Steps:

  • 1.新建一个ASP.NET Core Web项目,SigmalHex.IdentityServer;

  • 2.安装包

Install-Package IdentityServer4
  • 3.Startup中加入
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddIdentityServer()
.AddTemporarySigningCredential()
.AddInMemoryApiResources(Config.GetApiResources())
.AddInMemoryClients(Config.GetClients());
} public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(LogLevel.Debug);
app.UseDeveloperExceptionPage(); app.UseIdentityServer();
}
}
    • AddIdentityServer

      注册Identity Server 服务到DI系统。
    • AddTemporarySigningCredential

      每次启动的时候,生成一个临时的签名证书
  • 4.Config
using IdentityServer4.Models;
using System.Collections.Generic; namespace SigmalHex.IdentityServer
{
public class Config
{
// scopes define the API resources in your system
public static IEnumerable<ApiResource> GetApiResources()
{
return new List<ApiResource>
{
new ApiResource("api1", "My API")
};
} // client want to access resources (aka scopes)
public static IEnumerable<Client> GetClients()
{
return new List<Client>
{
new Client
{
ClientId = "client",
AllowedGrantTypes = GrantTypes.ClientCredentials, ClientSecrets =
{
new Secret("secret".Sha256())
},
AllowedScopes = { "api1" }
}
};
}
}
}
  • 5.启动,即完成了IdentityServer内存版的搭建。
using Microsoft.AspNetCore.Hosting;
using System;
using System.IO; namespace SigmalHex.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();
}
}
}

.net core 中 identity server 4 之Server简单示例的更多相关文章

  1. 在 .NET Core 中使用异步的 ADO.NET 的简单示例

    直接贴代码: Program.cs using Microsoft.Extensions.Configuration; using System; using System.Data; using S ...

  2. .net core 中 Identity Server 4 Topic 之 Startup

    约定 简称 Id4. Id4在.net core 中的使用符合.net core 的约定架构,即Services来注册服务,middleware方式集成. 1. 配置服务 通过DI注入: public ...

  3. TransactionScope事务处理方法介绍及.NET Core中的注意事项 SQL Server数据库漏洞评估了解一下 预热ASP.NET MVC 的VIEW [AUTOMAPPER]反射自动注册AUTOMAPPER PROFILE

    TransactionScope事务处理方法介绍及.NET Core中的注意事项   作者:依乐祝 原文链接:https://www.cnblogs.com/yilezhu/p/10170712.ht ...

  4. Asp.Net Core WebAPI入门整理(二)简单示例

    一.Core WebAPI中的序列化 使用的是Newtonsoft.Json,自定义全局配置处理: // This method gets called by the runtime. Use thi ...

  5. .net core 中 identity server 4 之Topic --定义API资源

    想要让客户端能够访问API资源,就需要在Identity Server中定义好API的资源. Scope作用域:即API资源的访问范围限制. 作用域是一个资源 (通常也称为 Web API) 的标识符 ...

  6. .net core 中 identity server 4 之Topic --定义Client

    客户端指能够从id4获取Token的角色. 客户端的共性: a unique client ID a secret if needed the allowed interactions with th ...

  7. .net core 中 identity server 4 之术语

    id4的职责: 保护你的资源 通过本地 账户库(Account Store)或者外部身份提供其 认证用户 提供Session管理以及SSO 管理和认证客户端 发行身份及访问Token给客户端 验证To ...

  8. _CrtDumpMemoryLeaks报告程序中的内存泄露问题(简单示例代码)

    // .h 文件 #pragma once class CConsoleDump { public: explicit CConsoleDump(LPCTSTR lpszWindowTitle = N ...

  9. asp.net core系列 61 Ocelot 构建服务发现简单示例

    一.概述 Ocelot允许指定服务发现提供程序,如Consul或Eureka. 这二个中间件是用来实现:服务治理或秒服务发现,服务发现查找Ocelot正在转发请求的下游服务的主机和端口.目前Ocelo ...

随机推荐

  1. lintcode-414-两个整数相除

    414-两个整数相除 将两个整数相除,要求不使用乘法.除法和 mod 运算符. 如果溢出,返回 2147483647 . 样例 给定被除数 = 100 ,除数 = 9,返回 11. 标签 二分法 思路 ...

  2. jdbc 2.0

    1.Statement接口不能接受参数 2.PreparedStatement接口在运行时接受输入参数 3.CallableStatement接口也可以接受运行时输入参数,当想要访问数据库存储过程时使 ...

  3. 对小组项目alpha发布的评价

    第一组:新蜂小组 项目:俄罗斯方块 评论:看见同学玩的时候,感到加速下落时不是很灵敏,没有及成绩的功能,用户的界面仍在修正. 第二组:天天向上 项目:连连看 评论:这个游戏增加了很多好玩的功能,比如更 ...

  4. xpath的学习

    xpath的作用就是两个字“定位”,运用各种方法进行快速准确的定位,推荐两个非常有用的的firefox工具:firebug和xpath checker   定位 1.依靠自己属性,文本定位 //td[ ...

  5. 新手必备!11个强大的 Visual Studio 调试技巧

    简介 调试是软件开发周期中很重要的一部分.它具有挑战性,同时也很让人疑惑和烦恼.总的来说,对于稍大一点的程序,调试是不可避免的.最近几年,调试工具的发展让很多调试任务变的越来越简单和省时. 这篇文章总 ...

  6. Linux的计划任务

    1. 语法格式:Minute Hour DayOfMonth Month DayOfWeek User Command Minute, 每个小时的第几分钟执行该任务Hour,每天的第几个小时执行该任务 ...

  7. 运维堡垒机----Gateone

    简介: 运维堡垒机的理念起源于跳板机.2000年左右,高端行业用户为了对运维人员的远程登录进行集中管理,会在机房里部署跳板机.跳板机就是一台服务器,维护人员在维护过程中,首先要统一登录到这台服务器上, ...

  8. Thread的run()与start()的区别

    java的线程是通过java.lang.Thread类来实现的.VM启动时会有一个由主方法所定义的线程.可以通过创建Thread的实例来创建新的线程.每个线程都是通过某个特定Thread对象所对应的方 ...

  9. IE 之 userData 模拟 localStorage

    引 chrome,  safari, firefox, ie 9都支持 localStorage.  但可恶的是,中国 ie 6 占有最大的比例. 使用 cookie 不但容量有限,而且给我们增加了不 ...

  10. LBP纹理特征[转自]

    LBP方法(Local binary patterns)是一个计算机视觉中用于图像特征分类的一个方法.LBP方法在1994年首先由T. Ojala, M.Pietikäinen, 和 D. Harwo ...