前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >专栏 >IdentityServer4学习及简单使用

IdentityServer4学习及简单使用

作者头像
Vincent-yuan
发布于 2019-09-10 10:31:16
发布于 2019-09-10 10:31:16
1.5K00
代码可运行
举报
文章被收录于专栏:Vincent-yuanVincent-yuan
运行总次数:0
代码可运行

本文,主要用来记录IdentityServer4的简单使用。

一. IdentityServer的预备知识

要学习IdentityServer,需要了解下基于Token的验证体系,其中涉及到Token, OAuth&OpenID,JWT,协议规范等。

如图过程,

二. IdentityServer简单介绍

IdentityServer4 是一个基于OpenID Connect和OAuth 2.0的针对ASP.NET Core 2.0的框架,以中间件的形式存在。

通常你可以构建(或重新使用)包含登录和注销页面的应用程序,IdentityServer中间件会向其添加必要的协议头,以便客户端应用程序可以使用这些标准协议与其对话。

我们可以用IdentityServer来做什么?

  1. 身份验证服务:官方认证的OpenID Connect实现
  2. 单点登录/注销(SSO)
  3. 访问受控的API : 为不同的客户提供访问API的令牌,比如:MVC网站、SPA、Mobile APP等
  4. ...等等

三.简单项目示例

先列出目录结构,以及创建顺序,来方便阅读

IdentityServerDemo --> APIService1和APIService2 --> MVCClient

其中,处MVCClient是asp.net core web mvc项目外,其他都是asp.net core web api 项目

创建名为IdentityServerDemo的认证服务

1. 创建一个asp.net core web api项目:IdentityServerDemo。

注意,不要设置HTTPS,否则后面使用postman测试时,会no response

2. 添加InMemoryConfiguration

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
public class InMemoryConfiguration
    {
        public static IConfiguration Configuration { get; set; }
        /// <summary>
        /// Define which APIs will use this IdentityServer
        /// </summary>
        /// <returns></returns>
        public static IEnumerable<ApiResource> GetApiResources()
        { 
            return new[]
            {
                new ApiResource("clientservice", "CAS Client Service"),
                new ApiResource("productservice", "CAS Product Service"),
                new ApiResource("agentservice", "CAS Agent Service")
            };
        }

        /// <summary>
        /// Define which Apps will use thie IdentityServer
        /// </summary>
        /// <returns></returns>
        public static IEnumerable<Client> GetClients()
        {
            return new[]
            {
                new Client
                {
                    ClientId = "client.api.service",
                    ClientSecrets = new [] { new Secret("clientsecret".Sha256()) },
                    AllowedGrantTypes = GrantTypes.ResourceOwnerPasswordAndClientCredentials,
                    AllowedScopes = new [] { "clientservice" }
                },
                new Client
                {
                    ClientId = "product.api.service",
                    ClientSecrets = new [] { new Secret("productsecret".Sha256()) },
                    AllowedGrantTypes = GrantTypes.ResourceOwnerPasswordAndClientCredentials,
                    AllowedScopes = new [] { "clientservice", "productservice" }
                },
                new Client
                {
                    ClientId = "agent.api.service",
                    ClientSecrets = new [] { new Secret("agentsecret".Sha256()) },
                    AllowedGrantTypes = GrantTypes.ResourceOwnerPasswordAndClientCredentials,
                    AllowedScopes = new [] { "agentservice", "clientservice", "productservice" }
                }
            };
        }

        /// <summary>
        /// Define which uses will use this IdentityServer
        /// </summary>
        /// <returns></returns>
        public static IEnumerable<TestUser> GetUsers()
        {
            return new[]
            {
                new TestUser
                {
                    SubjectId = "10001",
                    Username = "test1@hotmail.com",
                    Password = "test1password"
                },
                new TestUser
                {
                    SubjectId = "10002",
                    Username = "test2@hotmail.com",
                    Password = "test2password"
                },
                new TestUser
                {
                    SubjectId = "10003",
                    Username = "test3@hotmail.com",
                    Password = "test3password"
                }
            };
        }
    }

