mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-06-23 15:30:34 -04:00
Swagger: Creating a basic security definition
This commit is contained in:
parent
9fded9e4a2
commit
4791736019
@ -52,41 +52,61 @@ namespace Kyoo.Swagger
|
|||||||
public void Configure(IServiceCollection services)
|
public void Configure(IServiceCollection services)
|
||||||
{
|
{
|
||||||
services.AddTransient<IApplicationModelProvider, GenericResponseProvider>();
|
services.AddTransient<IApplicationModelProvider, GenericResponseProvider>();
|
||||||
services.AddOpenApiDocument(options =>
|
services.AddOpenApiDocument(document =>
|
||||||
{
|
{
|
||||||
options.Title = "Kyoo API";
|
document.Title = "Kyoo API";
|
||||||
// TODO use a real multi-line description in markdown.
|
// TODO use a real multi-line description in markdown.
|
||||||
options.Description = "The Kyoo's public API";
|
document.Description = "The Kyoo's public API";
|
||||||
options.Version = "1.0.0";
|
document.Version = "1.0.0";
|
||||||
options.DocumentName = "v1";
|
document.DocumentName = "v1";
|
||||||
options.UseControllerSummaryAsTagDescription = true;
|
document.UseControllerSummaryAsTagDescription = true;
|
||||||
options.GenerateExamples = true;
|
document.GenerateExamples = true;
|
||||||
options.PostProcess = postProcess =>
|
document.PostProcess = options =>
|
||||||
{
|
{
|
||||||
postProcess.Info.Contact = new OpenApiContact
|
options.Info.Contact = new OpenApiContact
|
||||||
{
|
{
|
||||||
Name = "Kyoo's github",
|
Name = "Kyoo's github",
|
||||||
Url = "https://github.com/AnonymusRaccoon/Kyoo"
|
Url = "https://github.com/AnonymusRaccoon/Kyoo"
|
||||||
};
|
};
|
||||||
postProcess.Info.License = new OpenApiLicense
|
options.Info.License = new OpenApiLicense
|
||||||
{
|
{
|
||||||
Name = "GPL-3.0-or-later",
|
Name = "GPL-3.0-or-later",
|
||||||
Url = "https://github.com/AnonymusRaccoon/Kyoo/blob/master/LICENSE"
|
Url = "https://github.com/AnonymusRaccoon/Kyoo/blob/master/LICENSE"
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
options.UseApiTags();
|
document.UseApiTags();
|
||||||
options.SortApis();
|
document.SortApis();
|
||||||
options.AddOperationFilter(x =>
|
document.AddOperationFilter(x =>
|
||||||
{
|
{
|
||||||
if (x is AspNetCoreOperationProcessorContext ctx)
|
if (x is AspNetCoreOperationProcessorContext ctx)
|
||||||
return ctx.ApiDescription.ActionDescriptor.AttributeRouteInfo?.Order != AlternativeRoute;
|
return ctx.ApiDescription.ActionDescriptor.AttributeRouteInfo?.Order != AlternativeRoute;
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
options.SchemaGenerator.Settings.TypeMappers.Add(new PrimitiveTypeMapper(typeof(Identifier), x =>
|
document.SchemaGenerator.Settings.TypeMappers.Add(new PrimitiveTypeMapper(typeof(Identifier), x =>
|
||||||
{
|
{
|
||||||
x.IsNullableRaw = false;
|
x.IsNullableRaw = false;
|
||||||
x.Type = JsonObjectType.String | JsonObjectType.Integer;
|
x.Type = JsonObjectType.String | JsonObjectType.Integer;
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
document.AddSecurity("Kyoo", new OpenApiSecurityScheme()
|
||||||
|
{
|
||||||
|
Type = OpenApiSecuritySchemeType.OpenIdConnect,
|
||||||
|
Description = "Kyoo's OpenID Authentication",
|
||||||
|
Flow = OpenApiOAuth2Flow.AccessCode,
|
||||||
|
Flows = new OpenApiOAuthFlows()
|
||||||
|
{
|
||||||
|
Implicit = new OpenApiOAuthFlow()
|
||||||
|
{
|
||||||
|
Scopes = new Dictionary<string, string>
|
||||||
|
{
|
||||||
|
{ "read", "Read access to protected resources" },
|
||||||
|
{ "write", "Write access to protected resources" }
|
||||||
|
},
|
||||||
|
AuthorizationUrl = "https://localhost:44333/core/connect/authorize",
|
||||||
|
TokenUrl = "https://localhost:44333/core/connect/token"
|
||||||
|
},
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user