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服务 ...
随机推荐
- 查看linux系统版本相关信息
1.查看内核版本:cat /proc/version A机器 root@debian:~# cat /proc/version Linux version -- (ty@debian) ( (Debi ...
- mysql和mssql数据库快速创建表格 五
* into testAAA FROM tbl_User --sqlserver方法一复制表结构 select * into testAAA FROM tbl_User --sqlserver复制表结 ...
- JAVA基础知识|synchronized和lock
一.synchronized 是jvm的一个关键字,使用过程均由jvm控制 有三种使用方式: 修饰实例方法,作用于当前实例加锁,进入同步代码前要获得当前实例的锁 修饰代码块,同方法 修饰静态方法,作用 ...
- Python 学习随笔 - 2 - list 、tuple 、dict、set 特殊数据类型 及 实际应用
1.list list是一种有序的集合,可以随时添加和删除其中的元素; 和C语言不同的地方是list里的元素甚至可以是不同类型的,甚至是另个list 例如:['A', 'B', 'C'] ['A ...
- 通过pro文件使Qt的build目录更清爽
1.指定moc存放的路径,Qt moc编译器生成的moc文件 unix:MOC_DIR = ../tmp win32:MOC_DIR = ../tmp 2.指定目标文件存放的路径,生成的dll或者ex ...
- git前期准备
git小结 设置用户名 git config –global user.name 'itcast' 设置用户名邮箱 git config –global user.email 'itcast' 查看设 ...
- Hibernate HQL和QBC
OID查询 一.什么是OID查询 根据对象的OID主键进行检索 二.OID查询方式 1. get方法 当get()方法被调用的时候就会立即发出SQL语句 并且返回的对象也是实际的对象 使用get()和 ...
- mybatis bind标签
开门见山的说,平时写模糊查询,一直用${name},例如: select * from table where name like '%${name}%' 后来知道了,这样写可能会引发sql注入,于是 ...
- Ionic4.x Javascript 扩展 ActionSheet Alert Toast Loading 以及 ionic 手势相 关事件
1.ActionSheet 官方文档:https://ionicframework.com/docs/api/action-sheet <ion-header> <ion-toolb ...
- i18n 语言码和对应的语言库
语言码 语言名称 af Afrikaans am Amharic ar Arabic az Azerbaijani be Belarusian bg Bulgarian bh Bihari bn Be ...