Authorisation with Back office controllers
# package-development
n
Hey everyone, so I'm working on a v14 package and I'm hitting a stumbling block that I can't seem to find the right docs to help me with. I've created a back office C# API controller with the following attribute
[Authorize(Policy = AuthorizationPolicies.BackOfficeAccess)]
My understanding is that this will protect my C# api behind the Umbraco backoffice login. I've then made sure my API controller shows in Swagger and from that generated an open-api TS client using the
@hey-api/openapi-ts
tooling. Both of these bits seem to have worked, however the issue I've got now, is that when I call my api using the ts generated client I'm getting a 401 unathorised error and my controller isn't hit at all. The error I get is in the associated image and the code that calls my TS client looks like this:
Copy code
ts
var currentNotFound = await tryExecuteAndNotify(this, PageNotFoundManagerService.getApiV1HcsGetNotFound( {pageId: this.args.unique} ));
https://cdn.discordapp.com/attachments/882984798719729704/1265423842650882209/image.png?ex=66a1754a&is=66a023ca&hm=fe470f3792748163383e005e1fa9037a41e30e24ecc550fa9ffda7bdf9471e4d&
Thank you to Kevin Jump for having this problem a while ago, and thank you to Seb for exposing Discord to Google! https://discord-chats.umbraco.com/t/16356022/solved-v14-using-custom-authenticated-controllers-with-the-n https://github.com/KevinJump/TimeDashboard/blob/5514c670020b7a17160eb790c7e7116379cc108b/TimeDashboard.Client/assets/src/index.ts#L40 These things together got me out of my jam!
7 Views