Add Eve access plugin and private auth plane
This commit is contained in:
parent
3b6229652b
commit
19e5109cf4
47 changed files with 1781 additions and 35 deletions
29
plugins/gamecult.heimdall.access/advertisement.json
Normal file
29
plugins/gamecult.heimdall.access/advertisement.json
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
{
|
||||
"schema": "gamecult.eve.plugin_advertisement.v1",
|
||||
"pluginId": "gamecult.heimdall.access",
|
||||
"ownerService": "asgard.heimdall",
|
||||
"version": "0.1.0",
|
||||
"manifestAddress": "cultmesh://gamecult/heimdall/plugins/access/manifest",
|
||||
"runtime": {
|
||||
"invocationModel": "executable-sidecar",
|
||||
"contract": "gamecult.eve.plugin_abi.v1",
|
||||
"transports": ["cultnet.operation.v0", "in-process-reference"],
|
||||
"authority": ["renderer-independent", "no-access-grant", "no-provider-state-mutation"],
|
||||
"sidecar": {
|
||||
"processKind": "heimdall-daemon-plugin-organ",
|
||||
"protocol": "cultnet.operation.v0",
|
||||
"requestSchema": "gamecult.eve.plugin_abi.request.v1",
|
||||
"responseSchema": "gamecult.eve.plugin_abi.response.v1",
|
||||
"operations": ["describe", "validate", "project"],
|
||||
"commandEnvelope": "gamecult.eve.command_invocation.v1",
|
||||
"receiptSchema": "gamecult.eve.command_result.v1",
|
||||
"stateAuthority": "Heimdall projects access state; the plugin cannot grant access.",
|
||||
"endpoint": "rudp://127.0.0.1:4101"
|
||||
}
|
||||
},
|
||||
"schemas": ["heimdall.access_gate_state.v1", "heimdall.auth_attempt.v1", "heimdall.auth_begin_receipt.v1", "heimdall.auth_completion_receipt.v1", "heimdall.auth_navigation_receipt.v1", "heimdall.auth_completion_status.v1"],
|
||||
"componentKinds": ["heimdall.access_gate", "heimdall.identity", "heimdall.access_status"],
|
||||
"commands": ["heimdall.auth.begin", "heimdall.auth.complete", "app.auth.logout"],
|
||||
"navigationOrigins": ["https://discord.com", "https://heimdall.gamecult.org"],
|
||||
"fixtures": ["anonymous", "pending", "denied", "authenticated", "expired", "unavailable"]
|
||||
}
|
||||
80
plugins/gamecult.heimdall.access/browser-adapter.ts
Normal file
80
plugins/gamecult.heimdall.access/browser-adapter.ts
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
const ATTEMPT_KEY = "gamecult.heimdall.access.attempt";
|
||||
|
||||
export interface HeimdallAccessResumeTarget {
|
||||
complete(handle: string): Promise<void>;
|
||||
}
|
||||
|
||||
export function createHeimdallAccessBrowserAdapter(options: { advertisedOrigins: readonly string[] }) {
|
||||
const advertisedOrigins = new Set(options.advertisedOrigins.map(value => new URL(value).origin));
|
||||
return {
|
||||
pluginId: "gamecult.heimdall.access",
|
||||
capabilities: ["auth.gate", "auth.begin", "auth.complete", "auth.logout"],
|
||||
componentKinds: ["heimdall.access_gate", "heimdall.identity", "heimdall.access_status"],
|
||||
schemas: ["heimdall.access_gate_state.v1"],
|
||||
normalizeDocument(_schemaId: string | undefined, value: unknown): unknown {
|
||||
return value;
|
||||
},
|
||||
renderComponent(
|
||||
component: { id?: string },
|
||||
props: Record<string, unknown>,
|
||||
): HTMLElement {
|
||||
const view = document.createElement("section");
|
||||
view.className = `heimdall-access heimdall-access-${String(props.state || "unknown")}`;
|
||||
if (component.id) view.id = component.id;
|
||||
view.setAttribute("role", "status");
|
||||
view.setAttribute("aria-live", "polite");
|
||||
const title = document.createElement("h2");
|
||||
title.textContent = String(props.title || "Access");
|
||||
const detail = document.createElement("p");
|
||||
detail.textContent = String(props.detail || "");
|
||||
view.append(title, detail);
|
||||
const displayName = String(props.displayName || "");
|
||||
if (displayName) {
|
||||
const identity = document.createElement("p");
|
||||
identity.className = "heimdall-identity";
|
||||
identity.textContent = displayName;
|
||||
view.append(identity);
|
||||
}
|
||||
return view;
|
||||
},
|
||||
async consumeCommandResult(
|
||||
pluginPayload: { schemaId: string; payload: Record<string, unknown> },
|
||||
): Promise<void> {
|
||||
if (pluginPayload.schemaId === "heimdall.auth_navigation_receipt.v1") {
|
||||
const handle = String(pluginPayload.payload.handle || "");
|
||||
const navigation = object(pluginPayload.payload.navigation);
|
||||
const url = new URL(String(navigation.url || ""));
|
||||
const allowedOrigins = Array.isArray(navigation.allowedOrigins)
|
||||
? navigation.allowedOrigins.filter((value): value is string => typeof value === "string")
|
||||
: [];
|
||||
if (!handle || url.protocol !== "https:" || !advertisedOrigins.has(url.origin) || !allowedOrigins.includes(url.origin)) {
|
||||
throw new Error("Heimdall returned an unsafe authentication navigation receipt.");
|
||||
}
|
||||
sessionStorage.setItem(ATTEMPT_KEY, handle);
|
||||
window.location.assign(url.toString());
|
||||
return;
|
||||
}
|
||||
if (pluginPayload.schemaId === "heimdall.auth_completion_status.v1") {
|
||||
const status = String(pluginPayload.payload.status || "");
|
||||
if (status === "authenticated" || status === "denied" || status === "expired") {
|
||||
sessionStorage.removeItem(ATTEMPT_KEY);
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export const heimdallAccessBrowserAdapter = createHeimdallAccessBrowserAdapter({
|
||||
advertisedOrigins: ["https://discord.com", "https://heimdall.gamecult.org"],
|
||||
});
|
||||
|
||||
export async function resumeHeimdallAccess(target: HeimdallAccessResumeTarget): Promise<boolean> {
|
||||
const handle = sessionStorage.getItem(ATTEMPT_KEY);
|
||||
if (!handle) return false;
|
||||
await target.complete(handle);
|
||||
return true;
|
||||
}
|
||||
|
||||
function object(value: unknown): Record<string, unknown> {
|
||||
return value && typeof value === "object" && !Array.isArray(value) ? value as Record<string, unknown> : {};
|
||||
}
|
||||
1
plugins/gamecult.heimdall.access/fixtures/anonymous.json
Normal file
1
plugins/gamecult.heimdall.access/fixtures/anonymous.json
Normal file
|
|
@ -0,0 +1 @@
|
|||
{"schema":"heimdall.access_gate_state.v1","state":"anonymous","title":"Sign in to Ghostlight Dungeon","detail":"Use your GameCult Discord identity to continue.","canBegin":true,"canComplete":false}
|
||||
|
|
@ -0,0 +1 @@
|
|||
{"schema":"heimdall.access_gate_state.v1","state":"authenticated","title":"Signed in","detail":"Heimdall verified this app session.","canBegin":false,"canComplete":false,"displayName":"Tester"}
|
||||
1
plugins/gamecult.heimdall.access/fixtures/denied.json
Normal file
1
plugins/gamecult.heimdall.access/fixtures/denied.json
Normal file
|
|
@ -0,0 +1 @@
|
|||
{"schema":"heimdall.access_gate_state.v1","state":"denied","title":"Access denied","detail":"This Discord identity does not currently satisfy Ghostlight's access policy.","canBegin":true,"canComplete":false}
|
||||
1
plugins/gamecult.heimdall.access/fixtures/expired.json
Normal file
1
plugins/gamecult.heimdall.access/fixtures/expired.json
Normal file
|
|
@ -0,0 +1 @@
|
|||
{"schema":"heimdall.access_gate_state.v1","state":"expired","title":"Sign-in expired","detail":"Begin a fresh authentication attempt.","canBegin":true,"canComplete":false}
|
||||
1
plugins/gamecult.heimdall.access/fixtures/pending.json
Normal file
1
plugins/gamecult.heimdall.access/fixtures/pending.json
Normal file
|
|
@ -0,0 +1 @@
|
|||
{"schema":"heimdall.access_gate_state.v1","state":"pending","title":"Authentication pending","detail":"Finish signing in with Discord, then return here.","canBegin":false,"canComplete":true}
|
||||
|
|
@ -0,0 +1 @@
|
|||
{"schema":"heimdall.access_gate_state.v1","state":"unavailable","title":"Authentication unavailable","detail":"Existing verified sessions continue until expiry; new sign-in is temporarily unavailable.","canBegin":false,"canComplete":false}
|
||||
49
plugins/gamecult.heimdall.access/manifest.json
Normal file
49
plugins/gamecult.heimdall.access/manifest.json
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
{
|
||||
"schema": "gamecult.eve.plugin.v1",
|
||||
"pluginId": "gamecult.heimdall.access",
|
||||
"title": "Heimdall Access",
|
||||
"owner": "heimdall",
|
||||
"version": "0.1.0",
|
||||
"componentKinds": ["heimdall.access_gate", "heimdall.identity", "heimdall.access_status"],
|
||||
"commands": [
|
||||
{ "command": "heimdall.auth.begin", "schema": "heimdall.auth_begin_command.v1", "effect": "request-auth-navigation" },
|
||||
{ "command": "heimdall.auth.complete", "schema": "heimdall.auth_complete_command.v1", "effect": "redeem-auth-completion" },
|
||||
{ "command": "app.auth.logout", "schema": "heimdall.auth_logout_command.v1", "effect": "request-app-local-session-revocation" }
|
||||
],
|
||||
"runtime": {
|
||||
"invocationModel": "executable-sidecar",
|
||||
"contract": "gamecult.eve.plugin_abi.v1",
|
||||
"transports": ["cultnet.operation.v0", "in-process-reference"],
|
||||
"authority": ["renderer-independent", "no-access-grant", "no-provider-state-mutation"],
|
||||
"sidecar": {
|
||||
"processKind": "heimdall-daemon-plugin-organ",
|
||||
"protocol": "cultnet.operation.v0",
|
||||
"requestSchema": "gamecult.eve.plugin_abi.request.v1",
|
||||
"responseSchema": "gamecult.eve.plugin_abi.response.v1",
|
||||
"operations": ["describe", "validate", "project"],
|
||||
"commandEnvelope": "gamecult.eve.command_invocation.v1",
|
||||
"receiptSchema": "gamecult.eve.command_result.v1",
|
||||
"stateAuthority": "Heimdall projects access state; host apps accept commands and create only their own local sessions.",
|
||||
"endpoint": "rudp://127.0.0.1:4101"
|
||||
}
|
||||
},
|
||||
"stateSchemas": [
|
||||
"heimdall.access_gate_state.v1",
|
||||
"heimdall.auth_attempt.v1",
|
||||
"heimdall.auth_begin_receipt.v1",
|
||||
"heimdall.auth_completion_receipt.v1",
|
||||
"heimdall.auth_navigation_receipt.v1",
|
||||
"heimdall.auth_completion_status.v1"
|
||||
],
|
||||
"fixtures": [
|
||||
{ "fixtureId": "heimdall.access.anonymous", "schema": "heimdall.access_gate_state.v1", "path": "fixtures/anonymous.json" },
|
||||
{ "fixtureId": "heimdall.access.pending", "schema": "heimdall.access_gate_state.v1", "path": "fixtures/pending.json" },
|
||||
{ "fixtureId": "heimdall.access.denied", "schema": "heimdall.access_gate_state.v1", "path": "fixtures/denied.json" },
|
||||
{ "fixtureId": "heimdall.access.authenticated", "schema": "heimdall.access_gate_state.v1", "path": "fixtures/authenticated.json" },
|
||||
{ "fixtureId": "heimdall.access.expired", "schema": "heimdall.access_gate_state.v1", "path": "fixtures/expired.json" },
|
||||
{ "fixtureId": "heimdall.access.unavailable", "schema": "heimdall.access_gate_state.v1", "path": "fixtures/unavailable.json" }
|
||||
],
|
||||
"capabilities": {
|
||||
"requires": ["auth.gate", "auth.begin", "auth.complete", "auth.logout", "control.button", "text.body"]
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue