MCPcopy
hub / github.com/authts/oidc-client-ts / navigate

Function navigate

src/navigators/AbstractChildWindow.ts:28–80  ·  view source on GitHub ↗
(params: NavigateParams)

Source from the content-addressed store, hash-verified

26 protected _window: WindowProxy | null = null;
27
28 public async navigate(params: NavigateParams): Promise<NavigateResponse> {
29 const logger = this._logger.create("navigate");
30 if (!this._window) {
31 throw new Error("Attempted to navigate on a disposed window");
32 }
33
34 logger.debug("setting URL in window");
35 this._window.location.replace(params.url);
36
37 const { url, keepOpen } = await new Promise<MessageData>((resolve, reject) => {
38 const listener = (e: MessageEvent) => {
39 const data: MessageData | undefined = e.data;
40 const origin = params.scriptOrigin ?? window.location.origin;
41 if (e.origin !== origin || data?.source !== messageSource) {
42 // silently discard events not intended for us
43 return;
44 }
45 try {
46 const state = UrlUtils.readParams(data.url, params.response_mode).get("state");
47 if (!state) {
48 logger.warn("no state found in response url");
49 }
50 if (e.source !== this._window && state !== params.state) {
51 // MessageEvent source is a relatively modern feature, we can't rely on it
52 // so we also inspect the payload for a matching state key as an alternative
53 return;
54 }
55 }
56 catch {
57 this._dispose();
58 reject(new Error("Invalid response from window"));
59 }
60 resolve(data);
61 };
62 window.addEventListener("message", listener, false);
63 this._disposeHandlers.add(() => window.removeEventListener("message", listener, false));
64 const channel = new BroadcastChannel(`oidc-client-popup-${params.state}`);
65 channel.addEventListener("message", listener, false);
66 this._disposeHandlers.add(() => channel.close());
67 this._disposeHandlers.add(this._abort.addHandler((reason) => {
68 this._dispose();
69 reject(reason);
70 }));
71 });
72 logger.debug("got response from window");
73 this._dispose();
74
75 if (!keepOpen) {
76 this.close();
77 }
78
79 return { url };
80 }
81
82 public abstract close(): void;
83

Callers

nothing calls this directly

Calls 4

addHandlerMethod · 0.80
debugMethod · 0.65
closeMethod · 0.65
createMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…