1.新建项目并添加引用

新建一个asp .net core 2.0的项目
引用IdentityServer4.AccessTokenValidation

2.配置

将Api与IdentityServer服务器挂钩

public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddMvcCore()
.AddAuthorization()
.AddJsonFormatters(); services.AddAuthentication("Bearer")
.AddIdentityServerAuthentication(options =>
{
//这里添加IdentityServer服务器的地址
options.Authority = "http://localhost:5000";
options.RequireHttpsMetadata = false;
//这个Api资源的名称,注意与IdentityServer的Api资源对应
options.ApiName = "api1";
});
} public void Configure(IApplicationBuilder app)
{
app.UseAuthentication(); app.UseMvc();
}
}

3.Api接口

添加一个新的Controller,使用此控制器来测试授权要求,以及通过Api可视化声明身份

[Route("identity")]
[Authorize]
public class IdentityController : ControllerBase
{
[HttpGet]
public IActionResult Get()
{
return new JsonResult(from c in User.Claims select new { c.Type, c.Value });
}
}

4.设置Api项目的端口号为5001

最新文章

  1. BZOJ4591——[Shoi2015]超能粒子炮·改
  2. 走进spring之springmvc实战篇(二)
  3. 自然语言18_Named-entity recognition
  4. 用Dictionary代替if
  5. javascript创建对象和属性的几种方式
  6. redis maxmemory设置
  7. iOS 最值宏定义
  8. wlcore: firmware chunk too long
  9. ch5-Class 与 Style 绑定(v-bind:class v-bind:style)
  10. JavaScript练习网站收集
  11. Neo4j学习笔记(2)——数据索引
  12. python+selenium自动测试之WebDriver的常用API(基础篇一)
  13. Bootstrap 常用属性
  14. 前端请求参数MD5加密发送后台
  15. VR外包团队—国内首家VR虚拟现实主题公园即将在北京推出
  16. C# Winform 跨线程更新UI控件常用方法汇总(多线程访问UI控件)
  17. SQLServer最耗资源时间的SQL语句
  18. November 17th, 2017 Week 46th Friday
  19. PAT B1048 数字加密 (20 分)
  20. 9.9Dajngo MTV

热门文章

  1. ios开发日期的NSDate,NSCalendar分类
  2. .NET-架构优化实战-梳理篇
  3. sublime-1 sublime设置到鼠标右键
  4. 非常实用全面的 C++框架,库类等资源
  5. [Ramda] Sort, SortBy, SortWith in Ramda
  6. 【BZOJ 1017】 [JSOI2008]魔兽地图DotR
  7. Crystal Report - 水晶报表导出文件的格式设置
  8. com.sun.mirror的jar包
  9. tolua#是Unity静态绑定lua的一个解决方案
  10. 利用WPF建立自己的3d gis软件(非axhost方式)(十)SDK中一些自带的展示面板应用