客户端集成IdentityServer4
1. vs code 终端执行 dotnet new webapi --name ClientCredentialApi
2. 找到ValuesController.cs
引用 using Microsoft.AspNetCore.Authorization;
[Authorize]
[Route("api/[controller]")]
[ApiController]
public class ValuesController : ControllerBase
{
}
3. Nuget 导入 IdentityServer4.AccessTokenValidation
4. 修改 Startup.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options; namespace ClientCredentialApi
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
} public IConfiguration Configuration { get; } // This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{ //注册Authentication
services.AddAuthentication("Bearer").AddIdentityServerAuthentication(options =>
{
options.Authority = "https://localhost:5000";
options.RequireHttpsMetadata = false;
options.ApiName = "api";
}); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
} // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseHsts();
} app.UseHttpsRedirection(); app.UseAuthentication(); app.UseMvc();
}
}
}
5. 启动 " IdentityServer4 登陆中心服务 " ,使用PostMan 调用 http://localhost:5003/connect/token
参数
client_id:client
client_secret:secrt
grant_type:client_credentials
6. 把当前项目也启动,进行验证 , 客户端验证整个过程没有任何毛病
客户端集成IdentityServer4的更多相关文章
- 09.客户端集成IdentityServer
09.客户端集成IdentityServer 新建API的项目 dotnet new webapi --name ClientCredentialApi 在我们上一节课的代码IdentityServe ...
- Envoy实现.NET架构的网关(四)集成IdentityServer4实现OAuth2认证
什么是OAuth2认证 简单说,OAuth 就是一种授权机制.数据的所有者告诉系统,同意授权第三方应用进入系统,获取这些数据.系统从而产生一个短期的进入令牌(token),用来代替密码,供第三方应用使 ...
- 环信 之 iOS 客户端集成四:集成UI
在Podfile文件里加入 pod 'EaseUI', :git => 'https://github.com/easemob/easeui-ios-cocoapods.git' 然后在终端中的 ...
- Asp.NetCoreWebApi图片上传接口(二)集成IdentityServer4授权访问(附源码)
写在前面 本文地址:http://www.cnblogs.com/yilezhu/p/9315644.html 作者:yilezhu 上一篇关于Asp.Net Core Web Api图片上传的文章使 ...
- [置顶] ZK高级特性:Style定制与客户端集成
1.ZK与传统MVC框架的集成 由于ZK应用本质上也是基于标准Web技术Servlet框架,因此与其它MVC框架的集成没有什么特别的, 以一个典型场景为例——为一个现有的Web项目(前端采用WebWo ...
- 携程apollo系列-客户端集成
本文讲解如何在 Java 程序中集成 Apollo 配置, 主要涉及到一些基础用法. 对于一些高级用法, 比如如何加密/解密配置项 (可用于数据库密码配置), 如何动态切换数据源地址,如何动态切换日志 ...
- spark-sql(spark sql cli)客户端集成hive
1.安装hadoop集群 参考:http://www.cnblogs.com/wcwen1990/p/6739151.html 2.安装hive 参考:http://www.cnblogs.com/w ...
- .net core Identity集成IdentityServer4 (1)基本操作
一. 新建asp.net core identity项目 新建项目->asp.net core web应用程序-> web应用程序(模型视图控制器)&更改身份验证为个人. 新建一个 ...
- C# Thrift 实战开发 从PLC到Thrift再到客户端集成开发
About Thrift: 本文并不是说明Thrift设计及原理的,直接拿Thrift来开发一个Demo程序,如果想要了解Thrift的细节,可以访问官方网站:https://thrift.apach ...
随机推荐
- CSV 文件
CSV 文件 CSV(Comma Separated Values 逗号分隔值) 是一种文件格式(如.txt..doc等),也可理解 .csv 文件就是一种特殊格式的纯文本文件.即是一组字符序列,字符 ...
- DB2 like两个表的字段或like一个变量
DB2中的like的使用是有限制的,它后面不能跟一个变量或者是字段,因此,在存储过程或SQL语句中就不能like一个变量或一个字段. 比如有两个表A(a,b,c,d),B(a,b,c,d). 普遍的用 ...
- vertical-align和text-align
vertical-align只适用于内联元素. 垂直对齐:vertical-align属性(转) 行高与单行纯文字的垂直居中,而如果行内含有图片和文字,在浏览器内浏览时,读者可以发现文字和图片在垂直方 ...
- 645. Set Mismatch
static int wing=[]() { std::ios::sync_with_stdio(false); cin.tie(NULL); ; }(); class Solution { publ ...
- tp5自动生成目录
1.// 定义应用目录 define('APP_PATH', __DIR__ . '/../application/'); // 加载框架引导文件 require __DIR__ . '/../thi ...
- EXT combobox 二级连动 清空store缓存数据
项目中有这样的一个需求,做一个连动操作,如图: 所属行业中的combobox中下拉框中的值会根据前一个选择框中的值动态去变化,这个其实非常好做,但不是我现在讨论的主要问题,主要问题是,当第二次选择了& ...
- java.lang.ExceptionInInitializerError Caused by: org.hibernate.InvalidMappingException: Unable to read XML
此错误是说无法读取你的xml文档,于是我们就该去更改xml文档,因为我是自动生成的,所以我找了一份之前手写的,发现是dtd错了,把之前的dtd拷贝过来之后程序就测试通过了
- cmake-file
file: File manipulation command. file(WRITE filename "message to write"... ) file(APPEND f ...
- php读取用友u8客户档案
include('../common/conn.php'); $list=[]; $sql="SELECT a.cCusCode,a.cCusName,b.cCCName,a.cCusDep ...
- authentication 和 authorization
单词 词性 解释 authentication n. 认证 authentic adj. 真实的 authorization n. 授权 authorise vt. 授权 authentication ...