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. vim 查找整个工程

    1. 使用vim内置搜索引擎 vimgrep 格式::vim /patern/gj ** 命令::vim 或者 :vimgrep 模式: 查询模式包含在 / / 之间 参数: g 表示将同一行搜到的关 ...

  2. matlab2016b -ubuntu 1604 -install- and -trouble -shooting--finally-all is ok!!

    Linux系统下安装matlab2016b 标签: ubuntumatlablinux 2016-09-24 22:11 16203人阅读 评论(22) 收藏 举报 分类: linux 版权声明:本文 ...

  3. caffe搭建--caffe- win10 vs2015 编译(支持GPU)--注意在cmake的时候需要根据情况仔细修改配置

    --http://blog.csdn.net/longji/article/details/60964998 注意: 在cmake的时候需要根据情况仔细修改配置,比如,如果gpu的能力不足3.0的话, ...

  4. ffmpeg api升级到3.3 api变化

     void av_free_packet(AVPacket * pkt) Use void av_packet_unref(AVPacket * pkt) Wipe the packet. Unref ...

  5. EasyNVR将如何能够把内网各种各样的监控摄像机对接到公网云平台

    需求 传统监控行业里面,监控客户端.服务器端,设备端都在一个内网里面,搞个电脑开个监控终端,顶多再配一个NVR做一做摄像机的录像存储.上个电视墙(个人感觉这功能除了面子工程,没啥实用的,还特费电!), ...

  6. Performance Tuning Using Linux Process Management Commands

    [root@bigdata-server-02 /]# ps --help all Usage: ps [options] Basic options: -A, -e all processes -a ...

  7. Error: EACCES: permission denied, mkdir '/root/.nvm/versions/node/......

    当我执行npm install -g node-inspector的时候报错. 所以就去网上搜索了一下答案. 有这么几种答案.请看完再执行相关命令 有说需要在前面加上sudo命令的. 不能解决我出现的 ...

  8. Hadoop实战-MapReduce之WordCount(五)

    环境介绍: 主服务器ip:192.168.80.128(master)  NameNode  SecondaryNameNode ResourceManager 从服务器ip:192.168.80.1 ...

  9. selenium2 python范例

    selenium2 python范例 下面脚本的功能是:打开谷歌浏览器-->跳转到某个网址-->输入用户名和密码登录-->读取页面内的数据并求和. # coding=utf-8 #编 ...

  10. 基于BASYS2的VHDL程序与烧写——按键消抖程序

    请尊重作者版权,转载请注明源地址http://www.cnblogs.com/connorzx/p/3548364.html 按键在按下的过程中通常会产生一段时间的抖动,为了消除这种抖动,一般采取两种 ...