源码下载

一.添加服务端的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. 微信小程序 wxParse插件显示视频

    修改wxParse/html2json.js 文件 ,在 html2json(html, bindName) 方法里 var node = { node: 'element', tag: tag, } ...

  2. nodejs做中间层,转发请求

    简述node中间层的优势 node中间层,可以解决前端的跨域问题,因为服务器端的请求是不涉及跨域的,跨域是浏览器的同源策略导致的,关于跨域可以查看跨域复习使用node坐中间层,方便前后端分离,后端只需 ...

  3. Team团队管理执行力

    执行力是什么_百度知道https://zhidao.baidu.com/question/144991863.html [图文]如何提高团队执行力 - 百度文库https://wenku.baidu. ...

  4. spring could 微服务 跨域问题(CORS )

    问题发现 正常情况下,跨域是这样的:1. 微服务配置跨域+zuul不配置=有跨域问题2. 微服务配置+zuul配置=有跨域问题3. 微服务不配置+zuul不配置=有跨域问题4. 微服务不配置+zuul ...

  5. js实现两个文本框数值的加减乘除运算

    <!DOCTYPE html><html> <head> <meta charset="utf-8"> <title>& ...

  6. 19 Flutter 自定义AppBar 定义顶部Tab切换 底部Tab结合顶部Tab实现类似头条页面布局(27分36秒)

    Flutter AppBar自定义顶部导航按钮图标.颜色以及TabBar定义顶部Tab切换. leading:在标题前面显示的一个控件,在首页通常显示应用的logo:在其他界面通常显示为付汇按钮. t ...

  7. OpenStack Heat模板详解

    Heat模板全称为heat orchestration template,简称为HOT. 1 典型Heat模板结构 heat_template_version: 2015-04-30 descript ...

  8. 《海会圣贤》高清字幕版(由香港佛陀教育协会发布DVD恭敬转成)

    常念阿彌陀佛 2015-09-22 视频(建议WIFI下收看)时长72分钟 https://v.qq.com/x/page/f0166amk57h.html 香港佛陀教育协会发布DVD   DVD+高 ...

  9. JAVA8 JVM内存结构变了,永久代到元空间

    在文章<JVM之内存结构详解>中我们描述了Java7以前的JVM内存结构,但在Java8和以后版本中JVM的内存结构慢慢发生了变化.作为面试官如果你还不知道,那么面试过程中是不是有些露怯? ...

  10. 【Leetcode_easy】788. Rotated Digits

    problem 788. Rotated Digits solution1: class Solution { public: int rotatedDigits(int N) { ; ; i< ...