源码下载

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

在WebApiIdentityServer服务端的config里添加用户

 public class config
{
//IdentityServer配置——用户
//IdentityServer用户-这里通过提供一个简单的C#类完成,
//当然你可以从任何数据存储加载用户。
//我们提供了ASP.NET Identity 和MembershipReboot支持检索用户信息。
public static IEnumerable<ApiResource> GetResources()
{
return new List<ApiResource> { new ApiResource("api","MQapi")};
} //IdentityServer需要一些关于客户端信息,这可以简单地提供使用客户端对象
public static IEnumerable<Client> GetClients()
{
return new List<Client>
{
new Client()
{
ClientId="ClientId",
AllowedGrantTypes=GrantTypes.ClientCredentials,//客户端模式
ClientSecrets={ new Secret("secrt".Sha256())},
AllowedScopes={ "api"}
},
new Client()
{
ClientId="pwdClient",
AllowedGrantTypes=GrantTypes.ResourceOwnerPassword,//密码模式
ClientSecrets={ new Secret("secrt".Sha256())},
RequireClientSecret=false,
AllowedScopes={ "api"}
}
};
} //模拟用户
public static List<TestUser> GetTsetUsers()
{
return new List<TestUser>{
new TestUser{
SubjectId="1",
Username="MQ",
Password="123456"
}
};
}
}

  然后再去配置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()
.AddInMemoryApiResources(config.GetResources())
.AddInMemoryClients(config.GetClients())
.AddTestUsers(config.GetTsetUsers()); 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();
}
}

  运行WebApiIdentityServer 和 ClientCredentialApi测试下 dotnet watch run

打开 paotman

拿到token后 去访问ClientCredentialApi

修改token看看

ASP.NET Core分布式项目-2.oauth密码模式identity server4实现的更多相关文章

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

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

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

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

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

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

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

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

  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分布式项目实战】(五)Docker制作dotnet core控制台程序镜像

    Docker制作dotnet core控制台程序镜像 基于dotnet SDK 新建控制台程序 mkdir /home/console cd /home/console dotnet new cons ...

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

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

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

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

随机推荐

  1. Centos 7设置静态IP,修改时区,关闭防火墙

    Centos 7设置静态IP # vi /etc/sysconfig/network-scripts/ifcfg-enxxx BOOTPROTO="static" ...... I ...

  2. elasticsearch java插入索引批量操作

    1.单条所以插入//第一个参数:索引名:第二个参数:索引类型:第三个参数:索引ID(相同的id时修改数据,默认为随机字符串)IndexResponse indexResponse = client.p ...

  3. AHOI2012树屋阶梯

    这玩意不是卡特兰的经典模型吗…… 我们设方案数为f(i),则f(0)=1,f(1)=1,f(2)=2,f(3)=5,(其实到这里你再手模一个就出来了)我们把左上角的矩形删掉,则会变成下方和右方两个更小 ...

  4. SSM整合小结

    基本环境搭建 pom依赖 <dependencies> <!--Junit--> <dependency> <groupId>junit</gro ...

  5. Qt 中 Oracle 数据库 QOCI 驱动问题及解决

    Qt 中 Oracle 数据库 QOCI 驱动问题及解决是本文要讲述的问题,用Qt开发Oracle程序时,常会遇到QOCI驱动问题,主要表现为程序运行时出现下面的错误. QOCI driver not ...

  6. git常见问题之git pull时Please specify which branch you want to merge with.

    $ git pull时遇到如下提示 $ git pull warning: no common commits remote: Counting objects: 5, done. remote: C ...

  7. Linux -- Proactor(及其与Reactor的比较)

    高并发服务器常由多线程+IO复用服务器(one event loop per thread) 两种I/O多路复用模式:Reactor和Proactor 一般地,I/O多路复用机制都依赖于一个事件多路分 ...

  8. vs2015配置link.exe环境变量

    https://www.cnblogs.com/johnwii/p/4966086.html

  9. 完全解读 margin 标签

    你真的了解margin吗?你知道margin有什么特性吗?你知道什么是垂直外边距合并?margin在块元素.内联元素中的区别?什么时候该用 padding而不是margin?你知道负margin吗?你 ...

  10. 【Leetcode_easy】696. Count Binary Substrings

    problem 696. Count Binary Substrings 题意:具有相同个数的1和0的连续子串的数目: solution1:还不是特别理解... 遍历元数组,如果是第一个数字,那么对应 ...