DEV Community

Kevin Jump
Kevin Jump

Posted on

Umbraco 14 - "Authing" your extensions.

We covered how to get Umbraco 14, Front->Backend Authentication working in our Umbraco Early Adopters series, in that we suggested you can add the auth code to your context(s) to ensure your instance of the openAPI model matches.

But in conversation with quite a few people, both in the community and the core team, esp. @mattbrailsford & @iovergaard , its certainly neater, cleaner, and better to put this in your entry point. then it happens once, for all your extension/contexts, and it happens when everything is loaded.

So. as an example, entry point we know have:

import { UmbEntryPointOnInit }
  from '@umbraco-cms/backoffice/extension-api';
import { UMB_AUTH_CONTEXT } 
  from '@umbraco-cms/backoffice/auth';
import { OpenAPI } 
  from './api/index.ts';

// load up the manifests here.
import { manifests as dashboardManifests }
  from './dashboards/manifest.ts';

export const onInit: UmbEntryPointOnInit 
   = (_host, extensionRegistry) => 
{

    // register manifests here. 
    extensionRegistry.registerMany([
        ...dashboardManifests,
    ]);

    // setup OpenAPI Token here
    _host.consumeContext(UMB_AUTH_CONTEXT, (_auth) => {
        const umbOpenApi = _auth.getOpenApiConfiguration();
        OpenAPI.BASE = umbOpenApi.base;
        OpenAPI.TOKEN = umbOpenApi.token;
        OpenAPI.WITH_CREDENTIALS = umbOpenApi.withCredentials;
        OpenAPI.CREDENTIALS = umbOpenApi.credentials;
    });

};
Enter fullscreen mode Exit fullscreen mode

Top comments (0)