客户端集成IdentityServer4
2024-08-29 02:46:41
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. 把当前项目也启动,进行验证 , 客户端验证整个过程没有任何毛病
最新文章
- 移动web页面前端开发总结
- 1047: 小A的计算器
- 单片机中用c编程时头文件reg51.h及reg52.h解析
- [转] Oracle analyze table 使用总结
- Android 在View中更新View
- BZOJ1107 : [POI2007]驾驶考试egz
- AE开发 入门教程
- C/C++流程图生成器 C转流程图【worldsing笔记】
- 关于在页面上执行sql语句
- HDU 5769 Substring(后缀数组)
- POJ1505&;amp;&;amp;UVa714 Copying Books(DP)
- [ACM] POJ 3259 Wormholes (bellman-ford最短路径,推断是否存在负权回路)
- Java集成开发环境--Eclipse for J2EE配置JRE运行环境
- Matlab: 路径的操作
- XP下ubuntu双系统安装方法
- Redhat5_linux 系统环境下 oracl11g的安装教程图解
- Spark多种运行模式
- JMH使用说明
- ThinkJava-新IO
- django系列5.3--ORM数据库的多表操作
热门文章
- abp 的坑
- KbmMW 4.50.00 测试版发布
- 2018.09.24 bzoj1867: [Noi1999]钉子和小球(概率dp)
- 2018.09.19 atcoder AtCoDeer and Rock-Paper(贪心)
- 2018.09.11 bzoj3629: [JLOI2014]聪明的燕姿(搜索)
- 2018.09.08 bzoj1151: [CTSC2007]动物园zoo(状压dp)
- Linux服务器部署系列之三—DNS篇
- 20155226 2016-2017-2 《Java程序设计》第7周学习总结
- ACL登陆认证
- C++虚函数表(vtbl)