原文地址

Clients 的定义

Client是指那些从 identityserver获取 token的应用

通常需要为client定义下面通用的设置

  • 唯一的client id
  • secret, 如果需要
  • 允许交互的令牌服务(也叫做 grant type)
  • 一个接收 identity 和/或 access token 的网络地址
  • client 被允许访问的 一组 scope (也叫做resource)

Note 运行时,clients 通过 实现IClientStore 调用方法得到。这使得可以从任意的数据源获取client数据,比如 config 文件或者数据库。文档中使用 in-memory 版本的 client 存储方式。通过在ConfigureService中添加 AddInmemoryClients 扩展实现。

client for service to service communication 的定义

这个场景下没有用户操作- 一个service(aka client)试图和一个API(aka scope)进行交互。

public class Clients
{
public static IEnumerable<Client> Get()
{
return new List<Client>
{
new Client
{
ClientId = "service.client",
ClientSecrets = { new Secret("secret".Sha256()) }, AllowedGrantTypes = GrantTypes.ClientCredentials,
AllowedScopes = { "api1", "api2.read_only" }
}
};
}
}

定义基于浏览器的JavaScript客户端(例如SPA)来对用户进行身份验证和授权Api访问

这个 client 使用叫做 implicit 的流程从 JavaScript 请求 identity 和 access token

var jsClient = new Client
{
ClientId = "js",
ClientName = "JavaScript Client",
ClientUri = "http://identityserver.io", AllowedGrantTypes = GrantTypes.Implicit,
AllowAccessTokensViaBrowser = true, RedirectUris = { "http://localhost:7017/index.html" },
PostLogoutRedirectUris = { "http://localhost:7017/index.html" },
AllowedCorsOrigins = { "http://localhost:7017" }, AllowedScopes =
{
IdentityServerConstants.StandardScopes.OpenId,
IdentityServerConstants.StandardScopes.Profile,
IdentityServerConstants.StandardScopes.Email, "api1", "api2.read_only"
}
};

定义基于服务端web应用程序(例如MVC)来对用户进行身份验证和授权Api访问

服务端(或者 本地桌面/手机)应用程序使用 hybrid flow. 这种方式最安全,因为access tokens 仅使用后台通信,而且允许刷新token

var mvcClient = new Client
{
ClientId = "mvc",
ClientName = "MVC Client",
ClientUri = "http://identityserver.io", AllowedGrantTypes = GrantTypes.Hybrid,
AllowOfflineAccess = true,
ClientSecrets = { new Secret("secret".Sha256()) }, RedirectUris = { "http://localhost:21402/signin-oidc" },
PostLogoutRedirectUris = { "http://localhost:21402/" },
FrontChannelLogoutUri = "http://localhost:21402/signout-oidc", AllowedScopes =
{
IdentityServerConstants.StandardScopes.OpenId,
IdentityServerConstants.StandardScopes.Profile,
IdentityServerConstants.StandardScopes.Email, "api1", "api2.read_only"
},
};

在 appsettings.json 中定义 clients

Asp.Net Core 配置文件

"IdentityServer": {
"IssuerUri": "urn:sso.company.com",
"Clients": [
{
"Enabled": true,
"ClientId": "local-dev",
"ClientName": "Local Development",
"ClientSecrets": [ { "Value": "<Insert Sha256 hash of the secret encoded as Base64 string>" } ],
"AllowedGrantTypes": [ "implicit" ],
"AllowedScopes": [ "openid", "profile" ],
"RedirectUris": [ "https://localhost:5001/signin-oidc" ],
"RequireConsent": false
}
]
}
AddInMemoryClients(configuration.GetSection("IdentityServer:Clients"))