3. 使用nuget管理器,添加IdentityServer4 ,并且修改StartUp.cs

修改StartUp.cs中的Configure方法

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            //启用IdentityServer
            app.UseIdentityServer();
            app.UseMvc();
        }

修改StartUp.cs中的ConfigureServices方法

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
public void ConfigureServices(IServiceCollection services)
        {
            //添加IdentityServer
            services.AddIdentityServer()
                       .AddDeveloperSigningCredential()
                       .AddTestUsers(InMemoryConfiguration.GetUsers().ToList())
                       .AddInMemoryClients(InMemoryConfiguration.GetClients())
                       .AddInMemoryApiResources(InMemoryConfiguration.GetApiResources());

            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
        }

这个主要是为了把IdentityServer注册到容器中,需要对其进行配置,而这个配置主要包含三个信息:

  1. 哪些api可以使用这个AuthorizationServer
  2. 哪些client可以使用这个AuthorizationServer
  3. 哪些User可以被这个AuthorizationServer识别并授权

这里的AuthorizationServer 指的就是这个项目的服务:用来认证及授权使用的.

这里是使用基于内存的方式。

对于Token签名需要一对公钥和私钥,IdentityServer为开发者提供了一个AddDeveloperSigningCredential()方法,它会帮我们搞定这个事情并且存储到硬盘。当切换到正式环境,需要使用真正的证书,更换为

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
public void ConfigureServices(IServiceCollection services)
    {
        InMemoryConfiguration.Configuration = this.Configuration;

        services.AddIdentityServer()
            .AddDeveloperSigningCredential()
            .AddTestUsers(InMemoryConfiguration.GetUsers().ToList())
            .AddInMemoryClients(InMemoryConfiguration.GetClients())
            .AddInMemoryApiResources(InMemoryConfiguration.GetApiResources());
    }

此项目,暂时不使用正式的证书了。

4.使用postman获取token

启动我们的IdentityServerDemo 项目,

然后使用postman发送请求

5.引入QuickStartUI

IdentityServer为我们提供了一套UI以使我们能快速的开发具有基本功能的认证/授权界面,下载地址:QuickStartUI

把QuickStartUI引入到我们的项目中,目录结构如下:

5.修改StartUp.cs

修改Configure方法

添加静态文件中间件

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            //启用IdentityServer
            app.UseIdentityServer();
            //for QuickStart-UI 启用静态文件
            app.UseStaticFiles();
            //app.UseMvc();
            app.UseMvcWithDefaultRoute(); //这里带有默认的路由
        }

6.运行程序

登录

点击here

登出

IdentityServer集成API Service

1. 添加asp.net core web api项目

注意,这里也是使用http方式;

2.在nuget中安装IdentityServer4.AccessTokenValidation

3.修改StartUp.cs文件

修改configureServices方法

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
public void ConfigureServices(IServiceCollection services)
        {
            //IdentityServer
            services.AddMvcCore().AddAuthorization().AddJsonFormatters();
            services.AddAuthentication(Configuration["Identity:Scheme"])
                        .AddIdentityServerAuthentication(options =>
                        {
                            options.RequireHttpsMetadata = false; //是否需要https
                            options.Authority = $"http://{Configuration["Identity:IP"]}:{Configuration["Identity:Port"]}";  //IdentityServer授权路径
                            options.ApiName = Configuration["Service:Name"];  //需要授权的服务名称
                        });

            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
        }

修改Configure方法

在UseMvc()之前启用Authentication中间件

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            //启用Authentication中间件
            app.UseAuthentication();

            app.UseMvc();
        }

