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. (9)launcher3 之 外部 更换主题Theme APP demo 实现原理以及demo

    先说下我的思路: luancher3里面更换图标的逻辑例如以下: 先从APP资源包里查询--数据库查询--其它地方查询ICON 因此,我们仅仅须要把 从数据库获取ICON 代码提前到  从APP资源包 ...

  2. 命令+mybatis-generator插件自己主动生成Mapper映射文件

    学mybatis的时候,自己写各种 *Mapper.xml和 *Mapper.java,注意各种sql语句中的 id 是否匹配.xml中的namespace是否正确,非常麻烦有木有?今天博客内容就是高 ...

  3. 使用Caffe完成图像目标检测 和 caffe 全卷积网络

    一.[用Python学习Caffe]2. 使用Caffe完成图像目标检测 标签: pythoncaffe深度学习目标检测ssd 2017-06-22 22:08 207人阅读 评论(0) 收藏 举报 ...

  4. C# 通过Hook的方法 屏蔽快捷键

     #region 屏蔽Windows功能键(快捷键)         public delegate int HookProc(int nCode, int wParam, IntPtr lParam ...

  5. wmware搬家

    由于D盘空间不足D:\Users\Documents\Virtual Machines文件夹剪切至E:\Virtual Machines. 先关闭虚拟机 然后剪切 直接通过icon无法打开 先运行E: ...

  6. 2015最新iherb海淘攻略-图文入门教程-6月免邮

    注:仅仅有首次下单才享有新人优惠10$,大家下单之后千万不要取消后.否则之后则不享有新人优惠. 注:眼下Sino-海淘客国际物流已取消,仅有UCS合众速递. IHerb是美国最热门的海淘海购网站之中的 ...

  7. swift3.0系列完整demo代码库

    https://github.com/soapyigu/Swift30Projects 感谢作者

  8. php 批量删除数据

    php 批量删除数据 :比如我们在看邮箱文件的时候,积攒了一段时间以后,看到有些文件没有用了 这时候我们就会想到把这些 没用的文件删除,这时候就用到了批量删除数据的功能,这里我是用了数据库原有的一个表 ...

  9. EasyPlayer Android安卓流媒体播放器实现播放同步录像功能实现(附源码)

    本文转自EasyDarwin团队John的博客:http://blog.csdn.net/jyt0551,John是EasyPusher安卓直播推流.EasyPlayer直播流媒体播放端的开发和维护者 ...

  10. Net Core环境开发与调试

    NET Core 包括.NET Core Runtime 和 .NET Core SDK: .NET Core = 应用运行依赖的 .NET Core Runtime .NET Core SDK = ...