Swagger 应用程序现在是 clientCredentials
Swagger application is now clientCredentials
在NetCore代码中使用swagger 2,我不明白如何使用应用程序流程(使用client-id和client-secret)
在官方文档 (https://swagger.io/docs/specification/authentication/) 中我发现了这个:
OAuth 2 flows were renamed to match the OAuth 2 Specification:
accessCode is now authorizationCode, and application is now
clientCredentials.
但是不行
// Activate swagger json file generation
services.AddSwaggerGen(
options =>
{
var scheme = new OAuth2Scheme
{
Type = "oauth2",
Flow = "clientCredentials",
AuthorizationUrl = "https://fs.xxx.com/adfs/oauth2/authorize",
TokenUrl = "https://fs.xxx.com/adfs/oauth2/token",
};
options.AddSecurityDefinition("oauth2", scheme);
options.AddSecurityRequirement(new Dictionary<string, IEnumerable<string>>
{
{ "oauth2", Array.Empty<string>() }
});
我不明白...这个文档是最新的吗?
您链接到的文档是针对 OpenAPI 3.0 的,但是您使用的是 Swashbuckle,它使用 OpenAPI 2.0。安全定义的 OpenAPI 2.0 规范在这里:
https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#security-scheme-object
这就是为什么代码需要 OpenAPI 2.0 中使用的 OAuth 流名称(在本例中为 application
)而不是 OpenAPI 3.0 中使用的名称(clientCredentials
)。
在NetCore代码中使用swagger 2,我不明白如何使用应用程序流程(使用client-id和client-secret)
在官方文档 (https://swagger.io/docs/specification/authentication/) 中我发现了这个:
OAuth 2 flows were renamed to match the OAuth 2 Specification: accessCode is now authorizationCode, and application is now clientCredentials.
但是不行
// Activate swagger json file generation
services.AddSwaggerGen(
options =>
{
var scheme = new OAuth2Scheme
{
Type = "oauth2",
Flow = "clientCredentials",
AuthorizationUrl = "https://fs.xxx.com/adfs/oauth2/authorize",
TokenUrl = "https://fs.xxx.com/adfs/oauth2/token",
};
options.AddSecurityDefinition("oauth2", scheme);
options.AddSecurityRequirement(new Dictionary<string, IEnumerable<string>>
{
{ "oauth2", Array.Empty<string>() }
});
我不明白...这个文档是最新的吗?
您链接到的文档是针对 OpenAPI 3.0 的,但是您使用的是 Swashbuckle,它使用 OpenAPI 2.0。安全定义的 OpenAPI 2.0 规范在这里:
https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#security-scheme-object
这就是为什么代码需要 OpenAPI 2.0 中使用的 OAuth 流名称(在本例中为 application
)而不是 OpenAPI 3.0 中使用的名称(clientCredentials
)。