I'm going my first steps with Umbraco 15. What I want to achieve is getting and calling a backoffice api controller like it was possible with UmbracoAuthorizedApiController in the past.
I learned, that the APIs now have the route /umbraco/management/api/v1/ plus some additional route segments. I can't manage to get a simple controller done. Consider the following code:
[VersionedApiBackOfficeRoute("laykit/environment")]
[ApiVersion("1.0")]
public class EnvironmentController : ManagementApiControllerBase
{
[HttpGet]
public string Get()
{
return "Teststring";
}
}
What is the right route to call this API from my backoffice extension? Is the above definition false? This would be the client code:
I tried with and without the get segment, it doesn't work. What I also want to achieve is, that the backoffice login should be sufficient to be authorized to all this api.
Do you have any insights to share, which makes this working?
Here is my simple backoffice controller for my custom section.
[ApiController]
[BackOfficeRoute("api/v{version:apiVersion}/[controller]")]
[Authorize(Policy = AuthorizationPolicies.BackOfficeAccess)]
[MapToApi("ich")]
public class BackOfficeControllerBase : ControllerBase
{ }
You need some other configuration to make it work.
public class IchBackofficeApiOperationSecurityFilter : BackOfficeSecurityRequirementsOperationFilterBase
{
protected override string ApiName => "ich";
}
Your swagger config if you need it
internal class ConfigureBackofficeSwaggerGenOptions : IConfigureOptions<SwaggerGenOptions>
{
public void Configure(SwaggerGenOptions options)
{
options.SwaggerDoc(
"ich",
new Microsoft.OpenApi.Models.OpenApiInfo
{
Title = "Ich Backoffice Api",
Version = "1.0",
Description = "Ich backoffice Api"
});
options.OperationFilter<IchBackofficeApiOperationSecurityFilter>();
var schemaHelper = new SwashbuckleSchemaHelper();
options.CustomSchemaIds(type => schemaHelper.GetSchemaId(type));
//options.OperationFilter<TimeBackOfficeSecurityRequirementsOperationFilter>();
}
}
And a composer
public class IchApiComposer : IComposer
{
public void Compose(IUmbracoBuilder builder)
{
builder.Services.ConfigureOptions<ConfigureBackofficeSwaggerGenOptions>();
}
}
Umbraco 15 Backoffice API
I'm going my first steps with Umbraco 15. What I want to achieve is getting and calling a backoffice api controller like it was possible with UmbracoAuthorizedApiController in the past.
I learned, that the APIs now have the route /umbraco/management/api/v1/ plus some additional route segments. I can't manage to get a simple controller done. Consider the following code:
What is the right route to call this API from my backoffice extension? Is the above definition false? This would be the client code:
I tried with and without the get segment, it doesn't work. What I also want to achieve is, that the backoffice login should be sufficient to be authorized to all this api.
Do you have any insights to share, which makes this working?
Hi,
Here is my simple backoffice controller for my custom section.
You need some other configuration to make it work.
Your swagger config if you need it
And a composer
Hope it will help you.
/Yasir
is working on a reply...