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. 把当前项目也启动,进行验证 , 客户端验证整个过程没有任何毛病

最新文章

  1. 移动web页面前端开发总结
  2. 1047: 小A的计算器
  3. 单片机中用c编程时头文件reg51.h及reg52.h解析
  4. [转] Oracle analyze table 使用总结
  5. Android 在View中更新View
  6. BZOJ1107 : [POI2007]驾驶考试egz
  7. AE开发 入门教程
  8. C/C++流程图生成器 C转流程图【worldsing笔记】
  9. 关于在页面上执行sql语句
  10. HDU 5769 Substring(后缀数组)
  11. POJ1505&&UVa714 Copying Books(DP)
  12. [ACM] POJ 3259 Wormholes (bellman-ford最短路径,推断是否存在负权回路)
  13. Java集成开发环境--Eclipse for J2EE配置JRE运行环境
  14. Matlab: 路径的操作
  15. XP下ubuntu双系统安装方法
  16. Redhat5_linux 系统环境下 oracl11g的安装教程图解
  17. Spark多种运行模式
  18. JMH使用说明
  19. ThinkJava-新IO
  20. django系列5.3--ORM数据库的多表操作

热门文章

  1. abp 的坑
  2. KbmMW 4.50.00 测试版发布
  3. 2018.09.24 bzoj1867: [Noi1999]钉子和小球(概率dp)
  4. 2018.09.19 atcoder AtCoDeer and Rock-Paper(贪心)
  5. 2018.09.11 bzoj3629: [JLOI2014]聪明的燕姿(搜索)
  6. 2018.09.08 bzoj1151: [CTSC2007]动物园zoo(状压dp)
  7. Linux服务器部署系列之三—DNS篇
  8. 20155226 2016-2017-2 《Java程序设计》第7周学习总结
  9. ACL登陆认证
  10. C++虚函数表(vtbl)