ASP.NETCORE OAuth之identityServer4简单实现

2024-10-11 18:50:20

1、新建ASP.NET CORE WEB空项目

ASP.NETCORE OAuth之identityServer4简单实现

2、安装identityserver4包1浏览identityserver42选择3安装

ASP.NETCORE OAuth之identityServer4简单实现

3、创建identityconfig配置帮助类using System;using System.Collect足毂忍珩ions.Generic;using System.Linq;using System.Threading.Tasks;using System.Collections;using System.Collections.Generic;using IdentityServer4.Models;namespace identityserverpeizhi{ public class IdentityConfig { //可访问的对象 public static IEnumerable<ApiResource> GetResource() { return new List<ApiResource> { new ApiResource("apiServer","apiServer") }; } public static IEnumerable<Client> GetClients() { return new List<Client> { new Client() { ClientId="clientId", AllowedGrantTypes = GrantTypes.ClientCredentials, ClientSecrets = { new Secret("secret1122".Sha512())}, AllowedScopes={ "apiServer" } //可以访问的resource } }; } }}

ASP.NETCORE OAuth之identityServer4简单实现

4、identity注入洧粽袄淖配置public void ConfigureServices(IServiceCollection services) { //依赖注入的配置 services.AddIdentityServer() .AddDeveloperSigningCredential() .AddInMemoryApiResources(IdentityConfig.GetResource()) .AddInMemoryClients(IdentityConfig.GetClients()) ; services.AddMvc(); }

ASP.NETCORE OAuth之identityServer4简单实现

5、identity管道配置 public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } //app.UseMvc(); app.UseIdentityServer(); }

ASP.NETCORE OAuth之identityServer4简单实现

6、运行完成,打开/.well-known/openid-configuration

ASP.NETCORE OAuth之identityServer4简单实现
猜你喜欢