Controller Plumbing
# package-development
d
So I just started to probe a bit the v14 stuff and I already feel dumb. I can't get my custom api controller return anything else then a 401 if I run it from Swagger. And I don't have a clue why. I added the Authorize attribute to the controller, I authorized the Swagger UI and then 401.. Any tips?
w
There is a fair bit of new plumbing to do David now. Take a look at Examine Peek as it’s pretty simple package.
So as you can see there is quite a lot of C# data attributes to add and decorate
Then I have this for my composer that configures the OpenAPI spec doc to show in Swagger. https://github.com/warrenbuckley/Examine-Peek/blob/main/ExaminePeek/Composers/ExaminePeekComposer.cs
But looks like the docs got way more expanded upon recently @User https://docs.umbraco.com/umbraco-cms/tutorials/creating-a-backoffice-api
Had to do a lot of guess work and reading source code but this looks to take you through all the steps
d
Ha the options.OperationFilter(); did the trick. But for that to work you're not allowed to mark your controllers with ProducesResponseType(404) as the filter does the same. Which then causes a 500 error
Thanks @Warren Buckley for the sample. That helped πŸ™‚
And I guess I should have another go at the docs πŸ˜›
w
Yeh the OperationFilter was the part of the puzzle that I was missing for ages.
That is the final part of the glue to ensure auth works correctly AFAIK
Seeing you tomorrow at CG 90s party?
d
Sadly not. This year only having a virtual attendance. 😦
w
Ah shame well happy hacking and hopefully catch you at the next thing
2 Views