首页 > 其他 > 详细

IdentityServer

时间:2021-01-16 01:13:03      阅读:37      评论:0      收藏:0      [点我收藏+]

1、创建一个ASP.NET Core空项目

2、创建一个Config类

using IdentityServer4.Models;
using System.Collections.Generic;

namespace Sample
{
    public static class Config
    {
        public static IEnumerable<ApiScope> ApiScopes => new ApiScope[]
        {
            new ApiScope{Name="sample_api",DisplayName="Sample Api"},
            new ApiScope{Name="scope2",DisplayName="Scope"}
        };
        public static IEnumerable<Client> Clients => new Client[]
        {
            new Client
            {
                ClientId="sample_Client",
                ClientName="Client Credentials Client",  //客户端名称
                AllowedGrantTypes=GrantTypes.ClientCredentials,//客户端验证(验证模式)
                ClientSecrets={new Secret("511536EF-F270-4058-80CA-1C89C192F69A".Sha256())},
                AllowedScopes={ "sample_api" } //访问资源范围
            }
        };
    }
}

3、配置服务和管道,IdentityServer4采用的中间件形式,必须进行管道配置

1)添加服务

        public void ConfigureServices(IServiceCollection services)
        {
            var builder= services.AddIdentityServer();//添加服务
            builder.AddDeveloperSigningCredential();//配置开发验证模式
            builder.AddInMemoryApiScopes(Config.ApiScopes);//配置内存API资源形式
            builder.AddInMemoryClients(Config.Clients);//配置内存客户端访问形式
        }

 

2)注册应用

        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseIdentityServer();
        }

4、测试https://localhost:5001/.well-known/openid-configuration进行GET请求,查看

技术分享图片

 

 

 2)使用https://localhost:5001/connect/token获取token

技术分享图片

 

 

 3)token为jwt加密,解析查看

技术分享图片

 

IdentityServer

原文:https://www.cnblogs.com/CelonY/p/14284389.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!