修改appsettings.json文件

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
{
  "Service": {
    "Name": "clientservice", //本服务的名称
    "Port": "53064",  //本服务的端口号,根据自己服务启动时的端口号进行更改
    "DocName": "clientservice",
    "Version": "v1",
    "Title": "CAS Client Service API",
    "Description": "CAS Client Service API provide some API to help you get client information from CAS",
    "Contact": {
      "Name": "CAS 2.0 Team",
      "Email": "EdisonZhou@manulife.com"
    },
    "XmlFile": "Manulife.DNC.MSAD.IdentityServer4Test.ApiService01.xml"
  },
  "Identity": { //去请求授权的Identity服务,这里即IdentityServerDemo的服务启动时的地址
    "IP": "localhost",
    "Port": "49363",  //IdentityServerDemo项目启动时的端口号,根据实际情况修改
    "Scheme": "Bearer"
  }
}

上面是APIService1的添加,对应的服务名称是clientservice;

APIService2与之类似,只是把appsettings.json中的clientservice改为productservice.

4. 在APIService1和APIService2的Controller添加[Authorize]特性

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
 [Authorize]
    [Route("api/[controller]")]
    public class ValuesController : Controller
    {
        ......
    }

5. 测试

注意,这里模拟的是clientservice服务(即APIService1)去认证服务器请求token的过程,所以请求到token,也应该在获取clientservice相关授权的时候携带这个token.

如果在请求productservice的授权服务中,使用clientservice的token则会显示未授权

过程总结:

  1. 首先,在授权服务中,设置需要请求的ApiResource,client,user
  2. 在postman(相当于client)中,输入client的相关信息(client_id,client_serect)去请求token
  3. 然后就可以根据授权服务中相应client的AllowedScopes设置的范围来请求服务了。

授权服务中的client设置

IdentityServer集成MVC Web Application

1. 新建一个ASP.NET Core MVC项目:MVCClient

2.为指定方法添加[Authorize]特性

我们为HomeController下的Privacy方法上添加Authorize特性

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
     [Authorize]
        public IActionResult Privacy()
        {
            return View();
        }

这个时候,直接访问Privacy,会报错

而我们希望的效果是:当用户第一次点击Privacy,页面重定向到验证服务(IdentityServerDemo),当用户登录验证授权后,再重定向到该网站。

此后一定时间范围内的第二次,第三次点击,都不需要再重定向到验证服务,而是直接读取保存的token.

3. 给MVCClient项目添加OpenID Connect Authentication

而这部分主要集中于做Authentication(身份验证)而非Authorization(授权)

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
public void ConfigureServices(IServiceCollection services)
        {
            services.Configure<CookiePolicyOptions>(options =>
            {
                // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                options.CheckConsentNeeded = context => true;
                options.MinimumSameSitePolicy = SameSiteMode.None;
            });


            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);

            //这部分主要是做身份验证的(Authentication),而不是授权(Authorization)
            JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();
            services.AddAuthentication(options =>
            {
                options.DefaultScheme = "Cookies";
                options.DefaultChallengeScheme = "oidc"; //oidc => open id connect
            })
            .AddCookie("Cookies")
            .AddOpenIdConnect("oidc", options =>
            {
                options.SignInScheme = "Cookies";
                options.Authority = $"http://{Configuration["Identity:IP"]}:{Configuration["Identity:Port"]}";
                options.RequireHttpsMetadata = false;
                options.ClientId = "cas.mvc.client.implicit";
                options.ResponseType = "id_token token";  //允许返回access token
                options.SaveTokens = true;
            });

        }

这里我们使用的是implicit这个flow,它主要用于客户端应用程序(主要指基于javascript的应用),它允许客户端程序重定向到验证服务(IdentityServerDemo),而后带着token重定向回来。

另外,这里的ResponseType为”id_token token”,表示既获取id_token也获取access_token. 而SaveTokens设置为true,表示会将从验证服务返回的token持久化到cookie中,这样就不用每次请求token了。

另在configure方法中,设置Authentication中间件:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
 public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseAuthentication();

            app.UseStaticFiles();
            app.UseCookiePolicy();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
        }

主要Authentication中间件,要再UseMvc之前。

