我正在尝试为Swagger设置 SecurityDefinition
。不幸的是,当我运行应用程序时,我会遇到一个错误,说它“无法渲染此组件,请参阅控制台”,“授权”按钮应该在哪里。
关于这个问题有很多帖子,但是我还没有找到任何解决问题的信息。奇怪的部分是它似乎已连接到 SecuritySchemeType
。因为此代码实际上渲染了按钮(但由于错误的类型,它实际上无法授权):
options.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
{
Type = SecuritySchemeType.Http,
In = ParameterLocation.Header,
Scheme = "Bearer"
});
这正确呈现“授权”按钮:
png“ rel =” nofollow noreferrer“>
oauth2 虽然...
options.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
{
Type = SecuritySchemeType.OAuth2, // Now the button does not render anymore
In = ParameterLocation.Header,
Scheme = "Bearer"
});
...现在给出以下错误:
< img src =“ https://i.sstatic.net/hypru.png” alt =“错误消息的屏幕截图“无法渲染此组件,请参见console&quort&quort&quort&quort;>
SecuritySchemeType
会影响“身份验证”按钮的渲染?我该怎么做才能解决?
I am trying to set up a SecurityDefinition
for Swagger. Unfortunately, when I run my app, I get an error, saying that it "Could no render this component, see the console", where the "Authorize" button should be.
There are quite a few posts on this issue, but I haven't found any which solved the problem for me. The odd part is that it seems to be connected to the SecuritySchemeType
. Because this code actually renders the button (but it won't actually authorize, due to being the wrong type):
options.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
{
Type = SecuritySchemeType.Http,
In = ParameterLocation.Header,
Scheme = "Bearer"
});
This correctly renders the "Authorize" button:

If I change it to OAuth2
though...
options.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
{
Type = SecuritySchemeType.OAuth2, // Now the button does not render anymore
In = ParameterLocation.Header,
Scheme = "Bearer"
});
...now it gives the following error:

How does the SecuritySchemeType
affect the rendering of the "Authenticate" button? And what can I do to fix it?
发布评论