IdentityServer4 Clients的更多相关文章

  1. IdentityServer4之Clients、Scopes、Claims与Token关联

    IdentityServer4之Clients.Scopes.Claims与Token关联 参考 官方文档:client.identity_resource.api_resource:三类配置项介绍描 ...

  2. IdentityServer4 简单使用,包括api访问控制,openid的授权登录,js访问

    写在前面 先分享一首数摇:http://music.163.com/m/song?id=36089751&userid=52749763 其次是:对于identityServer理解并不是特别 ...

  3. IdentityServer4 实现 OpenID Connect 和 OAuth 2.0

    关于 OAuth 2.0 的相关内容,点击查看:ASP.NET WebApi OWIN 实现 OAuth 2.0 OpenID 是一个去中心化的网上身份认证系统.对于支持 OpenID 的网站,用户不 ...

  4. ASP.NET Core的身份认证框架IdentityServer4(8)- 使用密码认证方式控制API访问

    前言 本文及IdentityServer这个系列使用的都是基于.net core 2.0的.上一篇博文在API项目中我使用了icrosoft.AspNetCore.Authentication.Jwt ...

  5. IdentityServer4实现Token认证登录以及权限控制

    相关知识点 不再对IdentityServer4做相关介绍,博客园上已经有人出了相关的系列文章,不了解的可以看一下: 蟋蟀大神的:小菜学习编程-IdentityServer4 晓晨Master:Ide ...

  6. IdentityServer4 配置负载均衡

    如果使用 IdentityServer4 做授权服务的负载均衡,默认情况下是不可以的,比如有两个授权服务站点,一个资源服务绑定其中一个授权服务(Authority配置),如果通过另外一个授权服务获取a ...

  7. 【ASP.NET Core分布式项目实战】(三)整理IdentityServer4 MVC授权、Consent功能实现

    本博客根据http://video.jessetalk.cn/my/course/5视频整理(内容可能会有部分,推荐看源视频学习) 前言 由于之前的博客都是基于其他的博客进行开发,现在重新整理一下方便 ...

  8. .NET Core IdentityServer4实战 第三章-使用EntityFramework Core进行持久化配置

    内容:本文带大家使用IdentityServer4进行使用使用EntityFramework Core进行配置和操作数据 作者:zara(张子浩) 欢迎分享,但需在文章鲜明处留下原文地址. 前两章内容 ...

  9. .NET Core IdentityServer4实战 第二章-OpenID Connect添加用户认证

    内容:本文带大家使用IdentityServer4进行使用OpenID Connect添加用户认证 作者:zara(张子浩) 欢迎分享,但需在文章鲜明处留下原文地址. 在这一篇文章中我们希望使用Ope ...

随机推荐

  1. poj3532 Round Numbers

      题意:给出l.r,求区间[l,r]内二进制中0的个数大于等于1的个数的数字有多少个. 简单的数位dp. //Serene #include<algorithm> #include< ...

  2. SpringCloud Zuul 路由映射规则配置

    阅读目录 前言 快速入门 路由详解 Cookie与头信息 本地跳转 Hystrix和Ribbon支持 过滤器解释 动态加载 后记 回到目录 前言 本文起笔于2018-06-26周二,接了一个这周要完成 ...

  3. navicat 导入SQL文件出错

    1.新建数据库 在数据库名或者表名上右键  运行SQL语句 2.去掉对勾 F5刷新则可以发现导入的表.

  4. @codeforces - 1214G@ Feeling Good

    目录 @description@ @solution@ @accepted code@ @details@ @description@ 给定一个 n*m 的 01 矩阵 A,一开始所有格子都为 0. ...

  5. Vue.js 第1章 Vue常用指令学习

    今日目标 能够写出第一个vue应用程序 能够接受为什么需要学vue 能够使用指令 能够通过指定完成简单的业务(增加删除查询) 能够理解mvvm 为什么要学习vue 企业需要 可以提高开发效率 实现vu ...

  6. python 检测目录

    #!/usr/bin/env python# -*- coding:utf-8 -*-import osimport win32fileimport win32con ACTIONS = { 1 : ...

  7. 2-3-4 tree留坑

    #include<bits/stdc++.h> #define LL long long #define pii pair<int,int> #define mp make_p ...

  8. Spring MVC 解决 Could not write JSON: No serializer found for class java.lang.Object

    Spring MVC 解决 Could not write JSON: No serializer found for class java.lang.Object 资料参考:http://stack ...

  9. Pytest - 使用介绍

    1. 概述 pytest是一个非常成熟的全功能的Python测试框架,主要特点有以下几点: 1.简单灵活,容易上手,文档丰富: 2.支持参数化,可以细粒度地控制要测试的测试用例: 3.能够支持简单的单 ...

  10. 洛谷P1488 肥猫的游戏 题解 博弈论入门

    题目链接:https://www.luogu.org/problem/P1488 其实这道题目我只需要 \(n\) 以及黑色三角形的三个端点编号就可以了. 我们假设在一个 \(n\) 边形中,黑色三角 ...