4. 修改app.settings

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
{
  "Service": {
    "Name": "cas.mvc.client.implicit", //本服务的名称
    "Port": "56458",  //服务端口号,根据实际情况调整
    "DocName": "cas.mvc.client.implicit",
    "Version": "v1",
    "Title": "CAS Client Service API",
    "Description": "CAS Client Service API provide some API to help you get client information from CAS",
    "Contact": {
      "Name": "CAS 2.0 Team",
      "Email": "EdisonZhou@manulife.com"
    },
    "XmlFile": "Manulife.DNC.MSAD.IdentityServer4Test.ApiService01.xml"
  },
  "Identity": { //去请求授权的Identity服务
    "IP": "localhost",
    "Port": "49363"
  }
}

其中port根据自己此服务启动后的端口号修改

5.在验证服务(IdentityServerDemo)中添加MvcClient

修改 InMemoryConfiguration 中的GetClients方法:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
public static IEnumerable<Client> GetClients()
        {
            return new[]
            {
                new Client
                {
                    ClientId = "client.api.service",
                    ClientSecrets = new [] { new Secret("clientsecret".Sha256()) },
                    AllowedGrantTypes = GrantTypes.ResourceOwnerPasswordAndClientCredentials,
                    AllowedScopes = new [] { "clientservice" }
                },
                new Client
                {
                    ClientId = "product.api.service",
                    ClientSecrets = new [] { new Secret("productsecret".Sha256()) },
                    AllowedGrantTypes = GrantTypes.ResourceOwnerPasswordAndClientCredentials,
                    AllowedScopes = new [] { "clientservice", "productservice" }
                },
                new Client
                {
                    ClientId = "agent.api.service",
                    ClientSecrets = new [] { new Secret("agentsecret".Sha256()) },
                    AllowedGrantTypes = GrantTypes.ResourceOwnerPasswordAndClientCredentials,
                    AllowedScopes = new [] { "agentservice", "clientservice", "productservice" }
                },
                new Client
                {
                    ClientId = "cas.mvc.client.implicit",
                    ClientName = "CAS MVC Web App Client",
                    AllowedGrantTypes = GrantTypes.Implicit,
                    RedirectUris = { $"http://localhost:56458/signin-oidc" },
                    PostLogoutRedirectUris = { $"http://localhost:56458/signout-callback-oidc" },
                    AllowedScopes = new [] {
                        IdentityServerConstants.StandardScopes.OpenId,
                        IdentityServerConstants.StandardScopes.Profile,
                        "agentservice", "clientservice", "productservice"
                    },
                    AllowAccessTokensViaBrowser = true // can return access_token to this client
                },
            };
        }

这里ClientId要和MvcClient中设置的一样。

RedirectUris是指登录成功以后需要重定向的地址(即重定向到MvcClient中的地址),

而PostLogoutRedirectUris是指登出之后需要重定向的地址。

和API Service Client的设置不同的就是AllowedScopes中给它增加了OpenId和Profile,因为我们为MvcClient设定的是oidc而不是bearer模式。

最后为了使用这些OpenID Connect Scopes,需要设置这些Identity Resources。

在 InMemoryConfiguration 中增加GetIdentityResources方法:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
public static IEnumerable<IdentityResource> GetIdentityResources()
        {
            return new List<IdentityResource>
            {
                new IdentityResources.OpenId(),
                new IdentityResources.Profile(),
            };
        }

在ConfigureServices方法中修改:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
 public void ConfigureServices(IServiceCollection services)
        {
            //添加IdentityServer
            services.AddIdentityServer()
                       .AddDeveloperSigningCredential()
                       .AddInMemoryIdentityResources(InMemoryConfiguration.GetIdentityResources())
                       .AddTestUsers(InMemoryConfiguration.GetUsers().ToList())
                       .AddInMemoryClients(InMemoryConfiguration.GetClients())
                       .AddInMemoryApiResources(InMemoryConfiguration.GetApiResources());

            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
        }

6. 在MvcClient项目的Privacy 页面中修改如下:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
@{
    ViewData["Title"] = "Privacy Policy";
}
<h1>@ViewData["Title"]</h1>

<p>Use this page to detail your site's privacy policy.</p>


