Kevin Jump
01/30/2024, 2:56 PM[Authorize(Policy = "New" + AuthorizationPolicies.BackOfficeAccess)]
tag is removed from the controller (so it has no auth!).
put it on, and the dashboard, does 'your session has expired'
I have gone down the road of replicating some of the extra swagger stuff from the core, https://github.com/KevinJump/TimeDashboard/blob/master/TimeDashboard.Client/Configuration/ConfigureSwaggerGenOptions.cs
(replacing the filters with ones that look for 'time' instead of 'management' for the API)
but i suspect i am either missing something obvious,
or this isn't the way to do this.
anyone, any clues ?
https://cdn.discordapp.com/attachments/1201903877721698395/1201903878304714783/image.png?ex=65cb8336&is=65b90e36&hm=61812c01435b7be7c7e3caf50ff9c27311838a80170d47d6158af10249b1c541&Nikcio
01/30/2024, 3:19 PMNikcio
01/30/2024, 3:20 PMKevin Jump
01/30/2024, 3:26 PMKevin Jump
01/30/2024, 4:00 PMcs
private static void CreatePolicies(AuthorizationOptions options,
string BackofficeAuthenticationScheme = Constants.Security.BackOfficeAuthenticationType)
{
options.AddPolicy(TimeAuthorizationPolicies.TimeDashboardAccess, policy =>
{
policy.AuthenticationSchemes.Add(BackofficeAuthenticationScheme);
policy.Requirements.Add(new BackOfficeRequirement());
});
}
attaching it to the head of the controller
cs
[ApiController]
[VersionedApiBackOfficeRoute("time")]
[Authorize(Policy = TimeAuthorizationPolicies.TimeDashboardAccess)]
[MapToApi("time")]
[JsonOptionsName("time")]
public class TimeDashboardControllerBase
gets me the login screen returned via the callD_Inventor
01/30/2024, 4:03 PM$http
service was loaded with an antiforgery token by the core. I would guess there is something similar in the new backoffice?Kevin Jump
01/30/2024, 4:08 PMD_Inventor
01/30/2024, 4:10 PMD_Inventor
01/30/2024, 4:11 PMKevin Jump
01/30/2024, 4:37 PMts
this.consumeContext(UMB_AUTH_CONTEXT, (_auth) => {
OpenAPI.TOKEN = ()=> _auth.getLatestToken();
OpenAPI.WITH_CREDENTIALS = true;
});
then this all works with the 'standard` Polices (no need to create your own etc)D_Inventor
01/30/2024, 4:38 PMCorné Hoskam
01/31/2024, 7:59 AMJacob Overgaard
01/31/2024, 8:08 AMOpenAPI
object be generally available to use for your own controllers. That would work if you use the same generator as we do in the backoffice source. Then we'd already have configured it globally for you.
If you use another generator, or you use something like the named API option from ours, or maybe you want to make a standard Fetch request, you can always consume UMB_AUTH_CONTEXT
and call the getLatestToken()
method.Jacob Overgaard
01/31/2024, 8:09 AMKevin Jump
01/31/2024, 8:49 AMKevin Jump
01/31/2024, 8:52 AMcore
folder to change that you would have to go into all of the auto generated files and change the references,
personally i wouldn't want to touch those files as i want to be able to regenerate them whenever the api changes - and i would likey forget.
so it seems like duplication, but actually i would guess its better to let the tool generate it's code and then insert these values into config from the auth context ??Jacob Overgaard
01/31/2024, 8:54 AMOpenAPI = window.umbraco.OpenAPI
and you would have the baseURL and token set up for youJacob Overgaard
01/31/2024, 8:55 AMJacob Overgaard
01/31/2024, 8:56 AMJacob Overgaard
01/31/2024, 8:58 AMbaseURL
option in the authentication section on your blog series...? It's not a big deal, but if you wanted to host the backoffice client somewhere else, you wouldn't be able to call the server since it's no longer relative to your client. We use it extensively since our Vite dev server runs on another portJacob Overgaard
01/31/2024, 8:58 AMBASE
not baseURL
Kevin Jump
01/31/2024, 9:06 AMgetOpenApiConfig
or something)
because then i could get it from there and if the method for calculating the base url ever changed in the core i would be using the same value. 👍Jacob Overgaard
01/31/2024, 9:07 AMJacob Overgaard
01/31/2024, 9:07 AMJacob Overgaard
01/31/2024, 9:47 AMJacob Overgaard
01/31/2024, 9:48 AMjs
import { OpenAPI } from '@umbraco-cms/backoffice/backend-api';
Kevin Jump
01/31/2024, 10:01 AMJacob Overgaard
01/31/2024, 10:04 AMjs
import { OpenAPI } from './your-own-generated-code'
import { OpenAPI as umbracoOpenAPI } from '@umbraco-cms/backoffice/backend-api'
OpenAPI = umbracoOpenAPI
Kevin Jump
01/31/2024, 10:13 AM@umbraco-cms/backoffice/external/backend-api
?
anyway, you can't assign it 😦
https://cdn.discordapp.com/attachments/1201903877721698395/1202195037287616542/image.png?ex=65cc9260&is=65ba1d60&hm=c55edd1522dcc0c543e5a4225334df01e964fdaf9f80293cc6d87927fc2e7096&Kevin Jump
01/31/2024, 10:14 AMOpenAPI.TOKEN = umbracoOpenAPI.TOKEN;
OpenAPI.BASE = umbracoOpenAPI.BASE;
OpenAPI.WITH_CREDENTIALS = umbracoOpenAPI.WITH_CREDENTIALS;
Kevin Jump
01/31/2024, 10:18 AMKevin Jump
01/31/2024, 10:20 AMJacob Overgaard
01/31/2024, 10:24 AMJacob Overgaard
01/31/2024, 10:27 AMKevin Jump
01/31/2024, 10:51 AMJacob Overgaard
01/31/2024, 12:53 PMSebastiaan
02/01/2024, 12:27 PMA hub and casual space for you to interact with fellow community members and learn more about Umbraco!
Powered by