Skip to content

Commit e1369f5

Browse files
authored
Updated legacy redirect flow (dfinity#3616)
Updated legacy redirect flow, use delegations, sessions and time limits instead of referrer. # Changes - Replace referrer logic with intermediate key pairs in both legacy and new origins. - Store auth origin, pubkey, timestamp and intermediate key pair in session storage. - Read the above after being redirected back to check if the incoming redirect is valid.
1 parent 9b3d8ba commit e1369f5

3 files changed

Lines changed: 257 additions & 76 deletions

File tree

src/frontend/src/lib/stores/channelStore.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,27 @@ import type {
1212
PermissionScope,
1313
SupportedStandard,
1414
} from "@slide-computer/signer";
15+
import { canisterConfig, getPrimaryOrigin } from "$lib/globals";
1516

1617
type ChannelStore = Readable<Channel | undefined> & {
1718
establish: (options?: ChannelOptions) => Promise<Channel>;
1819
};
1920

20-
const transports: Transport[] = [
21-
new PostMessageTransport(),
22-
new LegacyTransport(),
23-
];
21+
const getTransports = (): Transport[] => {
22+
const primaryOrigin = getPrimaryOrigin();
23+
return [
24+
new PostMessageTransport(),
25+
new LegacyTransport(
26+
// Redirect requests and responses between related origins and primary origin
27+
primaryOrigin !== undefined
28+
? {
29+
redirectToOrigin: primaryOrigin,
30+
trustedOrigins: canisterConfig.related_origins[0] ?? [],
31+
}
32+
: undefined,
33+
),
34+
];
35+
};
2436

2537
const supportedStandards: SupportedStandard[] = [
2638
{
@@ -94,7 +106,7 @@ export const channelStore: ChannelStore = {
94106
}
95107
// Else establish channel
96108
const channel = await Promise.any(
97-
transports.map((transport) => transport.establishChannel(options)),
109+
getTransports().map((transport) => transport.establishChannel(options)),
98110
);
99111
// Return default responses for ICRC-25 requests
100112
channel.addEventListener("request", supportedStandardsListener(channel));

0 commit comments

Comments
 (0)