ASP.NET Core分布式项目-1.IdentityServer4登录中心
一.添加服务端的api
1.添加NUGet包 IdentityServer4


点击下载,重新生成

2。添加Startup配置
打开Startup文件
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)
{
//添加依赖注入配置
services.AddIdentityServer()
.AddDeveloperSigningCredential();
services.AddMvc();
} // 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();
}
app.UseIdentityServer();
//app.UseMvc();
}
}
3.添加config配置,添加一个config类
public class config
{
public static IEnumerable<ApiResource> GetResources()
{
return new List<ApiResource> { new ApiResource("api","MQapi")};
} public static IEnumerable<Client> GetClients()
{
return new List<Client>
{
new Client()
{
ClientId="ClientId",
AllowedGrantTypes=GrantTypes.ClientCredentials,
ClientSecrets={ new Secret("secrt".Sha256())},
AllowedScopes={ "api"}
}
};
}
}
4.修改IdentityServer的配置,打开Startup文件
public void ConfigureServices(IServiceCollection services)
{
//添加依赖注入配置
services.AddIdentityServer()
.AddDeveloperSigningCredential()
.AddInMemoryApiResources(config.GetResources())
.AddInMemoryClients(config.GetClients());
services.AddMvc();
}
运行在浏览器中输入http://localhost:51227/.well-known/openid-configuration

二,添加客户端的api
添加一个api项目 ClientCredentialApi, 应用NuGet 包IdentityServer4.AccessTokenValidation
在控制器上添加[Authorize]标识。
然后在Startup文件里把认证授权添加进来
public void ConfigureServices(IServiceCollection services)
{
services.AddAuthentication("Bearer")
.AddIdentityServerAuthentication(c =>
{
c.Authority = "http://localhost:50000";
c.RequireHttpsMetadata = false;
c.ApiName = "api";
});
services.AddMvc();
}
我们用visual studio code 把两个项目打开
运行WebApiIdentityServer项目 dotnet run

打开浏览器http://localhost:50000/.well-known/openid-configuration

可以通过http://localhost:50000/connect/token 这个拿到token
打开Postman
post访问http://localhost:50000/connect/token

参数是在这里设置的

我再启动客户端

打开postMan去访问http://localhost:50001/api/values


最后一张流程图

ASP.NET Core分布式项目-1.IdentityServer4登录中心的更多相关文章
- ASP.NET Core分布式项目-2.oauth密码模式identity server4实现
源码下载 这里根据<ASP.NET Core分布式项目-1.IdentityServer4登录中心>的代码来继续更新oauth密码模式,这里的密码模式比上次的客户端模式更安全 在WebAp ...
- ASP.NET Core分布式项目实战
ASP.NET Core开发者成长路线图 asp.net core 官方文档 https://docs.microsoft.com/zh-cn/aspnet/core/getting-started/ ...
- 【笔记目录2】ASP.NET Core分布式项目实战
当前标签: ASP.NET Core分布式项目实战 共2页: 上一页 1 2 11.ClientCredential模式总结 GASA 2019-03-11 12:59 阅读:26 评论:0 10. ...
- 【笔记目录1】ASP.NET Core分布式项目实战
当前标签: ASP.NET Core分布式项目实战 共2页: 1 2 下一页 35.Docker安装Mysql挂载Host Volume GASA 2019-06-20 22:02 阅读:51 评论 ...
- ASP.NET Core分布式项目实战-目录
前言 今年是2018年,发现已经有4年没有写博客了,在这4年的时光里,接触了很多的.NET技术,自己的技术也得到很大的进步.在这段时光里面很感谢张队长以及其他开发者一直对.NET Core开源社区做出 ...
- 【ASP.NET Core分布式项目实战】(三)整理IdentityServer4 MVC授权、Consent功能实现
本博客根据http://video.jessetalk.cn/my/course/5视频整理(内容可能会有部分,推荐看源视频学习) 前言 由于之前的博客都是基于其他的博客进行开发,现在重新整理一下方便 ...
- 【ASP.NET Core分布式项目实战】(一)IdentityServer4登录中心、oauth密码模式identity server4实现
本博客根据http://video.jessetalk.cn/my/course/5视频整理 资料 OAuth2 流程:http://www.ruanyifeng.com/blog/2014/05/o ...
- 【ASP.NET Core分布式项目实战】(二)oauth2 + oidc 实现 server部分
本博客根据http://video.jessetalk.cn/my/course/5视频整理(内容可能会有部分,推荐看源视频学习) 资料 我们基于之前的MvcCookieAuthSample来做开发 ...
- 【ASP.NET Core分布式项目实战】(六)Gitlab安装
Gitlab GitLab是由GitLabInc.开发,使用MIT许可证的基于网络的Git仓库管理工具,且具有wiki和issue跟踪功能.使用Git作为代码管理工具,并在此基础上搭建起来的web服务 ...
随机推荐
- 【原】Python基础-序列
1 序列 在Python中,最基本的数据结构是序列,序列中每个元素被分配一个编号,也称为索引.第一个索引为0,第二个则是1,以此类推.序列中最后一个元素被标为-1,倒数第二个元素被标为-2,以此类推. ...
- Alpha项目冲刺! Day6-产出
各个成员今日完成的任务 林恩:任务分工,博客撰写,了解安卓环境搭建 杨长元:安卓本地数据库 李震:了解聊天类app相关内容 胡彤:完善服务端 寇永明:研究测试代码 王浩:研究测试代码 李杰:研究测试代 ...
- django + vue3 解决跨越问题
django跨域 解决: https://yq.aliyun.com/articles/517215 vue3 跨越(此处没必要,django处理即可): https://blog.csdn.net/ ...
- js学习笔记(1)
前言 因为后期的软件工程组队作业需要js,在纪华裕大佬的带领下(我觉得他好像更喜欢纪华裕这个名字),我开始了js的学习.其实这篇博客应该在两天前的晚上就发出来了,因为忙着写个人编程,拖到了现在,组 ...
- python中的with的用法,上下文管理器
with是从Python2.5引入的一个新的语法,它是一种上下文管理协议,目的在于从流程图中把 try,except 和finally 关键字和 资源分配释放相关代码统统去掉,简化try….excep ...
- Java 关于日期加一天(日期往后多一天)
1.原来Java的日期添加不像.NET的.Add: import java.util.Date ; Date date=new Date();//取时间System.out.println(dat ...
- 【scikit-learn】06:make_blobs聚类数据生成器
版权声明:本文为博主原创文章,遵循CC 4.0 by-sa版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.csdn.net/kevinelstri/article/ ...
- oracle利用触发器实现将ddl操作存入数据表中
先创建DDL数据库事件操作表: create table ddl_event( sys_time date primary key, event_name ), ), obj_type ), obj_ ...
- 关于Android studio下V4包 KeyEventCompat 类找不到问题
V4包 KeyEventCompat 类找不到问题 本文链接:https://blog.csdn.net/shanshan_1117/article/details/84344557 今天我把su ...
- Java8 新特性之Stream
1.Student package com.elk.log.myTest; public class Student implements Comparable<Student> { /* ...