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登陆中心的更多相关文章

  1. 08.IdentityServer4登录中心

    08.IdentityServer4登录中心 IdentityServer就是一套Framework,实现了OAuth的授权 理解OAuth流程,学会怎么使用他 http://ruanyifeng.c ...

  2. Asp.Net Core 中IdentityServer4 授权中心之自定义授权模式

    一.前言 上一篇我分享了一篇关于 Asp.Net Core 中IdentityServer4 授权中心之应用实战 的文章,其中有不少博友给我提了问题,其中有一个博友问我的一个场景,我给他解答的还不够完 ...

  3. 【ASP.NET Core分布式项目实战】(一)IdentityServer4登录中心、oauth密码模式identity server4实现

    本博客根据http://video.jessetalk.cn/my/course/5视频整理 资料 OAuth2 流程:http://www.ruanyifeng.com/blog/2014/05/o ...

  4. Asp.Net Core 中IdentityServer4 授权中心之应用实战

    一.前言 查阅了大多数相关资料,查阅到的IdentityServer4 的相关文章大多是比较简单并且多是翻译官网的文档编写的,我这里在 Asp.Net Core 中IdentityServer4 的应 ...

  5. ASP.NET Core分布式项目-1.IdentityServer4登录中心

    源码下载 一.添加服务端的api 1.添加NUGet包 IdentityServer4 点击下载,重新生成 2.添加Startup配置 打开Startup文件 public class Startup ...

  6. 客户端集成IdentityServer4

    1. vs code 终端执行  dotnet new webapi --name ClientCredentialApi 2. 找到ValuesController.cs 引用  using Mic ...

  7. IdentityServer4 禁用 Consent screen page(权限确认页面)

    IdentityServer4 在登录完成的适合,会再跳转一次页面(权限确认),如下: 我之前以为 IdentityServer4 就是这样使用的,但实际业务场景并不需要进行权限确认,而是登陆成功后直 ...

  8. ASP.NET Core Swagger接入使用IdentityServer4 的 WebApi

    写在前面 是这样的,我们现在接口使用了Ocelot做网关,Ocelot里面集成了基于IdentityServer4开发的授权中心用于对Api资源的保护.问题来了,我们的Api用了SwaggerUI做接 ...

  9. IdentityServer4 + SignalR Core +RabbitMQ 构建web即时通讯(二)

    IdentityServer4 + SignalR Core +RabbitMQ 构建web即时通讯(二) IdentityServer4 用户中心生成数据库 上文已经创建了所有的数据库上下文迁移代码 ...

随机推荐

  1. Picard Tools

    Picard Tools - By Broad Institute http://broadinstitute.github.io/picard/command-line-overview.html ...

  2. Devexpress VCL Build v2013 vol 13.2.5 发布

    支持xe6 了,但是承诺的功能在哪里? What's New in 13.2.5 (VCL Product Line)   New Major Features in 13.2 What's New ...

  3. 改变yii2 $form最外层div样式

    <?php $form = ActiveForm::begin([ 'options'=>['class' => 'form-horizontal row-border','enct ...

  4. ThinkPHP5 union分页

    直接贴代码,记录一下,备用 $a = Db::name(表名)->field(字段)->where(条件)->buildSql(); $b = Db::name(表名)->fi ...

  5. spring boot2.0冷知识

    首先,Spring Boot 2.0.0 要求 Java 8 或更高版本,不再支持 Java 6 和 7. 在 Spring Boot 2.0 中,许多配置属性已被重命名或被删除,相应地,开发者需要升 ...

  6. gj7 对象引用、可变性和垃圾回收

    7.1 python变量到底是什么 #python和java中的变量本质不一样,python的变量实质上是一个指针 int str, 便利贴 a = 1 a = "abc" #1. ...

  7. Linux 修改 IP地址 和 网关

    修改IP地址和网关是很常见的操作,在做相关实验的时候,如果没有设置好,会带来很多不必要的麻烦.. 1. 修改IP地址vi /etc/sysconfig/network-scripts/ifcfg-et ...

  8. 基础的linux学习

    学习了这几个命令分享一下: 文本文件内搜索数据 grep -n -e pattern1 -e pattern2 file1 -n 搜索到的数据显示行号展示 -e pattern1 多个匹配模式下可以通 ...

  9. scrapy windows 安装

    windows 7 系统下参照官网安装总是会提示出错,现在整理一下安装的流程 1.安装 python 2.7,添加环境变量 C:\Python27\;C:\Python27\Scripts\; 在 C ...

  10. 四)mybatis 二级缓存 ehcache 常见问题

    1. java.io.NotSerializableException 94359 [EH_CACHE Async Replication Thread] ERROR n.s.e.d.jgroups. ...