Skip to content

Add silent renew#420

Open
ben-polinsky wants to merge 3 commits intomasterfrom
add-silent-renew
Open

Add silent renew#420
ben-polinsky wants to merge 3 commits intomasterfrom
add-silent-renew

Conversation

@ben-polinsky
Copy link
Contributor

@ben-polinsky ben-polinsky commented Mar 2, 2026

Add explicit support for silent renew of auth tokens to web template.
(Desktop applications use refresh token)

@ben-polinsky ben-polinsky marked this pull request as ready for review March 2, 2026 22:17
@ben-polinsky ben-polinsky requested a review from Copilot March 2, 2026 22:17
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds explicit support for OIDC silent renew across the web template and the web-viewer-test app by introducing a dedicated silent callback page and wiring a new silentRedirectUri environment variable into the auth client configuration.

Changes:

  • Add signin-silent.html + signin-silent.ts callback entrypoints for silent renew.
  • Add IMJS_AUTH_CLIENT_SILENT_REDIRECT_URI env var (typing + docs + sample .env) and pass it into BrowserAuthorizationClient configuration.
  • Configure the template Vite build for a multi-page output including the silent callback HTML.

Reviewed changes

Copilot reviewed 11 out of 12 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
packages/templates/web/vite.config.mts Adds multi-page Rollup input for signin-silent.html (but currently uses __dirname in .mts).
packages/templates/web/src/vite-env.d.ts Adds typing for IMJS_AUTH_CLIENT_SILENT_REDIRECT_URI.
packages/templates/web/src/signin-silent.ts Adds a silent callback handler entrypoint.
packages/templates/web/src/components/Authorization.tsx Passes silentRedirectUri to BrowserAuthorizationClient.
packages/templates/web/signin-silent.html Adds the silent callback HTML entry.
packages/templates/web/README.md Documents the new silent redirect env var and how to configure it.
packages/templates/web/.env Adds the new env var placeholder.
packages/apps/web-viewer-test/src/signin-silent.ts Adds a silent callback handler entrypoint.
packages/apps/web-viewer-test/src/services/auth/AuthorizationClient.ts Passes silentRedirectUri into the auth client configuration.
packages/apps/web-viewer-test/signin-silent.html Adds the silent callback HTML entry.
packages/apps/web-viewer-test/README.md Documents silent redirect env var configuration.
packages/apps/web-viewer-test/.env Sets a default local IMJS_AUTH_CLIENT_SILENT_REDIRECT_URI.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +13 to +17
rollupOptions: {
input: {
main: resolve(__dirname, "index.html"),
"signin-silent": resolve(__dirname, "signin-silent.html"),
},
Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vite.config.mts is an ESM/TypeScript config (.mts), so __dirname is not defined in Node ESM and this will throw at config-load time. Compute the directory from import.meta.url (e.g., via fileURLToPath/dirname) or use new URL("index.html", import.meta.url) style paths instead of __dirname.

Copilot uses AI. Check for mistakes.

import { BrowserAuthorizationClient } from "@itwin/browser-authorization";

BrowserAuthorizationClient.handleSignInCallback().catch(() => window.close());
Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The codebase uses client.handleSigninCallback() (note casing/spelling: Signin) elsewhere, but this new page calls BrowserAuthorizationClient.handleSignInCallback() (SignIn) as a static. Please verify the exact API name; if handleSignInCallback doesn’t exist this will fail at runtime/compile-time. Prefer using the same callback handler naming used by the existing redirect flow for consistency.

Suggested change
BrowserAuthorizationClient.handleSignInCallback().catch(() => window.close());
BrowserAuthorizationClient.handleSigninCallback().catch(() => window.close());

Copilot uses AI. Check for mistakes.

import { BrowserAuthorizationClient } from "@itwin/browser-authorization";

BrowserAuthorizationClient.handleSignInCallback().catch(() => window.close());
Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The codebase uses client.handleSigninCallback() (note casing/spelling: Signin) elsewhere, but this new page calls BrowserAuthorizationClient.handleSignInCallback() (SignIn) as a static. Please verify the exact API name; if handleSignInCallback doesn’t exist this will fail at runtime/compile-time. Prefer using the same callback handler naming used by the existing redirect flow for consistency.

Suggested change
BrowserAuthorizationClient.handleSignInCallback().catch(() => window.close());
BrowserAuthorizationClient.handleSigninCallback().catch(() => window.close());

Copilot uses AI. Check for mistakes.
Comment on lines +35 to 37
responseType: "code",
silentRedirectUri: import.meta.env.IMJS_AUTH_CLIENT_SILENT_REDIRECT_URI,
};
Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import.meta.env.IMJS_AUTH_CLIENT_SILENT_REDIRECT_URI is referenced here, but packages/apps/web-viewer-test/src/vite-env.d.ts doesn’t declare this env var in ImportMetaEnv, so this will fail type-checking. Add the new optional env key to that file (or adjust env typing) to keep TS builds green.

Copilot uses AI. Check for mistakes.
Comment on lines +7 to +8
<script type="module" src="/src/signin-silent.ts"></script>
</body>
Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This app adds a new standalone HTML entry (signin-silent.html), but vite.config.ts for web-viewer-test currently doesn’t configure a multi-page Rollup input. In production builds this page may not be emitted to dist/, which would break silent renew. Consider adding build.rollupOptions.input for this HTML entry (similar to the template’s config).

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants