-
Notifications
You must be signed in to change notification settings - Fork 3
feat: share one session across origins with a shared session storage backend #144
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
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 8e763a0
feat: keep the expiration isAuthenticated() reads in a swappable sync…
sea-snake b48f114
fix: declare the ignored expiresAt on SyncLocalStorage.set
sea-snake f8f6747
test: settle the shared-session hub handshake before the test ends
sea-snake 34c57af
fix: scope the expiration cookie to the hub, not the derivation origin
sea-snake 75b2fd8
refactor: drop sharedSessionHub in favour of setting the storage dire…
sea-snake 90da96b
refactor: flatten the hub option and key the cookie by derivation origin
sea-snake 8ffe1fc
refactor: drop the derivation origin from both client-side stores
sea-snake 533c230
feat: resolve the derivation origin's canister id instead of asking f…
sea-snake 564d4e6
docs: cut the shared session guide to the scenario and the three steps
sea-snake 14dd7b5
docs: drop em dashes and the entry-count note from the shared session…
sea-snake 56c1ca3
docs: trim the shared session intro and drop the frame-ancestors aside
sea-snake fa66b8b
docs: assume familiarity with alternative origins
sea-snake 6e4885d
style: drop em dashes from comments added in this branch
sea-snake fd2d930
docs: point the Internet Identity spec links at the live URL
sea-snake c03dc12
docs: import SharedSessionStorage from the client entry point
sea-snake 9a41536
fix: stop clearing the cached expiration when the store looks empty
sea-snake 5871030
style: drop an unverified browser claim from a cookie comment
sea-snake File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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'; | ||
|
|
||
| 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. | | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?