@using Microsoft.AspNetCore.Authentication
<div>
    <strong>id_token</strong>
    <span>@await ViewContext.HttpContext.GetTokenAsync("id_token")</span>
</div>
<div>
    <strong>access_token</strong>
    <span>@await ViewContext.HttpContext.GetTokenAsync("access_token")</span>
</div>

<dl>
    @foreach (var claim in User.Claims)
    {
        <dt>@claim.Type</dt>
        <dd>@claim.Value</dd>
    }
</dl>

这里,我们会把id_token和access_token显示出来

7. 为了退出方便,暂时在HomeController下增加Logout方法

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
 public async Task Logout()
        {
            await HttpContext.SignOutAsync("Cookies");
            await HttpContext.SignOutAsync("oidc");
        } 

8. 简单测试

启动IdentityServerDemo这个验证服务;

启动MvcClient这个Mvc Web Application服务;

这里没有添加可点击的按钮,可直接在url中修改路径来登出

参考网址:

https://www.cnblogs.com/edisonchou/p/identityserver4_foundation_and_quickstart_01.html

另外推荐edisonchou微服务系列,感觉非常棒

https://github.com/Vincent-yuan/IdentityServerDemo

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2019-06-11 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
暂无评论
推荐阅读
编辑精选文章
换一批
.NET Core微服务之基于IdentityServer建立授权与验证服务(续)
上一篇我们基于IdentityServer4建立了一个AuthorizationServer,并且继承了QuickStartUI,能够成功获取Token了。这一篇我们了解下如何集成API Service和MVC Web Application。
Edison Zhou
2018/08/07
1.9K0
.NET Core微服务之基于IdentityServer建立授权与验证服务(续)
.NET Core微服务之基于Ocelot+IdentityServer实现统一验证与授权
  这里,假设我们有两个客户端(一个Web网站,一个移动App),他们要使用系统,需要通过API网关(这里API网关始终作为客户端的统一入口)先向IdentityService进行Login以进行验证并获取Token,在IdentityService的验证过程中会访问数据库以验证。然后再带上Token通过API网关去访问具体的API Service。这里我们的IdentityService基于IdentityServer4开发,它具有统一登录验证和授权的功能。
Edison Zhou
2018/08/21
7230
.NET Core微服务之基于Ocelot+IdentityServer实现统一验证与授权
.NET Core微服务之基于IdentityServer建立授权与验证服务
  要学习IdentityServer,事先得了解一下基于Token的验证体系,这是一个庞大的主题,涉及到Token,OAuth&OpenID,JWT,协议规范等等等等,园子里已经有很多介绍的文章了,个人觉得solenovex的这一篇文章《学习IdentityServer4的预备知识》言简意赅,可以快速的看看。另外savaboard的《ASP.NET Core 之 Identity 入门(一)》和《ASP.NET Core 之 Identity 入门(二)》这两篇也可以一看,对Claims和Identity的基本知识讲的比较通俗易懂,深入浅出,有故事情节,哈哈。
Edison Zhou
2018/08/07
1.8K0
.NET Core微服务之基于IdentityServer建立授权与验证服务
.NET Core微服务之基于Ocelot+IdentityServer实现统一验证与授权
  这里,假设我们有两个客户端(一个Web网站,一个移动App),他们要使用系统,需要通过API网关(这里API网关始终作为客户端的统一入口)先向IdentityService进行Login以进行验证并获取Token,在IdentityService的验证过程中会访问数据库以验证。然后再带上Token通过API网关去访问具体的API Service。这里我们的IdentityService基于IdentityServer4开发,它具有统一登录验证和授权的功能。
