08.IdentityServer4登录中心

IdentityServer就是一套Framework,实现了OAuth的授权

理解OAuth流程,学会怎么使用他

http://ruanyifeng.com/blog/2014/05/oauth_2_0.html

客户端模式(client credentials)

客户端模式,在使用微信支付或者支付宝支付的时候,会使用这种模式

简单的实现一个IdentityServer

首先新建webapi的项目

在我的电脑D:\MyDemos\jesse\下创建文件夹IdentityServerSample

D:\MyDemos\jesse\IdentityServerSample

然后在这个文件夹下面打开dos窗体。创建webapi的项目

dotnet new webapi --name IdentityServerCenter

D:\MyDemos\jesse\IdentityServerSample\IdentityServerCenter

视频上用VScode打开的。 我还是用VS2017打开吧

添加Nuget包

Nuget安装包:IdentityServer4

添加StartUp配置

在MVC以前添加service配置

引入命名空间 using IdentityServer4;

配置添加到依赖注入里面

services.AddIdentityServer()
                .AddDeveloperSigningCredential();

添加完依赖注入以后,要使用这个Identity

 //app.UseMvc();//这里我们暂时用不到MVC。这里先注释掉
app.UseIdentityServer();

然后我们在Program.cs里面

设置启动地方为5000端口

.UseUrls("http://localhost:5000")

Config.cs类

在根目录下创建 Config.cs文件

这个类是我们暂时用来初始化IdentityServer的

类里面我们会写一些静态方法

这里返回一个Resource

接下来定义Client客户端

在给一个可以访问Resource,就是这个Client呢可以访问我们那些Resource

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using IdentityServer4.Models; namespace IdentityServerCenter
{
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("secret".Sha256())
},
AllowedScopes={ "api"}
}
};
} }
}

把我们的ApiResoure加入进来

运行程序

这里我先都注释掉

这里没有添加mvc的管道也没有添加webapi

webapi和mvc实际上一个管道。

打开地址,什么也看不到

http://localhost:5000/

identityServer给我提供一个固定的地址:

http://localhost:5000/.well-known/openid-configuration

这里给我们一些基本的配置,基本的信息

{
"issuer": "http://localhost:5000",
"jwks_uri": "http://localhost:5000/.well-known/openid-configuration/jwks",
"authorization_endpoint": "http://localhost:5000/connect/authorize",
"token_endpoint": "http://localhost:5000/connect/token",
"userinfo_endpoint": "http://localhost:5000/connect/userinfo",
"end_session_endpoint": "http://localhost:5000/connect/endsession",
"check_session_iframe": "http://localhost:5000/connect/checksession",
"revocation_endpoint": "http://localhost:5000/connect/revocation",
"introspection_endpoint": "http://localhost:5000/connect/introspect",
"device_authorization_endpoint": "http://localhost:5000/connect/deviceauthorization",
"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",
"urn:ietf:params:oauth:grant-type:device_code"
],
"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"
]
}

这里是支持的几种模式

这里是加密的方式

会暴露一些endpoint

下一节课  我们要实现Resource。写一个API

08.IdentityServer4登录中心的更多相关文章

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

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

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

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

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

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

  4. IdentityServer4 登录成功后,跳转到原来页面

    IdentityServer4 登录成功后,默认会跳转到Config.Client配置的RedirectUris地址http://localhost:5003/callback.html,用于获取 T ...

  5. Easyui入门视频教程 第08集---登录实现 ajax button的使用

    目录 ----------------------- Easyui入门视频教程 第09集---登录完善 图标自定义   Easyui入门视频教程 第08集---登录实现 ajax button的使用  ...

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

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

  7. IdentityServer4 登录使用数据库

    业务场景: IdentityServer4 默认使用TestUser和UserStore,需要模拟和加载所有的用户数据,正式环境肯定不能这样实现,我们想从自己的数据库中读取用户信息,另外,因为 Ide ...

  8. 统一登录中心SSO 单点登录系统的构想

    什么是单点登录?我想肯定有一部分人“望文生义”的认为单点登录就是一个用户只能在一处登录,其实这是错误的理解.单点登录指的是多个子系统只需要登录一个,其他系统不需要登录了(一个浏览器内).一个子系统退出 ...

  9. IdentityServer4登陆中心

    1. 使用Vsual Studio Code 终端执行 dotnet new webapi --name IdentityServerSample 命令创建一个webapi 的 IdentitySer ...

随机推荐

  1. Android对apk源代码的改动--反编译+源代码改动+又一次打包+签名【附HelloWorld的改动实例】

    最近遇到了须要改动apk源代码的问题,于是上网查了下相关资料.编写了HelloWorld进行改动看看可行性,经过实验证明此方案可行,而且后来也成功用这种方法对目标apk进行了改动,仅仅只是须要改动的部 ...

  2. forEach for for in for of性能问题

    var arr = new Array(1000); console.time('forEach'); arr.forEach(data => { }); console.timeEnd('fo ...

  3. 关于erlang解析json数据

    JSON(JavaScript Object Notation)是一种轻量级的数据交换语言,以文字为基础,且易于让人阅读.json的数据格式是文本文档格式的一种.在erlang中可以参考mochiwe ...

  4. 数据结构基础之memset---有memset 抛出的int 和 char 之间的转换和字节对齐

    今天晚上,在做滤波算法时,里面用到很多float 和int 以及char 之间的类型强制转换,后面滤波完发现图片有些区域块,有过度曝光的白光,我就跟踪,以为是char 字符数字数据溢出问题,加了0-2 ...

  5. live555直播

    http://www.cppblog.com/tx7do/archive/2014/05/31/207155.aspx http://blog.csdn.net/sunkwei/article/det ...

  6. Lance老师UI系列教程第九课->高仿比特币监控大师

    http://blog.csdn.net/lancees/article/details/22898971

  7. 整形范围 运行Java代码的机器

    Java 无关 C C++ 有关  移植  整形溢出

  8. 如何缓存hbase数据以减少下次取数据的时间

    缓存从hbase取得的数据的好处是显而易见的,缓存到本地以后,如果下次的输入能够直接从已缓存的本地文件中取得数据就无需再次访问hbase数据库,这样一来数据量大的话可以节省大量的访问hbase数据库的 ...

  9. HDU3605 Escape —— 二分图多重匹配

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3605 Escape Time Limit: 4000/2000 MS (Java/Others)    ...

  10. Codeforces Round #376 (Div. 2) A. Night at the Museum —— 循环轴

    题目链接: http://codeforces.com/contest/731/problem/A A. Night at the Museum time limit per test 1 secon ...