• .net core swaggerUI 添加自定义的token 验证


    最开始用的JWT, 使用以下配置;

            //AddSwaggerGen
                    c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
                    {
                        Description = "JWT Authorization header using the Bearer scheme.",
                        Name = "Authorization",
                        In = ParameterLocation.Header,
                        Scheme = "bearer",
                        Type = SecuritySchemeType.Http,
                        BearerFormat = "JWT"
                    });
    
                    c.AddSecurityRequirement(new OpenApiSecurityRequirement
                    {
                        {
                            new OpenApiSecurityScheme
                            {
                                Reference = new OpenApiReference { Type = ReferenceType.SecurityScheme, Id = "Bearer" }
                            },
                            new List<string>()
                        }
                    });

    后续项目使用自定义的token 验证规则,使用以下配置

             //AddSwaggerGen
                    c.AddSecurityDefinition("token", new OpenApiSecurityScheme
                    {
                        Description = "header token",
                        Name = "token",
                        In = ParameterLocation.Header,
                        Scheme = "",
                        Type = SecuritySchemeType.ApiKey,//设置类型
                        BearerFormat = ""
                    });
    
                    c.AddSecurityRequirement(new OpenApiSecurityRequirement
                    {
                        {
                            new OpenApiSecurityScheme
                            {
                                Reference = new OpenApiReference { Type = ReferenceType.SecurityScheme, Id = "token" }
                            },
                            new List<string>()
                        }
                    });

    效果如下,输入你的token:

  • 相关阅读:
    html5对分辨率和设备的嗅探方法
    给前端苦手的同学们一点建议——前端之所以难学,可能的原因
    css3学习笔记
    关于viewport的一些问题
    js通过as完成socket通信
    【数学】数论常识
    AbstractFactory 模式
    State 模式
    Strategy 模式
    error LNK2001
  • 原文地址:https://www.cnblogs.com/zhanghm1/p/14850296.html
Copyright © 2020-2023  润新知