V16 RC: getOpenApiConfiguration().token does not work (#19217)

This commit is contained in:
Jacob Overgaard
2025-05-06 09:43:10 +02:00
committed by GitHub
parent 6518a261f0
commit 95bfee7c63
4 changed files with 26 additions and 28 deletions

View File

@@ -250,7 +250,7 @@ export class UmbAuthContext extends UmbContextBase {
return { return {
base: config.baseUrl, base: config.baseUrl,
credentials: config.credentials, credentials: config.credentials,
token: this.getLatestToken, token: () => this.getLatestToken(),
}; };
} }

View File

@@ -9,13 +9,13 @@
"generate-client": "node scripts/generate-openapi.js https://localhost:44339/umbraco/swagger/umbracoextension/swagger.json" "generate-client": "node scripts/generate-openapi.js https://localhost:44339/umbraco/swagger/umbracoextension/swagger.json"
}, },
"devDependencies": { "devDependencies": {
"@hey-api/client-fetch": "^0.8.3", "@hey-api/client-fetch": "^0.10.0",
"@hey-api/openapi-ts": "^0.64.10", "@hey-api/openapi-ts": "^0.66.7",
"@umbraco-cms/backoffice": "^UMBRACO_VERSION_FROM_TEMPLATE", "@umbraco-cms/backoffice": "^UMBRACO_VERSION_FROM_TEMPLATE",
"chalk": "^5.4.1", "chalk": "^5.4.1",
"cross-env": "^7.0.3", "cross-env": "^7.0.3",
"node-fetch": "^3.3.2", "node-fetch": "^3.3.2",
"typescript": "^5.8.2", "typescript": "^5.8.3",
"vite": "^6.2.0" "vite": "^6.3.4"
} }
} }

View File

@@ -7,29 +7,25 @@ import {
} from "@umbraco-cms/backoffice/external/lit"; } from "@umbraco-cms/backoffice/external/lit";
import { UmbElementMixin } from "@umbraco-cms/backoffice/element-api"; import { UmbElementMixin } from "@umbraco-cms/backoffice/element-api";
import { UUIButtonElement } from "@umbraco-cms/backoffice/external/uui"; import { UUIButtonElement } from "@umbraco-cms/backoffice/external/uui";
import { import { UMB_NOTIFICATION_CONTEXT } from "@umbraco-cms/backoffice/notification";
UMB_NOTIFICATION_CONTEXT, import { UMB_CURRENT_USER_CONTEXT } from "@umbraco-cms/backoffice/current-user";
UmbNotificationContext,
} from "@umbraco-cms/backoffice/notification";
import {
UMB_CURRENT_USER_CONTEXT,
UmbCurrentUserModel,
} from "@umbraco-cms/backoffice/current-user";
import { UmbracoExtensionService, UserModel } from "../api/index.js"; import { UmbracoExtensionService, UserModel } from "../api/index.js";
@customElement("example-dashboard") @customElement("example-dashboard")
export class ExampleDashboardElement extends UmbElementMixin(LitElement) { export class ExampleDashboardElement extends UmbElementMixin(LitElement) {
@state() @state()
private _yourName: string | undefined = "Press the button!"; private _yourName?: string = "Press the button!";
@state() @state()
private _timeFromMrWolf: Date | undefined; private _timeFromMrWolf?: Date;
@state() @state()
private _serverUserData: UserModel | undefined = undefined; private _serverUserData?: UserModel;
@state() @state()
private _contextCurrentUser: UmbCurrentUserModel | undefined = undefined; private _contextCurrentUser?: typeof UMB_CURRENT_USER_CONTEXT.TYPE;
#notificationContext?: typeof UMB_NOTIFICATION_CONTEXT.TYPE;
constructor() { constructor() {
super(); super();
@@ -42,14 +38,16 @@ export class ExampleDashboardElement extends UmbElementMixin(LitElement) {
// When we have the current user context // When we have the current user context
// We can observe properties from it, such as the current user or perhaps just individual properties // We can observe properties from it, such as the current user or perhaps just individual properties
// When the currentUser object changes we will get notified and can reset the @state properrty // When the currentUser object changes we will get notified and can reset the @state properrty
this.observe(currentUserContext.currentUser, (currentUser) => { this.observe(
this._contextCurrentUser = currentUser; currentUserContext.currentUser,
}); (currentUser) => {
this._contextCurrentUser = currentUser;
},
"_contextCurrentUser"
);
}); });
} }
#notificationContext: UmbNotificationContext | undefined = undefined;
#onClickWhoAmI = async (ev: Event) => { #onClickWhoAmI = async (ev: Event) => {
const buttonElement = ev.target as UUIButtonElement; const buttonElement = ev.target as UUIButtonElement;
buttonElement.state = "waiting"; buttonElement.state = "waiting";

View File

@@ -1,4 +1,4 @@
import { import type {
UmbEntryPointOnInit, UmbEntryPointOnInit,
UmbEntryPointOnUnload, UmbEntryPointOnUnload,
} from "@umbraco-cms/backoffice/extension-api"; } from "@umbraco-cms/backoffice/extension-api";
@@ -15,12 +15,12 @@ export const onInit: UmbEntryPointOnInit = (_host, _extensionRegistry) => {
// Do the OAuth token handshake stuff // Do the OAuth token handshake stuff
_host.consumeContext(UMB_AUTH_CONTEXT, async (authContext) => { _host.consumeContext(UMB_AUTH_CONTEXT, async (authContext) => {
// Get the token info from Umbraco // Get the token info from Umbraco
const config = authContext.getOpenApiConfiguration(); const config = authContext?.getOpenApiConfiguration();
client.setConfig({ client.setConfig({
auth: config.token, auth: config?.token ?? undefined,
baseUrl: config.base, baseUrl: config?.base ?? "",
credentials: config.credentials, credentials: config?.credentials ?? "same-origin",
}); });
}); });
//#endif //#endif