Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
f477a7f
feat: share one session across origins via a derivation-origin hub
sea-snake Aug 7, 2026
8e763a0
feat: keep the expiration isAuthenticated() reads in a swappable sync…
sea-snake Aug 7, 2026
b48f114
fix: declare the ignored expiresAt on SyncLocalStorage.set
sea-snake Aug 7, 2026
f8f6747
test: settle the shared-session hub handshake before the test ends
sea-snake Aug 7, 2026
34c57af
fix: scope the expiration cookie to the hub, not the derivation origin
sea-snake Aug 7, 2026
75b2fd8
refactor: drop sharedSessionHub in favour of setting the storage dire…
sea-snake Aug 7, 2026
90da96b
refactor: flatten the hub option and key the cookie by derivation origin
sea-snake Aug 7, 2026
8ffe1fc
refactor: drop the derivation origin from both client-side stores
sea-snake Aug 7, 2026
533c230
feat: resolve the derivation origin's canister id instead of asking f…
sea-snake Aug 7, 2026
564d4e6
docs: cut the shared session guide to the scenario and the three steps
sea-snake Aug 7, 2026
14dd7b5
docs: drop em dashes and the entry-count note from the shared session…
sea-snake Aug 7, 2026
56c1ca3
docs: trim the shared session intro and drop the frame-ancestors aside
sea-snake Aug 7, 2026
fa66b8b
docs: assume familiarity with alternative origins
sea-snake Aug 7, 2026
6e4885d
style: drop em dashes from comments added in this branch
sea-snake Aug 7, 2026
fd2d930
docs: point the Internet Identity spec links at the live URL
sea-snake Aug 7, 2026
c03dc12
docs: import SharedSessionStorage from the client entry point
sea-snake Aug 7, 2026
9a41536
fix: stop clearing the cached expiration when the store looks empty
sea-snake Aug 7, 2026
5871030
style: drop an unverified browser claim from a cookie comment
sea-snake Aug 7, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,32 @@ const authClient = new AuthClient({
});
```

### Sharing One Session Across Origins

Give several apps under one custom domain the same principal and the same sign-in state, so that `docs.example.com` and `chat.example.com` sign in once as the same user.

Deploy a page that hosts the session:

```typescript
import { serveSharedSession } from '@icp-sdk/auth/shared-session';

serveSharedSession({ derivationOrigin: 'https://auth.example.com' });
```

Then point each origin at it:

```typescript
import { AuthClient, SharedSessionStorage, SyncCookieStorage } from '@icp-sdk/auth/client';

const authClient = new AuthClient({
storage: new SharedSessionStorage({ url: 'https://auth.example.com/shared-session.html' }),
syncStorage: new SyncCookieStorage({ domain: 'example.com' }),
derivationOrigin: 'https://auth.example.com',
});
```

Each app must be listed in the derivation origin's `.well-known/ii-alternative-origins` record. See the [shared session guide](https://js.icp.build/auth/shared-session).

### Requesting Identity Attributes

Internet Identity can provide signed identity attributes (e.g., email) alongside authentication. Your backend canister initiates the flow by issuing a nonce tied to the action — this way, even if an attribute bundle is intercepted, it can't be replayed or used for a different action.
Expand Down
11 changes: 10 additions & 1 deletion docs/src/content/docs/_sidebar.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"items": [
{ "label": "Overview", "link": "/" },
{ "label": "Installation", "link": "/installation" },
{ "label": "Quick Start", "link": "/quick-start" }
{ "label": "Quick Start", "link": "/quick-start" },
{ "label": "Shared Session", "link": "/shared-session" }
]
},
{
Expand All @@ -17,6 +18,14 @@
"collapsed": true,
"directory": "api/client/"
}
},
{
"label": "Shared Session",
"collapsed": true,
"autogenerate": {
"collapsed": true,
"directory": "api/shared-session/"
}
}
]
},
Expand Down
55 changes: 55 additions & 0 deletions docs/src/content/docs/shared-session.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
---
title: Shared Session
description: Share one principal and one sign-in across several apps on your domain.
---

Use a shared session when several apps under one custom domain need the same principal and the same sign-in state, so that `docs.example.com` and `chat.example.com` sign in once as the same user.

A `derivationOrigin` alone gives them the same principal, but each app still signs in separately and keeps its own session. The setup below shares the session itself, so signing in or out of one app applies to all of them.

A shared session requires a derivation origin. The examples below use `example.com` as the custom domain and `https://auth.example.com` as the derivation origin.

## 1. Host the session

Deploy a page that calls `serveSharedSession`, on any origin you control:

```html
<!doctype html>
<meta charset="utf-8" />
<title>Shared session</title>
<script type="module" src="/shared-session.js"></script>
```

```typescript
import { serveSharedSession } from '@icp-sdk/auth/shared-session';

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Can this be vanilla JS?

Can we inline it into the HTML to avoid having two snippets?


serveSharedSession({ derivationOrigin: 'https://auth.example.com' });
```

## 2. Authorize each app

The derivation origin decides which origins may read the session. List them in its [`.well-known/ii-alternative-origins`](https://docs.internetcomputer.org/references/internet-identity-spec/#alternative-frontend-origins) record:

```json
{ "alternativeOrigins": ["https://docs.example.com", "https://chat.example.com"] }
```

## 3. Point each app at it

On `docs.example.com` and `chat.example.com` alike:

```typescript
import { AuthClient, SharedSessionStorage, SyncCookieStorage } from '@icp-sdk/auth/client';

const authClient = new AuthClient({
storage: new SharedSessionStorage({ url: 'https://auth.example.com/shared-session.html' }),
syncStorage: new SyncCookieStorage({ domain: 'example.com' }),
derivationOrigin: 'https://auth.example.com',
});
```

| Option | Set it to |
| --- | --- |
| `storage` | A `SharedSessionStorage` pointing at the page from step 1. |
| `syncStorage` | A `SyncCookieStorage` scoped to your custom domain. |
| `derivationOrigin` | The origin to derive the principal for. |
2 changes: 1 addition & 1 deletion docs/typedoc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://typedoc-plugin-markdown.org/schema.json",
"entryPoints": ["../src/client/index.ts"],
"entryPoints": ["../src/client/index.ts", "../src/shared-session/index.ts"],
"tsconfig": "../tsconfig.lib.json",
"readme": "none",
"out": "src/content/tmp",
Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
"import": "./dist/esm/client/index.js",
"default": "./dist/esm/client/index.js"
},
"./shared-session": {
"types": "./dist/esm/shared-session/index.d.ts",
"import": "./dist/esm/shared-session/index.js",
"default": "./dist/esm/shared-session/index.js"
},
"./package.json": "./package.json"
},
"files": [
Expand Down
Loading
Loading