Edison Zhou
2018/08/02
1.2K0
.NET Core微服务之基于Ocelot+IdentityServer实现统一验证与授权
IdentityServer4入门
IdentityServer4是用于ASP.NET Core的OpenID Connect和OAuth 2.0框架。
鱼找水需要时间
2023/02/16
7.8K0
使用Identity Server 4建立Authorization Server (3)
上一部分简单的弄了个web api 并通过Client_Credentials和ResourceOwnerPassword两种方式获取token然后进行api请求. 这次讲一下Authenticati
solenovex
2018/03/01
1.3K0
使用Identity Server 4建立Authorization Server (3)
【One by One系列】IdentityServer4(四)授权码流程
接下来我们介绍新内容,OAuth2.0叫做授权码(authorization code),在OpenID Connect中则属于OpenId Connect Flow,称为授权码流程(Authorization Code Flow),这种方式主要场景:
DDGarfield
2022/06/23
2K0
【One by One系列】IdentityServer4(四)授权码流程
Asp.Net Core 中IdentityServer4 授权流程及刷新Token
上面分享了IdentityServer4 两篇系列文章,核心主题主要是密码授权模式及自定义授权模式,但是仅仅是分享了这两种模式的使用,这篇文章进一步来分享IdentityServer4的授权流程及refreshtoken。
Jlion
2022/04/07
2K0
Asp.Net Core 中IdentityServer4 授权流程及刷新Token
Asp.NetCoreWebApi图片上传接口(二)集成IdentityServer4授权访问(附源码)
上一篇文章中,给大家讲解了如何通过 Asp.Net Core Web Api实现图片上传的接口,具体的可以[点这里查看][https://www.cnblogs.com/yilezhu/p/9297009.html] 。这个接口是一个公开的接口,如何发布的话,任何知道调用方法的"任何人"都能任意的调用这个接口,俗称“裸奔”。这时候我们就应该给接口加入认证以及访问控制机制,来加强安全性!那么我们怎么来实现接口的认证以及访问控制呢?这时候部分人就会很懵逼了,还有一部分人就会联想到 OpenID Connect 和 OAuth 2.0了!可是怎么实现呢?从到到位搭一个这样的框架,会累死我滴,可能还要经过很长时间的测试呢!别担心,这时候就体现出Asp.Net Core社区的强大了,我们的主角IdentityServer4闪亮登场!
依乐祝
2018/09/18
1.1K0
Asp.NetCoreWebApi图片上传接口(二)集成IdentityServer4授权访问(附源码)
asp.net core IdentityServer4 实现 Client credentials(客户端凭证)
认证服务器在确定客户端信息无误后向客户端返回token,客户端请求资源时带着该token进行访问.(在这种模式中用户可直接向客户端注册,客户端再以自己的名义请求认证服务器)
HueiFeng
2020/02/12
1.2K0
asp.net core IdentityServer4 实现 Client credentials(客户端凭证)
IdentityServer Topics(3)- 定义客户端
客户端代表可以从您的身份服务器请求令牌的应用程序。 细节有所不同,但您通常为客户端定义以下常用设置: 一个唯一的客户端ID 一个密钥,如果需要 允许与令牌服务的交互(称为授权类型) 身份或访问令牌被发送到的网络位置(称为重定向URI) 允许客户端访问的范围列表(资源) 在运行时,客户端通过IClientStore的实现来检索。 这允许从配置文件或数据库的任意数据源加载它们。 对于本文档,我们将使用客户端存储的内存存储版本。 您可以通过AddInMemoryClients扩展方法在ConfigureServ
晓晨
2018/06/22
7120
IdentityServer(12)- 使用 ASP.NET Core Identity
IdentityServer具有非常好的扩展性,其中用户及其数据(包括密码)部分你可以使用任何想要的数据库进行持久化。 如果需要一个新的用户数据库,那么ASP.NET Core Identity是你的一个选择。 本快速入门介绍了如何将ASP.NET Core Identity 和 IdentityServer4一起使用。 在阅读这篇文章是,希望你能把前面的文章全部看一遍,了解基本使用和相关的理论。 这个快速入门使用ASP.NET Core Identity的方法是从Visual Studio中的ASP.NE
晓晨
2018/06/22
1.8K0
ASP.NET Core分布式项目实战(oauth2 + oidc 实现 client部分)--学习笔记
任务16:oauth2 + oidc 实现 client部分 实现 client 之前启动一下上一节的 server,启动之前需要清除一些代码 注释 Program 的 MigrateDbContext public static void Main(string[] args) { BuildWebHost(args) //.MigrateDbContext<ApplicationDbContext>((context, services) => { // n
郑子铭
2021/01/13
7830
ASP.NET Core分布式项目实战(oauth2 + oidc 实现 client部分)--学习笔记
Asp.Net Core 中IdentityServer4 授权中心之应用实战
查阅了大多数相关资料,搜索到的IdentityServer4 的应用文章大多是比较简单并且多是翻译官网的文档编写的,我这里在 Asp.Net Core 中IdentityServer4 的应用分析中会以一个电商系统架构升级过程中普遍会遇到的场景进行实战性讲述分析,同时最后会把我的实战性的代码放到github 上,敬请大家关注!
Jlion
2022/04/07
8200
Asp.Net Core 中IdentityServer4 授权中心之应用实战
asp.net core IdentityServer4 实现 implicit(隐式许可)实现第三方登录
,不通过第三方应用程序的服务器,直接在浏览器中向认证服务器申请令牌,跳过了"授权码"这个步骤,因此得名。所有步骤在浏览器中完成,令牌对访问者是可见的,且客户端不需要认证。
HueiFeng
2020/02/12
1.4K0
asp.net core IdentityServer4 实现 implicit(隐式许可)实现第三方登录
Identity Server4学习系列四之用户名密码获得访问令牌
Identity Server4支持用户名密码模式,允许调用客户端使用用户名密码来获得访问Api资源(遵循Auth 2.0协议)的Access Token,MS可能考虑兼容老的系统,实现了这个功能,但是不建议这么做.
郑小超.
2018/12/27
8900
Identity Server4学习系列四之用户名密码获得访问令牌
asp.net core IdentityServer4 实现 resource owner password credentials(密码凭证)
本章主要介绍密码模式(resource owner password credentials),OAuth2.0资源所有者密码授权功能允许客户端将用户名和密码发送到令牌服务,并获得该用户的访问令牌.
HueiFeng
2020/02/12
1.4K0
asp.net core IdentityServer4 实现 resource owner password credentials(密码凭证)
ASP.NET Core的身份认证框架IdentityServer4(9)-使用OpenID Connect添加用户认证
OpenID Connect OpenID Connect 1.0是OAuth 2.0协议之上的一个简单的身份层。 它允许客户端基于授权服务器执行的身份验证来验证最终用户的身份,以及以可互操作和类似R
晓晨
2018/06/22
3.4K0
ASP.NET Core的身份认证框架IdentityServer4(8)- 使用密码认证方式控制API访问
前言 本文及IdentityServer这个系列使用的都是基于.net core 2.0的。上一篇博文在API项目中我使用了Microsoft.AspNetCore.Authentication.JwtBearer组件来代替IdentityServer4.AccessTokenValidation组件,今天(2017-9-12)我发现后者已经更新到了2.0.0,支持.net core 2.0,所以现在所使用的组件已经更新为后者,在代码里我有详细注释。 资源所有者密码授权 OAuth 2.0 资源所有者密码授
晓晨
2018/06/22
1.5K0
IdentityServer(11)- 使用Hybrid Flow并添加API访问控制
关于Hybrid Flow 和 implicit flow 我在前一篇文章使用OpenID Connect添加用户认证中提到了implicit flow,那么它们是什么呢,它和Hybrid Flow有什么不同呢,这里简单讲一下。 Hybrid Flow 和 implicit flow是OIDC(OpenID Connect)协议中的术语,Implicit Flow是指使用OAuth2的Implicit流程获取Id Token和Access Token;Hybrid Flow是指混合Authorization
晓晨
2018/06/22
1.2K0
推荐阅读
相关推荐
.NET Core微服务之基于IdentityServer建立授权与验证服务(续)
更多 >
LV.1
这个人很懒,什么都没有留下~
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
查看详情【社区公告】 技术创作特训营有奖征文