IdentityServer4登陆中心
1. 使用Vsual Studio Code 终端执行 dotnet new webapi --name IdentityServerSample 命令创建一个webapi 的 IdentityServer4Sample 项目
2. 添加Config.cs 类
using System.Collections;
using System.Collections.Generic;
using IdentityServer4.Models; namespace IdentityServiceSample
{
public class Config
{
public static IEnumerable<ApiResource> GetResource()
{ return new List<ApiResource>(){
new ApiResource("api","my api")
}; } public static IEnumerable<Client> GetClients()
{ return new List<Client>(){
new Client(){
ClientId="client",
AllowedGrantTypes=GrantTypes.ClientCredentials,
ClientSecrets={new Secret("secrt".Sha256())},
AllowedScopes={"api"}
}
};
}
}
}
3. 修改 Startup.cs 如下 (安装IdentityServer4 包 当前使用的是2.1.1)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using IdentityServer4; namespace IdentityServiceSample
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
} public IConfiguration Configuration { get; } // This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
//1.注入IdentityServer
services.AddIdentityServer().AddDeveloperSigningCredential().AddInMemoryApiResources(Config.GetResource())
.AddInMemoryClients(Config.GetClients()); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
} // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseHsts();
} app.UseHttpsRedirection();
// app.UseMvc(); //2. 注册IdentityServer
app.UseIdentityServer();
}
}
}
4. 修改 Program.cs UseUrls 启动地址
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging; namespace IdentityServiceSample
{
public class Program
{
public static void Main(string[] args)
{
CreateWebHostBuilder(args).Build().Run();
} public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseUrls("https://localhost:5000") //修改启动地址
.UseStartup<Startup>();
}
}
5. dotnet run 运行
可以用:https://localhost:5000/.well-known/openid-configuration 查看配置信息 类似于Endpoint
{
"issuer":"https://localhost:5000",
"jwks_uri":"https://localhost:5000/.well-known/openid-configuration/jwks",
"authorization_endpoint":"https://localhost:5000/connect/authorize",
"token_endpoint":"https://localhost:5000/connect/token",
"userinfo_endpoint":"https://localhost:5000/connect/userinfo",
"end_session_endpoint":"https://localhost:5000/connect/endsession",
"check_session_iframe":"https://localhost:5000/connect/checksession",
"revocation_endpoint":"https://localhost:5000/connect/revocation",
"introspection_endpoint":"https://localhost:5000/connect/introspect",
"frontchannel_logout_supported":true,
"frontchannel_logout_session_supported":true,
"backchannel_logout_supported":true,
"backchannel_logout_session_supported":true,
"scopes_supported":[
"api",
"offline_access"
],
"claims_supported":[
],
"grant_types_supported":[
"authorization_code",
"client_credentials",
"refresh_token",
"implicit"
],
"response_types_supported":[
"code",
"token",
"id_token",
"id_token token",
"code id_token",
"code token",
"code id_token token"
],
"response_modes_supported":[
"form_post",
"query",
"fragment"
],
"token_endpoint_auth_methods_supported":[
"client_secret_basic",
"client_secret_post"
],
"subject_types_supported":[
"public"
],
"id_token_signing_alg_values_supported":[
"RS256"
],
"code_challenge_methods_supported":[
"plain",
"S256"
]
}
IdentityServer4登陆中心的更多相关文章
- 08.IdentityServer4登录中心
08.IdentityServer4登录中心 IdentityServer就是一套Framework,实现了OAuth的授权 理解OAuth流程,学会怎么使用他 http://ruanyifeng.c ...
- Asp.Net Core 中IdentityServer4 授权中心之自定义授权模式
一.前言 上一篇我分享了一篇关于 Asp.Net Core 中IdentityServer4 授权中心之应用实战 的文章,其中有不少博友给我提了问题,其中有一个博友问我的一个场景,我给他解答的还不够完 ...
- 【ASP.NET Core分布式项目实战】(一)IdentityServer4登录中心、oauth密码模式identity server4实现
本博客根据http://video.jessetalk.cn/my/course/5视频整理 资料 OAuth2 流程:http://www.ruanyifeng.com/blog/2014/05/o ...
- Asp.Net Core 中IdentityServer4 授权中心之应用实战
一.前言 查阅了大多数相关资料,查阅到的IdentityServer4 的相关文章大多是比较简单并且多是翻译官网的文档编写的,我这里在 Asp.Net Core 中IdentityServer4 的应 ...
- ASP.NET Core分布式项目-1.IdentityServer4登录中心
源码下载 一.添加服务端的api 1.添加NUGet包 IdentityServer4 点击下载,重新生成 2.添加Startup配置 打开Startup文件 public class Startup ...
- 客户端集成IdentityServer4
1. vs code 终端执行 dotnet new webapi --name ClientCredentialApi 2. 找到ValuesController.cs 引用 using Mic ...
- IdentityServer4 禁用 Consent screen page(权限确认页面)
IdentityServer4 在登录完成的适合,会再跳转一次页面(权限确认),如下: 我之前以为 IdentityServer4 就是这样使用的,但实际业务场景并不需要进行权限确认,而是登陆成功后直 ...
- ASP.NET Core Swagger接入使用IdentityServer4 的 WebApi
写在前面 是这样的,我们现在接口使用了Ocelot做网关,Ocelot里面集成了基于IdentityServer4开发的授权中心用于对Api资源的保护.问题来了,我们的Api用了SwaggerUI做接 ...
- IdentityServer4 + SignalR Core +RabbitMQ 构建web即时通讯(二)
IdentityServer4 + SignalR Core +RabbitMQ 构建web即时通讯(二) IdentityServer4 用户中心生成数据库 上文已经创建了所有的数据库上下文迁移代码 ...
随机推荐
- Storm 系列(三)Storm 集群部署和配置
Storm 系列(二)Storm 集群部署和配置 本章中主要介绍了 Storm 的部署过程以及相关的配置信息.通过本章内容,帮助读者从零开始搭建一个 Storm 集群. 一.Storm 的依赖组件 1 ...
- 打开jsp页面时,显示空白页。
打开jsp页面时,显示空白页. #foreach($e in $listPlanItem) #set($listPlanDetail=$!e.get(2)) < ...
- Activiti中23张表的含义
1.与流程定义相关的4张表: 2.与执行任务相关的5张表: 3.与流程变量相关的2张表
- 2018.08.30 bzoj4318: OSU!(期望dp)
传送门 简单期望dp. 感觉跟Easy差不多,就是把平方差量进阶成了立方差量,原本维护的是(x+1)2−x2" role="presentation" style=&qu ...
- 表格边框重复合并属性: border-collapse:collapse;
table { border-collapse:collapse; }
- b4和tncl_extract_UNCL_new
# -*- coding:utf-8 -*- import re ''' 适应新版本 注意: 1)17A文件改完后缀后,需要转为UTF-8无BOM格式,才能正确处理. 2)fr = open(file ...
- nlms_step_get
module nlms_step_get( rst , clk , nd , din01_i, din01_q, din02_i, din02_q, dou ...
- Python+Android开发
1 下载Scripting Layer for Android (SL4A) Scripting Layer for Android (SL4A) 是一个开源项目,目标是为android系统提供脚本语 ...
- hdu3853 LOOPS(概率dp) 2016-05-26 17:37 89人阅读 评论(0) 收藏
LOOPS Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 125536/65536 K (Java/Others) Total Su ...
- OpenGL中的矩阵相乘
OpenGL中的矩阵相乘 1, 在OpenGL中所有的视图变换,模型变换 都是4×4矩阵,每个后续的glMultiMatrix*(N),或者变换函数,glTranslate* (),glRotate* ...