【发布时间】:2022-09-30 22:52:06
【问题描述】:
不知何故,我们正在与我的同事合作的同一个项目没有调用在我的电脑上检索令牌的 http post 方法,但在我的同事电脑上工作正常。 代码是相同的,但我的输出显示了这个弹出窗口。
在我的邮递员请求中也可以正常工作
已经测试了不同的浏览器,我们已经在服务器上部署了包,并且正确地检索了令牌。在本地部署包显示相同的错误,所以我的电脑干扰了 http 请求?
任何猜测都是一种祝福
谢谢
这里有一些代码
services
.AddSwaggerGen(
(c) =>
{
var version = $\"v{Assembly.GetEntryAssembly()?.GetVersionInfo()}\";
c.OperationFilter<ChorusModeHeaderFilter>();
c.OperationFilter<AuthenticationFilter>();
c.OperationFilter<ErrorFilter>();
c.OperationFilter<MaintenanceFilter>();
c.SwaggerDoc(version, new OpenApiInfo { Title = appName, Version = version });
c.AddSecurityDefinition(
\"Bearer\",
new OpenApiSecurityScheme
{
Type = SecuritySchemeType.OpenIdConnect,
OpenIdConnectUrl = new Uri($\"../../.well-known/openid-configuration\", UriKind.Relative)
});
c.AddSecurityRequirement(
new OpenApiSecurityRequirement
{
{
new OpenApiSecurityScheme
{
Reference = new OpenApiReference
{
Type=ReferenceType.SecurityScheme,
Id=\"Bearer\"
}
},
Array.Empty<string>()
}
});
xmlDocumentationFiles
.Select((path) => Path.Combine(AppContext.BaseDirectory, path))
.ToList()
.ForEach((path) => c.IncludeXmlComments(path));
});
并且
public class AuthenticationFilter : IOperationFilter
{
public void Apply(OpenApiOperation operation, OperationFilterContext context)
{
if (!context.MethodInfo.GetCustomAttributes(true).OfType<AllowAnonymousAttribute>().Any())
{
operation.Responses.Add(
$\"{(int)HttpStatusCode.Unauthorized}\",
new OpenApiResponse { Description = \"Unauthorized\" });
}
else
{
// No authentication skip it
}
}
}
标签: asp.net postman token openid-connect swagger-ui