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. [Jenkins] 在Jenkins执行单个test suite

    cd %WORKSPACE%cmd /c call "%READYAPI_PRO_190%\bin\testrunner.bat" -a -j -s"%TestSuite ...

  2. socket domain 样例

    服务端 #include<stdio.h> #include <sys/stat.h> #include <sys/socket.h> #include <s ...

  3. Part 3 - Advanced Concepts(11-13)

    https://simpleisbetterthancomplex.com/series/2017/09/18/a-complete-beginners-guide-to-django-part-3. ...

  4. java-Runtime 调用命令

    java是一个跨平台的语言,可以在多种平台上运行相应的程序,但是有些时候进行数据的提取时,可能就需要系统的相关命令,尤其是调用linux命令 这时候就需要使用java的Runtime命令,来执行lin ...

  5. 关于React的入门级安装和最浅显解释

    春节临近,办公室里半片空位,半片浮嚣. 想到将放假,屏幕上的代码也都变成了雀跃的小虫. 无法专心了. 终于还是强迫自己读了半篇文档,写了几坨程序. 这次记录的是关于React,最浅显的内容. ———— ...

  6. 【翻译】追溯“typeof null”的历史

    我的翻译小站:https://www.zcfy.cc/article/the-history-of-typeof-null 翻译原文链接:http://2ality.com/2013/10/typeo ...

  7. python正则表达式转义注意事项

    无论哪种语言,在使用正则表达式的时候都避免不了一个问题,就是在匹配元字符的时候,需要对元字符进行转义,让 正则表达式引擎将其当做普通字符来匹配.本文主要以python为例,说明一下转义中需要注意的问题 ...

  8. Codeforces777A Shell Game 2017-05-04 17:11 59人阅读 评论(0) 收藏

    A. Shell Game time limit per test 0.5 seconds memory limit per test 256 megabytes input standard inp ...

  9. jsTree问题

    1. 问题:刷新页面时,会自动打开刚才上次选中的节点 解决办法:去掉'state'插件 2. 关闭一个node时,使用close_all,不能修改class 注:好像用toggle_node,可以op ...

  10. Paul and Joyce are going to a movie(More listening of Unit 2)

      Paul: Hurry up, Joyce. We need to leave now if we're going to get to the theater a half hour befor ...