我正在尝试向swagger api添加承载身份验证,这种情况下我非常糟糕,并且我试图了解一些内容(即14 ...),情况是,我找不到ApiKeyScheme ... 有我的代码:
c.AddSecurityDefinition("Bearer",
new ApiKeyScheme { In = "header",
Description = "Please enter into field the word 'Bearer' following by space and JWT",
Name = "Authorization", Type = "apiKey" });
c.AddSecurityRequirement(new Dictionary<string, IEnumerable<string>> {
{ "Bearer", Enumerable.Empty<string>() },
});
那是我的图书馆:
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.EntityFrameworkCore;
using EdictApi.Models;
using Microsoft.OpenApi.Models;
using System;
using System.Linq;
我对此感到困惑,有人可以冷静地向我解释一下吗? :)
答案 0 :(得分:0)
c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
{
Description =
"JWT Authorization header using the Bearer scheme. \r\n\r\n Enter 'Bearer' [space] and then your token in the text input below.\r\n\r\nExample: \"Bearer 12345abcdef\"",
Name = "Authorization",
In = ParameterLocation.Header,
Type = SecuritySchemeType.ApiKey,
Scheme = "Bearer"
});
c.IncludeXmlComments($@"{AppDomain.CurrentDomain.BaseDirectory}\I.Api.xml");
c.OperationFilter<T2ParametersOperationFilter>();
c.OperationFilter<T1ParametersOperationFilter>();