.net core 中 identity server 4 之Server简单示例
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系统。
- AddIdentityServer
- AddTemporarySigningCredential
每次启动的时候,生成一个临时的签名证书
- 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简单示例的更多相关文章
- 在 .NET Core 中使用异步的 ADO.NET 的简单示例
直接贴代码: Program.cs using Microsoft.Extensions.Configuration; using System; using System.Data; using S ...
- .net core 中 Identity Server 4 Topic 之 Startup
约定 简称 Id4. Id4在.net core 中的使用符合.net core 的约定架构,即Services来注册服务,middleware方式集成. 1. 配置服务 通过DI注入: public ...
- TransactionScope事务处理方法介绍及.NET Core中的注意事项 SQL Server数据库漏洞评估了解一下 预热ASP.NET MVC 的VIEW [AUTOMAPPER]反射自动注册AUTOMAPPER PROFILE
TransactionScope事务处理方法介绍及.NET Core中的注意事项 作者:依乐祝 原文链接:https://www.cnblogs.com/yilezhu/p/10170712.ht ...
- Asp.Net Core WebAPI入门整理(二)简单示例
一.Core WebAPI中的序列化 使用的是Newtonsoft.Json,自定义全局配置处理: // This method gets called by the runtime. Use thi ...
- .net core 中 identity server 4 之Topic --定义API资源
想要让客户端能够访问API资源,就需要在Identity Server中定义好API的资源. Scope作用域:即API资源的访问范围限制. 作用域是一个资源 (通常也称为 Web API) 的标识符 ...
- .net core 中 identity server 4 之Topic --定义Client
客户端指能够从id4获取Token的角色. 客户端的共性: a unique client ID a secret if needed the allowed interactions with th ...
- .net core 中 identity server 4 之术语
id4的职责: 保护你的资源 通过本地 账户库(Account Store)或者外部身份提供其 认证用户 提供Session管理以及SSO 管理和认证客户端 发行身份及访问Token给客户端 验证To ...
- _CrtDumpMemoryLeaks报告程序中的内存泄露问题(简单示例代码)
// .h 文件 #pragma once class CConsoleDump { public: explicit CConsoleDump(LPCTSTR lpszWindowTitle = N ...
- asp.net core系列 61 Ocelot 构建服务发现简单示例
一.概述 Ocelot允许指定服务发现提供程序,如Consul或Eureka. 这二个中间件是用来实现:服务治理或秒服务发现,服务发现查找Ocelot正在转发请求的下游服务的主机和端口.目前Ocelo ...
随机推荐
- 测试bug
模板在运行时出现了以下 1 个错误:---------------------------Controller.tt(-1,-1) : error : 获取 AppDomain 以便从主机运行转换时出 ...
- 对IT行业的看法和对软件工程的理解
现在社会上IT行业的人才需求越来越大,而作为一个学软件工程的大学生,我认为IT行业是一个前景十分强大的发展方向,而且现在的社会越来越信息化,未来的生活中,电脑肯定是不可缺少的,所以我认为IT行业这是一 ...
- vue-cli3使用 DllPlugin 实现预编译,提升构建速度
在项目打包上有两个目标:减少打包代码体积和加快打包速度 1. 减少打包体积: (1)对于用的比较少的库,可以去掉(我去掉了jquery以及lodash),用到的地方,参考源码自己写 (2)非用不可的又 ...
- 服务器控件的异步请求——UpdatePanel和ScriptManager
aspx文件里面有以下一段代码 <body> <form id="form1" runat="server"> <div> ...
- Vue使用,异步获取日期时间后格式成"/Date(1333245600000+0800)/" 转换成正常格式
js从后台mvc中日期获取,结果格式成"/Date(1333245600000+0800)/"了,当然不能这样展显给用户了,要转换,方法如下: function data_stri ...
- 使用cookie保存用户登录信息
写入Cookie HttpCookie _cookie = new HttpCookie("User"); _cookie.Values.Add("UserName&qu ...
- week1day01 认识python 变量 数据类型 条件if语句
1.什么是python? Python是一种解释型.面向对象.动态数据类型的高级程序设计语言.Python由Guido van Rossum于1989年底发明,第一个公开发行版发行于1991年.像Pe ...
- 各行业最受欢迎的编程语言,硬件最青睐C和C++
近日,HackerRank发布了2018年开发技能报告,其中探讨了一些对理解开发人员环境至关重要的事情,本文将摘录编程语言排行部分 2018 开发者技能调查:不同行业中最热门的编程语言 尽管新语言经常 ...
- 怎样才能高效地使用JQuery
1. 使用最新版本的jQuery jQuery的版本更新很快,你应该总是使用最新的版本.因为新版本会改进性能,还有很多新功能.下面就来看看,不同版本的jQuery性能差异有多大.这里是三条最常见的jQ ...
- Dom4j 操作, 节点查找 添加 删除 修改 。。。xPath
转: Dom4j 操作, 节点查找 添加 删除 修改 ...xPath 2013年11月28日 10:48:59 今晚打酱油8 阅读数:8506更多 个人分类: JavaWeb 版权声明:本文为博 ...