源码下载

一.添加服务端的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登录中心的更多相关文章

  1. ASP.NET Core分布式项目-2.oauth密码模式identity server4实现

    源码下载 这里根据<ASP.NET Core分布式项目-1.IdentityServer4登录中心>的代码来继续更新oauth密码模式,这里的密码模式比上次的客户端模式更安全 在WebAp ...

  2. ASP.NET Core分布式项目实战

    ASP.NET Core开发者成长路线图 asp.net core 官方文档 https://docs.microsoft.com/zh-cn/aspnet/core/getting-started/ ...

  3. 【笔记目录2】ASP.NET Core分布式项目实战

    当前标签: ASP.NET Core分布式项目实战 共2页: 上一页 1 2  11.ClientCredential模式总结 GASA 2019-03-11 12:59 阅读:26 评论:0 10. ...

  4. 【笔记目录1】ASP.NET Core分布式项目实战

    当前标签: ASP.NET Core分布式项目实战 共2页: 1 2 下一页  35.Docker安装Mysql挂载Host Volume GASA 2019-06-20 22:02 阅读:51 评论 ...

  5. ASP.NET Core分布式项目实战-目录

    前言 今年是2018年,发现已经有4年没有写博客了,在这4年的时光里,接触了很多的.NET技术,自己的技术也得到很大的进步.在这段时光里面很感谢张队长以及其他开发者一直对.NET Core开源社区做出 ...

  6. 【ASP.NET Core分布式项目实战】(三)整理IdentityServer4 MVC授权、Consent功能实现

    本博客根据http://video.jessetalk.cn/my/course/5视频整理(内容可能会有部分,推荐看源视频学习) 前言 由于之前的博客都是基于其他的博客进行开发,现在重新整理一下方便 ...

  7. 【ASP.NET Core分布式项目实战】(一)IdentityServer4登录中心、oauth密码模式identity server4实现

    本博客根据http://video.jessetalk.cn/my/course/5视频整理 资料 OAuth2 流程:http://www.ruanyifeng.com/blog/2014/05/o ...

  8. 【ASP.NET Core分布式项目实战】(二)oauth2 + oidc 实现 server部分

    本博客根据http://video.jessetalk.cn/my/course/5视频整理(内容可能会有部分,推荐看源视频学习) 资料 我们基于之前的MvcCookieAuthSample来做开发 ...

  9. 【ASP.NET Core分布式项目实战】(六)Gitlab安装

    Gitlab GitLab是由GitLabInc.开发,使用MIT许可证的基于网络的Git仓库管理工具,且具有wiki和issue跟踪功能.使用Git作为代码管理工具,并在此基础上搭建起来的web服务 ...

随机推荐

  1. case设计及验证:入口+页面+展示

    测试个性CB问题, 功能整体结构为:入口+页面+展示 总结: 1. 产品文档为主,其次是服务端接口返回.数据结构及字段值确认.结合实际场景检查是否有遗漏或不合理. 2. 以字段为维度,每个字段的检查点 ...

  2. webpack介绍和使用

    一webpack介绍1由来2介绍3作用4拓展说明5webpack整体认知二webpack安装1安装node2安装cnpm3安装nrm的两种方法4安装webpack三webpack配置0搭建项目结构1初 ...

  3. [Oracle] Oracle中和MySql的limit对应的方法

    MySql很贴心,有个限制范围查询的limit函数,用起来也很方便,SQL不用嵌套.如下: select id,name,age,cdate as ctime from emp order by id ...

  4. Android:ART 优化配置(Mstar-6A648)

    1.Android预优化的原理 先来回顾一下Android的发展史,在2014年的Google I/O大会上,Google隆重的发布了Android 4.4操作系统,其中有一个环节着重介绍了ART(A ...

  5. angular 中父子路由

    1. 创建组件引入组件 import { NewsaddComponent } from './components/newsadd/newsadd.component'; import { News ...

  6. HTML5 地理位置定位API(5)

    HTML5 Geolocation API (地理位置应用程序接口) 目前PC浏览器支持情况: Firefox 3.5+Chrome 5.0+Safari 5.0+Opera 10.60+Intern ...

  7. Linux -- GCC Built-in functions for atomic memory access

    下列内建函数旨在兼容Intel Itanium Processor-specific Application Binary Interface, section 7.4. 因此,这些函数区别于普通的G ...

  8. LeetCode_169. Majority Element

    169. Majority Element Easy Given an array of size n, find the majority element. The majority element ...

  9. eclipse spring3.X redis 整合-配置

    花了一天时间折腾redis的配置 用到的jar spring 3.1.1 aopalliance-1.0.jar commons-pool2-2.3.jar jedis-2.7.2.jar sprin ...

  10. 实现下拉弹出视图和Block的简单实现

    实现效果如下: 实现代码如下: @interface ViewController ()<UIViewControllerTransitioningDelegate> { UILabel ...