Add StreamPixels managed auth seams
This commit is contained in:
parent
5ef94bb725
commit
f22db66d64
15 changed files with 589 additions and 26 deletions
|
|
@ -20,6 +20,9 @@ function createTestConfig(): HeimdallConfig {
|
|||
completionTtlSeconds: 300,
|
||||
bootstrapSigningPrivateKeyOnMissing: false,
|
||||
tokenEncryptionKeyBase64: Buffer.alloc(32, 7).toString("base64"),
|
||||
appSharedSecrets: {
|
||||
streampixels: "streampixels-secret",
|
||||
},
|
||||
storage: {
|
||||
backend: "memory",
|
||||
applySchemaOnStartup: true,
|
||||
|
|
@ -576,4 +579,80 @@ describe("Heimdall service", () => {
|
|||
})
|
||||
);
|
||||
});
|
||||
|
||||
it("resolves app-managed provider credentials without exposing refresh custody", async () => {
|
||||
const store = new InMemoryStore();
|
||||
const app = await buildApp({
|
||||
config: createTestConfig(),
|
||||
store,
|
||||
oauthRuntimes: {
|
||||
twitch: {
|
||||
async exchangeAuthorizationCode() {
|
||||
return {
|
||||
accessToken: "twitch-access-token",
|
||||
refreshToken: "twitch-refresh-token",
|
||||
tokenType: "Bearer",
|
||||
scope: ["user:read:email"],
|
||||
expiresAt: "2026-04-26T13:00:00.000Z",
|
||||
raw: { source: "test" },
|
||||
};
|
||||
},
|
||||
async resolveIdentity() {
|
||||
return {
|
||||
provider: "twitch",
|
||||
providerUserId: "twitch-user-123",
|
||||
username: "pixelpaladin",
|
||||
displayName: "PixelPaladin",
|
||||
profile: { id: "twitch-user-123" },
|
||||
};
|
||||
},
|
||||
async evaluateEntitlements() {
|
||||
return { facts: [], snapshots: [] };
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
apps.push(app);
|
||||
|
||||
const startResponse = await app.inject({
|
||||
method: "POST",
|
||||
url: "/v1/oauth/twitch/start",
|
||||
payload: {
|
||||
appSlug: "streampixels",
|
||||
mode: "connect",
|
||||
returnTo: "https://streampixels.gamecult.org/auth/connect",
|
||||
},
|
||||
});
|
||||
const stateToken = startResponse.json().stateToken as string;
|
||||
|
||||
const callbackResponse = await app.inject({
|
||||
method: "GET",
|
||||
url: `/v1/oauth/twitch/callback?code=test-code&state=${encodeURIComponent(stateToken)}`,
|
||||
});
|
||||
const accountId = callbackResponse.json().account.id as string;
|
||||
|
||||
const credentialResponse = await app.inject({
|
||||
method: "POST",
|
||||
url: "/v1/apps/streampixels/managed-credentials/resolve",
|
||||
headers: {
|
||||
"x-heimdall-app-secret": "streampixels-secret",
|
||||
},
|
||||
payload: {
|
||||
accountId,
|
||||
provider: "twitch",
|
||||
},
|
||||
});
|
||||
|
||||
expect(credentialResponse.statusCode).toBe(200);
|
||||
expect(credentialResponse.json()).toEqual(
|
||||
expect.objectContaining({
|
||||
accountId,
|
||||
provider: "twitch",
|
||||
providerUserId: "twitch-user-123",
|
||||
accessToken: "twitch-access-token",
|
||||
scopes: ["user:read:email"],
|
||||
})
|
||||
);
|
||||
expect(credentialResponse.body).not.toContain("twitch-refresh-token");
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ function createTestConfig(overrides: Partial<HeimdallConfig> = {}): HeimdallConf
|
|||
stateTtlSeconds: 600,
|
||||
completionTtlSeconds: 300,
|
||||
bootstrapSigningPrivateKeyOnMissing: false,
|
||||
appSharedSecrets: {},
|
||||
storage: {
|
||||
backend: "memory",
|
||||
applySchemaOnStartup: true,
|
||||
|
|
|
|||
Loading…
Reference in a new issue