@atlasauth/chrome-extension 0.2.2 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +29 -0
- package/dist/client.d.ts +86 -6
- package/dist/client.js +180 -15
- package/dist/client.js.map +1 -1
- package/dist/react.d.ts +14 -0
- package/dist/react.js +14 -2
- package/dist/react.js.map +1 -1
- package/dist/storage.d.ts +14 -0
- package/dist/storage.js +27 -0
- package/dist/storage.js.map +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,34 @@
|
|
|
1
1
|
# @atlasauth/chrome-extension changelog
|
|
2
2
|
|
|
3
|
+
## 0.3.0
|
|
4
|
+
|
|
5
|
+
### Changed
|
|
6
|
+
- **`AtlasClient.signOut(options?: SignOutOptions)` now resolves `Promise<SignOutResult>`** (`{ revoked: boolean;
|
|
7
|
+
activeSessionId?: string }`) instead of `Promise<void>`; existing `await client.signOut()` call sites keep working. The
|
|
8
|
+
revoke is no longer fire-and-forget: it is sent with the token being dropped, retried once, then re-tried in the
|
|
9
|
+
background (still authenticated as that token after `chrome.storage` was cleared). `{ strict: true }` rejects with
|
|
10
|
+
`SignOutError` (`code: 'SIGN_OUT_REVOKE_FAILED'`, `sessionId`, `status`) after the local sign-out. A token without a
|
|
11
|
+
`sid` claim no longer skips the revoke (`GET /v1/client` finds the session). `activeSessionId` (a server-promoted
|
|
12
|
+
session) is reported but not adopted: the bearer revoke returns no credential for it.
|
|
13
|
+
- **A signed-out session is never re-adopted by any extension surface.** Its id is recorded (a tombstone, via
|
|
14
|
+
`SignOutGuard` from `@atlasauth/js`) in `chrome.storage.local` before the revoke, and re-read before every decision, so
|
|
15
|
+
a popup, options page, content script or service worker that booted before the sign-out neither sends a stored token of
|
|
16
|
+
that session (it is removed and its revoke re-tried in the background) nor writes back a token its in-flight refresh
|
|
17
|
+
rotated for it (`syncSessionToken`, `persistingBearerFetch`). The tombstone is dropped once a revoke is confirmed.
|
|
18
|
+
- `AtlasClient.store` is now the guarded store (refuses a signed-out session's token on read and write).
|
|
19
|
+
- `@atlasauth/chrome-extension/react` `<AtlasProvider>`: `signOut` is `@atlasauth/react`'s (`Promise<SignOutResult>`,
|
|
20
|
+
strict `SignOutError`); revoking the stored token's session now also tombstones it in `chrome.storage.local` and drops
|
|
21
|
+
the token for every surface, and a stored token of a signed-out session is never sent nor written back.
|
|
22
|
+
|
|
23
|
+
### Added
|
|
24
|
+
- `ExtensionSignOutGuard` (with `ExtensionSignOutGuardOptions`): the shared-`chrome.storage` sign-out guard —
|
|
25
|
+
`guard`, `bearerRequest(token)`, `isSignedOut(sid)`, `guardStore(store)`, `remember(sid, token)`, `droppedToken(sid)`.
|
|
26
|
+
- `CreateAtlasClientOptions.tombstoneStore?: TombstoneStore` and `CreateAtlasClientOptions.signOutRetryDelaysMs?: number[]`;
|
|
27
|
+
`ChromeAtlasProviderProps.tombstoneStore?: TombstoneStore`.
|
|
28
|
+
- `createChromeTombstoneStore(area?)` and `StorageCache.tombstoneStore()`.
|
|
29
|
+
- `persistingBearerFetch(fetchImpl, store, signOutGuard?)` — optional third argument.
|
|
30
|
+
- Re-exports `SignOutError`, `SignOutOptions`, `SignOutResult` and `TombstoneStore` from `@atlasauth/js`.
|
|
31
|
+
|
|
3
32
|
## 0.2.2
|
|
4
33
|
- Picks up `@atlasauth/react` 0.6.0 / `@atlasauth/js` 0.7.0: popup sign-in completes when the opener page
|
|
5
34
|
sends `Cross-Origin-Opener-Policy: same-origin`; a tab opened after a failed sign-out stays signed out
|
package/dist/client.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FapiClient, type ProviderToken } from '@atlasauth/js';
|
|
1
|
+
import { FapiClient, SignOutGuard, type FapiRequest, type ProviderToken, type SignOutOptions, type SignOutResult, type TombstoneStore } from '@atlasauth/js';
|
|
2
2
|
import { type TokenStore } from './storage';
|
|
3
3
|
/**
|
|
4
4
|
* The extension FAPI layer.
|
|
@@ -27,6 +27,57 @@ export declare function decodeTokenClaims(jwt: string): SessionTokenClaims | nul
|
|
|
27
27
|
* while signed out simply carries no `Authorization` header.
|
|
28
28
|
*/
|
|
29
29
|
export declare function bearerFetch(fetchImpl: typeof fetch, store: TokenStore): typeof fetch;
|
|
30
|
+
export interface ExtensionSignOutGuardOptions {
|
|
31
|
+
publishableKey: string;
|
|
32
|
+
/** The (validated) Frontend API base URL. Tombstones are kept per Frontend API origin. */
|
|
33
|
+
frontendApi: string;
|
|
34
|
+
/** Injectable for tests; defaults to the platform `fetch`. */
|
|
35
|
+
fetchImpl?: typeof fetch;
|
|
36
|
+
/** Where tombstones live. Defaults to `chrome.storage.local`. */
|
|
37
|
+
tombstoneStore?: TombstoneStore;
|
|
38
|
+
/** Delays (ms) between background re-tries of a failed revoke. @default `[15_000, 60_000, 300_000]` */
|
|
39
|
+
retryDelaysMs?: number[];
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* The safer sign-out for an extension, where several surfaces (popup, options
|
|
43
|
+
* page, content scripts, the service worker) share one token in
|
|
44
|
+
* `chrome.storage` but each has its own memory.
|
|
45
|
+
*
|
|
46
|
+
* Wraps `@atlasauth/js`'s {@link SignOutGuard} with tombstones in
|
|
47
|
+
* `chrome.storage.local`, and re-reads them before every decision — so a surface
|
|
48
|
+
* that booted before another one signed out still sees the sign-out: it neither
|
|
49
|
+
* adopts the signed-out session's token ({@link guardStore} `getToken`) nor
|
|
50
|
+
* writes back a token a refresh rotated for it (`setToken`). Revokes ride on the
|
|
51
|
+
* very token being dropped ({@link bearerRequest}), so a background re-try can
|
|
52
|
+
* still authenticate after the store was cleared.
|
|
53
|
+
*/
|
|
54
|
+
export declare class ExtensionSignOutGuard {
|
|
55
|
+
readonly guard: SignOutGuard;
|
|
56
|
+
private readonly baseUrl;
|
|
57
|
+
private readonly publishableKey;
|
|
58
|
+
private readonly fetchImpl;
|
|
59
|
+
private readonly store;
|
|
60
|
+
/** Tokens dropped at sign-out, by session id, for a revoke re-tried after the store was cleared. */
|
|
61
|
+
private readonly dropped;
|
|
62
|
+
constructor(options: ExtensionSignOutGuardOptions);
|
|
63
|
+
/** A Frontend API request carrying exactly `token` as its bearer (none for null). */
|
|
64
|
+
bearerRequest(token: string | null): FapiRequest;
|
|
65
|
+
/**
|
|
66
|
+
* Whether the extension signed out of `sessionId` — on ANY surface: the
|
|
67
|
+
* tombstones another surface wrote to the shared store are learned first.
|
|
68
|
+
*/
|
|
69
|
+
isSignedOut(sessionId: string | null | undefined): Promise<boolean>;
|
|
70
|
+
/** Remember the token of a session being signed out of, for later re-tries of its revoke. */
|
|
71
|
+
remember(sessionId: string, token: string): void;
|
|
72
|
+
/** The token a session was signed out with, if this surface dropped it. */
|
|
73
|
+
droppedToken(sessionId: string): string | null;
|
|
74
|
+
/**
|
|
75
|
+
* Wrap a {@link TokenStore} so it never hands out — nor accepts — a token of
|
|
76
|
+
* a session the extension signed out of. A refused stored token is removed
|
|
77
|
+
* and its session revoked again in the background, as itself.
|
|
78
|
+
*/
|
|
79
|
+
guardStore(store: TokenStore): TokenStore;
|
|
80
|
+
}
|
|
30
81
|
/**
|
|
31
82
|
* A {@link bearerFetch} that ALSO captures a freshly-minted session token out of
|
|
32
83
|
* the response and persists it to the store.
|
|
@@ -40,7 +91,13 @@ export declare function bearerFetch(fetchImpl: typeof fetch, store: TokenStore):
|
|
|
40
91
|
* `/v1/client` responses and guarded by JSON parsing, so a non-JSON or unrelated
|
|
41
92
|
* response is left untouched.
|
|
42
93
|
*/
|
|
43
|
-
export declare function persistingBearerFetch(fetchImpl: typeof fetch, store: TokenStore
|
|
94
|
+
export declare function persistingBearerFetch(fetchImpl: typeof fetch, store: TokenStore,
|
|
95
|
+
/**
|
|
96
|
+
* Make it sign-out safe: a stored token of a signed-out session is never
|
|
97
|
+
* sent nor written back, and a revoke of the stored token's session
|
|
98
|
+
* tombstones it and drops the token from `chrome.storage` for every surface.
|
|
99
|
+
*/
|
|
100
|
+
signOutGuard?: ExtensionSignOutGuard): typeof fetch;
|
|
44
101
|
export interface CreateAtlasClientOptions {
|
|
45
102
|
publishableKey: string;
|
|
46
103
|
/** The instance's FAPI origin, e.g. `https://fapi.your-instance.atlasauth.net`. */
|
|
@@ -49,6 +106,17 @@ export interface CreateAtlasClientOptions {
|
|
|
49
106
|
store?: TokenStore;
|
|
50
107
|
/** Injectable for tests; defaults to the platform `fetch`. */
|
|
51
108
|
fetchImpl?: typeof fetch;
|
|
109
|
+
/**
|
|
110
|
+
* Where the ids of sessions the extension signed out of are kept, shared by
|
|
111
|
+
* every surface. Defaults to the {@link StorageCache}'s storage area (else
|
|
112
|
+
* `chrome.storage.local`).
|
|
113
|
+
*/
|
|
114
|
+
tombstoneStore?: TombstoneStore;
|
|
115
|
+
/**
|
|
116
|
+
* Delays (ms) between background re-tries of a revoke `signOut()` could not
|
|
117
|
+
* complete. @default `[15_000, 60_000, 300_000]`
|
|
118
|
+
*/
|
|
119
|
+
signOutRetryDelaysMs?: number[];
|
|
52
120
|
}
|
|
53
121
|
/**
|
|
54
122
|
* The extension client. A thin, React-free handle the background service worker
|
|
@@ -58,7 +126,10 @@ export interface CreateAtlasClientOptions {
|
|
|
58
126
|
export interface AtlasClient {
|
|
59
127
|
/** The bearer-wired `@atlasauth/js` client for any raw FAPI call. */
|
|
60
128
|
readonly fapi: FapiClient;
|
|
61
|
-
/**
|
|
129
|
+
/**
|
|
130
|
+
* The token store this client reads and writes. It never hands out — nor
|
|
131
|
+
* writes back — a token of a session the extension signed out of.
|
|
132
|
+
*/
|
|
62
133
|
readonly store: TokenStore;
|
|
63
134
|
/** The current session token, or null when signed out. */
|
|
64
135
|
getToken(): Promise<string | null>;
|
|
@@ -68,8 +139,17 @@ export interface AtlasClient {
|
|
|
68
139
|
getProviderToken(provider: string): Promise<ProviderToken | null>;
|
|
69
140
|
/** Refresh the token if it is near expiry (or `force`) and persist it. */
|
|
70
141
|
syncSessionToken(options?: SyncOptions): Promise<string | null>;
|
|
71
|
-
/**
|
|
72
|
-
|
|
142
|
+
/**
|
|
143
|
+
* Sign out: remember the session id in `chrome.storage` (so no surface
|
|
144
|
+
* re-adopts it, and a refresh in flight anywhere cannot write its token
|
|
145
|
+
* back), revoke it on the Frontend API with the token being dropped (retried
|
|
146
|
+
* once, then in the background), and clear the stored token. Resolves
|
|
147
|
+
* `{ revoked }` — `false` when the server could not be reached (signed out
|
|
148
|
+
* locally regardless); `{ strict: true }` rejects with a `SignOutError`
|
|
149
|
+
* instead, after the local sign-out. A promoted `activeSessionId` is only
|
|
150
|
+
* reported: the bearer revoke returns no credential for it.
|
|
151
|
+
*/
|
|
152
|
+
signOut(options?: SignOutOptions): Promise<SignOutResult>;
|
|
73
153
|
}
|
|
74
154
|
/**
|
|
75
155
|
* Build an {@link AtlasClient}. `background: true` is accepted for parity with
|
|
@@ -99,4 +179,4 @@ export interface SyncOptions {
|
|
|
99
179
|
* can retry on its next tick, and the server rejects a truly-dead token on use.
|
|
100
180
|
*/
|
|
101
181
|
export declare function syncSessionToken(client: AtlasClient, options?: SyncOptions): Promise<string | null>;
|
|
102
|
-
export type
|
|
182
|
+
export { SignOutError, type ProviderToken, type SignOutOptions, type SignOutResult, type TombstoneStore } from '@atlasauth/js';
|
package/dist/client.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SignOutError = exports.ExtensionSignOutGuard = void 0;
|
|
3
4
|
exports.decodeTokenClaims = decodeTokenClaims;
|
|
4
5
|
exports.bearerFetch = bearerFetch;
|
|
5
6
|
exports.persistingBearerFetch = persistingBearerFetch;
|
|
@@ -44,6 +45,108 @@ function urlOf(input) {
|
|
|
44
45
|
return input.toString();
|
|
45
46
|
return input.url;
|
|
46
47
|
}
|
|
48
|
+
/** The session id in a stored token, or null. */
|
|
49
|
+
function sidOf(token) {
|
|
50
|
+
const sid = token ? decodeTokenClaims(token)?.sid : undefined;
|
|
51
|
+
return typeof sid === 'string' && sid ? sid : null;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* The safer sign-out for an extension, where several surfaces (popup, options
|
|
55
|
+
* page, content scripts, the service worker) share one token in
|
|
56
|
+
* `chrome.storage` but each has its own memory.
|
|
57
|
+
*
|
|
58
|
+
* Wraps `@atlasauth/js`'s {@link SignOutGuard} with tombstones in
|
|
59
|
+
* `chrome.storage.local`, and re-reads them before every decision — so a surface
|
|
60
|
+
* that booted before another one signed out still sees the sign-out: it neither
|
|
61
|
+
* adopts the signed-out session's token ({@link guardStore} `getToken`) nor
|
|
62
|
+
* writes back a token a refresh rotated for it (`setToken`). Revokes ride on the
|
|
63
|
+
* very token being dropped ({@link bearerRequest}), so a background re-try can
|
|
64
|
+
* still authenticate after the store was cleared.
|
|
65
|
+
*/
|
|
66
|
+
class ExtensionSignOutGuard {
|
|
67
|
+
guard;
|
|
68
|
+
baseUrl;
|
|
69
|
+
publishableKey;
|
|
70
|
+
fetchImpl;
|
|
71
|
+
store;
|
|
72
|
+
/** Tokens dropped at sign-out, by session id, for a revoke re-tried after the store was cleared. */
|
|
73
|
+
dropped = new Map();
|
|
74
|
+
constructor(options) {
|
|
75
|
+
this.baseUrl = options.frontendApi;
|
|
76
|
+
this.publishableKey = options.publishableKey;
|
|
77
|
+
this.fetchImpl = options.fetchImpl ?? ((input, init) => fetch(input, init));
|
|
78
|
+
this.store = options.tombstoneStore ?? (0, storage_1.createChromeTombstoneStore)();
|
|
79
|
+
this.guard = new js_1.SignOutGuard({
|
|
80
|
+
request: this.bearerRequest(null),
|
|
81
|
+
frontendApi: options.frontendApi,
|
|
82
|
+
store: this.store,
|
|
83
|
+
...(options.retryDelaysMs ? { retryDelaysMs: options.retryDelaysMs } : {}),
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
/** A Frontend API request carrying exactly `token` as its bearer (none for null). */
|
|
87
|
+
bearerRequest(token) {
|
|
88
|
+
return (path, init) => {
|
|
89
|
+
const headers = new Headers(init?.headers);
|
|
90
|
+
headers.set('x-publishable-key', this.publishableKey);
|
|
91
|
+
if (token)
|
|
92
|
+
headers.set('authorization', `Bearer ${token}`);
|
|
93
|
+
return this.fetchImpl(`${this.baseUrl}${path}`, { ...init, headers });
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Whether the extension signed out of `sessionId` — on ANY surface: the
|
|
98
|
+
* tombstones another surface wrote to the shared store are learned first.
|
|
99
|
+
*/
|
|
100
|
+
async isSignedOut(sessionId) {
|
|
101
|
+
if (!sessionId)
|
|
102
|
+
return false;
|
|
103
|
+
await this.guard.ready;
|
|
104
|
+
if (this.guard.isSignedOut(sessionId))
|
|
105
|
+
return true;
|
|
106
|
+
const shared = new js_1.SessionTombstones({ frontendApi: this.baseUrl, store: this.store });
|
|
107
|
+
await shared.ready;
|
|
108
|
+
this.guard.learn({ signedOut: shared.list() });
|
|
109
|
+
return this.guard.isSignedOut(sessionId);
|
|
110
|
+
}
|
|
111
|
+
/** Remember the token of a session being signed out of, for later re-tries of its revoke. */
|
|
112
|
+
remember(sessionId, token) {
|
|
113
|
+
this.dropped.set(sessionId, token);
|
|
114
|
+
}
|
|
115
|
+
/** The token a session was signed out with, if this surface dropped it. */
|
|
116
|
+
droppedToken(sessionId) {
|
|
117
|
+
return this.dropped.get(sessionId) ?? null;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Wrap a {@link TokenStore} so it never hands out — nor accepts — a token of
|
|
121
|
+
* a session the extension signed out of. A refused stored token is removed
|
|
122
|
+
* and its session revoked again in the background, as itself.
|
|
123
|
+
*/
|
|
124
|
+
guardStore(store) {
|
|
125
|
+
return {
|
|
126
|
+
getToken: async () => {
|
|
127
|
+
const token = await store.getToken();
|
|
128
|
+
const sid = sidOf(token);
|
|
129
|
+
if (!token || !sid || !(await this.isSignedOut(sid)))
|
|
130
|
+
return token;
|
|
131
|
+
this.guard.refuse(sid, this.bearerRequest(token));
|
|
132
|
+
// Only if no surface has stored a newer token meanwhile.
|
|
133
|
+
if ((await store.getToken().catch(() => null)) === token) {
|
|
134
|
+
await store.removeToken().catch(() => undefined);
|
|
135
|
+
}
|
|
136
|
+
return null;
|
|
137
|
+
},
|
|
138
|
+
setToken: async (token) => {
|
|
139
|
+
// A refresh that was in flight at sign-out (here or on another surface)
|
|
140
|
+
// must not write the signed-out session's token back.
|
|
141
|
+
if (await this.isSignedOut(sidOf(token)))
|
|
142
|
+
return;
|
|
143
|
+
await store.setToken(token);
|
|
144
|
+
},
|
|
145
|
+
removeToken: () => store.removeToken(),
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
exports.ExtensionSignOutGuard = ExtensionSignOutGuard;
|
|
47
150
|
/**
|
|
48
151
|
* A {@link bearerFetch} that ALSO captures a freshly-minted session token out of
|
|
49
152
|
* the response and persists it to the store.
|
|
@@ -57,18 +160,64 @@ function urlOf(input) {
|
|
|
57
160
|
* `/v1/client` responses and guarded by JSON parsing, so a non-JSON or unrelated
|
|
58
161
|
* response is left untouched.
|
|
59
162
|
*/
|
|
60
|
-
function persistingBearerFetch(fetchImpl, store
|
|
163
|
+
function persistingBearerFetch(fetchImpl, store,
|
|
164
|
+
/**
|
|
165
|
+
* Make it sign-out safe: a stored token of a signed-out session is never
|
|
166
|
+
* sent nor written back, and a revoke of the stored token's session
|
|
167
|
+
* tombstones it and drops the token from `chrome.storage` for every surface.
|
|
168
|
+
*/
|
|
169
|
+
signOutGuard) {
|
|
170
|
+
const tokens = signOutGuard ? signOutGuard.guardStore(store) : store;
|
|
61
171
|
return async (input, init) => {
|
|
62
|
-
|
|
172
|
+
let token = await tokens.getToken();
|
|
173
|
+
const url = urlOf(input);
|
|
174
|
+
const method = (init?.method ?? (typeof input === 'object' && 'method' in input ? input.method : 'GET')).toUpperCase();
|
|
175
|
+
const revoking = signOutGuard && method === 'POST' ? /\/v1\/client\/sessions\/([^/?#]+)\/revoke(?:[?#]|$)/.exec(url) : null;
|
|
176
|
+
let dropping = null;
|
|
177
|
+
if (signOutGuard && revoking) {
|
|
178
|
+
const sid = decodeURIComponent(revoking[1]);
|
|
179
|
+
if (token && sidOf(token) === sid) {
|
|
180
|
+
// Signing out of the session this extension is signed in with:
|
|
181
|
+
// remember it first, so no surface re-adopts it from here on.
|
|
182
|
+
await signOutGuard.guard.ready;
|
|
183
|
+
signOutGuard.guard.tombstones.add(sid);
|
|
184
|
+
signOutGuard.remember(sid, token);
|
|
185
|
+
dropping = sid;
|
|
186
|
+
}
|
|
187
|
+
else if (!token) {
|
|
188
|
+
// A re-try after the token was dropped: authenticate as that session.
|
|
189
|
+
token = signOutGuard.droppedToken(sid);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
63
192
|
const headers = new Headers(init?.headers);
|
|
64
193
|
if (token)
|
|
65
194
|
headers.set('authorization', `Bearer ${token}`);
|
|
66
|
-
const
|
|
67
|
-
|
|
195
|
+
const dropped = async (response) => {
|
|
196
|
+
if (!signOutGuard || !dropping || !token)
|
|
197
|
+
return;
|
|
198
|
+
// Signed out locally whatever the server said — but only if no surface
|
|
199
|
+
// stored a newer token meanwhile.
|
|
200
|
+
if ((await store.getToken().catch(() => null)) === token)
|
|
201
|
+
await store.removeToken().catch(() => undefined);
|
|
202
|
+
if (!response || (!response.ok && response.status !== 404)) {
|
|
203
|
+
// Keep trying in the background (retried once, then on the guard's delays).
|
|
204
|
+
void signOutGuard.guard.revoke(dropping, { request: signOutGuard.bearerRequest(token), frontchannel: false });
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
let response;
|
|
208
|
+
try {
|
|
209
|
+
response = await fetchImpl(input, { ...init, headers });
|
|
210
|
+
}
|
|
211
|
+
catch (error) {
|
|
212
|
+
await dropped(null);
|
|
213
|
+
throw error;
|
|
214
|
+
}
|
|
215
|
+
await dropped(response);
|
|
216
|
+
if (response.ok && /\/v1\/client(\/|\?|$)/.test(url)) {
|
|
68
217
|
try {
|
|
69
218
|
const body = (await response.clone().json());
|
|
70
219
|
if (typeof body.jwt === 'string')
|
|
71
|
-
await
|
|
220
|
+
await tokens.setToken(body.jwt);
|
|
72
221
|
}
|
|
73
222
|
catch {
|
|
74
223
|
// Not JSON, or no body (a 204 revoke). Nothing to capture.
|
|
@@ -90,8 +239,17 @@ function createAtlasClient(options) {
|
|
|
90
239
|
component: 'createAtlasClient()',
|
|
91
240
|
allowSameOrigin: false,
|
|
92
241
|
});
|
|
93
|
-
const
|
|
242
|
+
const rawStore = options.store ?? new storage_1.StorageCache();
|
|
94
243
|
const fetchImpl = options.fetchImpl ?? fetch;
|
|
244
|
+
const signOutGuard = new ExtensionSignOutGuard({
|
|
245
|
+
publishableKey: options.publishableKey,
|
|
246
|
+
frontendApi: baseUrl,
|
|
247
|
+
fetchImpl,
|
|
248
|
+
tombstoneStore: options.tombstoneStore ??
|
|
249
|
+
(rawStore instanceof storage_1.StorageCache ? rawStore.tombstoneStore() : (0, storage_1.createChromeTombstoneStore)()),
|
|
250
|
+
...(options.signOutRetryDelaysMs ? { retryDelaysMs: options.signOutRetryDelaysMs } : {}),
|
|
251
|
+
});
|
|
252
|
+
const store = signOutGuard.guardStore(rawStore);
|
|
95
253
|
const fapi = new js_1.FapiClient({
|
|
96
254
|
publishableKey: options.publishableKey,
|
|
97
255
|
baseUrl,
|
|
@@ -104,15 +262,20 @@ function createAtlasClient(options) {
|
|
|
104
262
|
setToken: (token) => store.setToken(token),
|
|
105
263
|
getProviderToken: (provider) => getProviderTokenFor(fapi, provider),
|
|
106
264
|
syncSessionToken: (opts) => syncSessionToken(client, opts),
|
|
107
|
-
signOut: async () => {
|
|
108
|
-
const
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
265
|
+
signOut: async (opts = {}) => {
|
|
266
|
+
const token = await rawStore.getToken().catch(() => null);
|
|
267
|
+
await signOutGuard.guard.ready;
|
|
268
|
+
// Tombstones the session (when the token names it) before anything below
|
|
269
|
+
// yields; with a token but no `sid`, GET /v1/client finds it. The revoke
|
|
270
|
+
// rides on the token being dropped, so its background re-try still can.
|
|
271
|
+
const pending = token
|
|
272
|
+
? signOutGuard.guard.revoke(sidOf(token), { ...opts, request: signOutGuard.bearerRequest(token) })
|
|
273
|
+
: null;
|
|
274
|
+
// The local token is cleared regardless, so no surface keeps showing a
|
|
275
|
+
// signed-in state after sign-out (the tombstone covers a failed clear).
|
|
276
|
+
await rawStore.removeToken().catch(() => undefined);
|
|
277
|
+
const attempt = pending ? await pending : { sessionId: null, outcome: { revoked: true, status: 200 } };
|
|
278
|
+
return signOutGuard.guard.settle(attempt, opts);
|
|
116
279
|
},
|
|
117
280
|
};
|
|
118
281
|
return client;
|
|
@@ -172,4 +335,6 @@ async function getProviderTokenFor(fapi, provider) {
|
|
|
172
335
|
scopes: response.data.scopes ?? [],
|
|
173
336
|
};
|
|
174
337
|
}
|
|
338
|
+
var js_2 = require("@atlasauth/js");
|
|
339
|
+
Object.defineProperty(exports, "SignOutError", { enumerable: true, get: function () { return js_2.SignOutError; } });
|
|
175
340
|
//# sourceMappingURL=client.js.map
|
package/dist/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":";;AA8BA,8CAUC;AAQD,kCAOC;AAsBD,sDAoBC;AAuCD,8CAqCC;AAsBD,4CA6BC;AAhOD,sCAMuB;AACvB,uCAA0D;AAoB1D;;6EAE6E;AAC7E,SAAgB,iBAAiB,CAAC,GAAW;IAC3C,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC7B,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IACpC,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,KAAK,CACf,IAAI,CAAC,KAAK,CAAC,CAAC,CAAE,CAAC,OAAO,CAAC,IAAI,EAAE,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AC,IAAI,EAAE,GAAG;QAAE,OAAO,OAAO,CAAC;IAExD,MAAM,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC/C,OAAO,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC;AAC3B,CAAC;AAED;;;;GAIG;AACH,KAAK,UAAU,mBAAmB,CAChC,IAAgB,EAChB,QAAgB;IAEhB,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,GAAG,CAK5B,mCAAmC,kBAAkB,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAE5E,IAAI,CAAC,QAAQ,CAAC,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI;QAAE,OAAO,IAAI,CAAC;IAChD,OAAO;QACL,QAAQ,EAAE,QAAQ,CAAC,IAAI,CAAC,QAAQ;QAChC,WAAW,EAAE,QAAQ,CAAC,IAAI,CAAC,YAAY;QACvC,SAAS,EAAE,QAAQ,CAAC,IAAI,CAAC,UAAU,IAAI,IAAI;QAC3C,MAAM,EAAE,QAAQ,CAAC,IAAI,CAAC,MAAM,IAAI,EAAE;KACnC,CAAC;AACJ,CAAC;AAED,oCAA+H;AAAtH,kGAAA,YAAY,OAAA"}
|
package/dist/react.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type TombstoneStore } from '@atlasauth/js';
|
|
1
2
|
import { type AtlasProviderProps } from '@atlasauth/react';
|
|
2
3
|
import { type TokenStore } from './storage';
|
|
3
4
|
/**
|
|
@@ -19,6 +20,14 @@ import { type TokenStore } from './storage';
|
|
|
19
20
|
* `syncSessionToken`, `StorageCache`) from the package root instead and never
|
|
20
21
|
* pulls React in.
|
|
21
22
|
*
|
|
23
|
+
* Sign-out is `@atlasauth/react`'s (`signOut(options?)` resolving
|
|
24
|
+
* `SignOutResult`, `{ strict: true }` rejecting with `SignOutError`), made safe
|
|
25
|
+
* for the surfaces sharing `chrome.storage`: revoking the stored token's session
|
|
26
|
+
* tombstones it in `chrome.storage.local` and drops the token for every surface,
|
|
27
|
+
* a stored token of a signed-out session is never sent (so a boot on any surface
|
|
28
|
+
* stays signed out — its revoke is re-tried in the background) nor written back
|
|
29
|
+
* by a refresh that was in flight.
|
|
30
|
+
*
|
|
22
31
|
* The token must already be in the store (seed it with `client.setToken(jwt)`
|
|
23
32
|
* after a hosted sign-in, or let a prior session persist it). This provider does
|
|
24
33
|
* not itself drive the sign-in UI flow.
|
|
@@ -28,6 +37,11 @@ export interface ChromeAtlasProviderProps extends Omit<AtlasProviderProps, 'fetc
|
|
|
28
37
|
store?: TokenStore;
|
|
29
38
|
/** Base `fetch` to wrap (before bearer/persist). Defaults to the platform `fetch`. */
|
|
30
39
|
fetchImpl?: typeof fetch;
|
|
40
|
+
/**
|
|
41
|
+
* Where the ids of sessions the extension signed out of are kept, shared by
|
|
42
|
+
* every surface. Defaults to the {@link StorageCache}'s area (else `chrome.storage.local`).
|
|
43
|
+
*/
|
|
44
|
+
tombstoneStore?: TombstoneStore;
|
|
31
45
|
}
|
|
32
46
|
export declare function AtlasProvider(props: ChromeAtlasProviderProps): import("react").FunctionComponentElement<AtlasProviderProps>;
|
|
33
47
|
export * from '@atlasauth/react';
|
package/dist/react.js
CHANGED
|
@@ -16,12 +16,24 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
exports.AtlasProvider = AtlasProvider;
|
|
18
18
|
const react_1 = require("react");
|
|
19
|
+
const js_1 = require("@atlasauth/js");
|
|
19
20
|
const react_2 = require("@atlasauth/react");
|
|
20
21
|
const client_1 = require("./client");
|
|
21
22
|
const storage_1 = require("./storage");
|
|
22
23
|
function AtlasProvider(props) {
|
|
23
|
-
const { store, fetchImpl, ...rest } = props;
|
|
24
|
-
const
|
|
24
|
+
const { store, fetchImpl, tombstoneStore, ...rest } = props;
|
|
25
|
+
const tokenStore = (0, react_1.useMemo)(() => store ?? new storage_1.StorageCache(), [store]);
|
|
26
|
+
const signOutGuard = (0, react_1.useMemo)(() => new client_1.ExtensionSignOutGuard({
|
|
27
|
+
publishableKey: rest.publishableKey,
|
|
28
|
+
// Throws the same AtlasConfigError the React provider would.
|
|
29
|
+
frontendApi: (0, js_1.resolveFrontendApi)(rest.frontendApi, { component: '<AtlasProvider>' }),
|
|
30
|
+
...(fetchImpl ? { fetchImpl } : {}),
|
|
31
|
+
tombstoneStore: tombstoneStore ??
|
|
32
|
+
(tokenStore instanceof storage_1.StorageCache ? tokenStore.tombstoneStore() : (0, storage_1.createChromeTombstoneStore)()),
|
|
33
|
+
}), [rest.publishableKey, rest.frontendApi, fetchImpl, tombstoneStore, tokenStore]);
|
|
34
|
+
// Cancel scheduled background revokes when the provider goes away.
|
|
35
|
+
(0, react_1.useEffect)(() => () => signOutGuard.guard.dispose(), [signOutGuard]);
|
|
36
|
+
const wrappedFetch = (0, react_1.useMemo)(() => (0, client_1.persistingBearerFetch)(fetchImpl ?? fetch, tokenStore, signOutGuard), [tokenStore, fetchImpl, signOutGuard]);
|
|
25
37
|
return (0, react_1.createElement)(react_2.AtlasProvider, { ...rest, fetchImpl: wrappedFetch });
|
|
26
38
|
}
|
|
27
39
|
// Re-export the React SDK surface so extension code has one import site for the
|
package/dist/react.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react.js","sourceRoot":"","sources":["../src/react.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"react.js","sourceRoot":"","sources":["../src/react.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAiDA,sCA0BC;AA3ED,iCAA0D;AAC1D,sCAAwE;AACxE,4CAAgG;AAChG,qCAAwE;AACxE,uCAAsF;AA6CtF,SAAgB,aAAa,CAAC,KAA+B;IAC3D,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,GAAG,IAAI,EAAE,GAAG,KAAK,CAAC;I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
CHANGED
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
* (the FAPI client, the background sync, the React provider) reads and writes it
|
|
21
21
|
* only through the {@link TokenStore} interface below.
|
|
22
22
|
*/
|
|
23
|
+
import type { TombstoneStore } from '@atlasauth/js';
|
|
23
24
|
/**
|
|
24
25
|
* The minimal, structural shape of the two `chrome.storage.local` methods this
|
|
25
26
|
* package uses. Declared here — rather than pulled from `@types/chrome` — so the
|
|
@@ -69,7 +70,20 @@ export declare class StorageCache implements TokenStore {
|
|
|
69
70
|
getToken(): Promise<string | null>;
|
|
70
71
|
setToken(token: string): Promise<void>;
|
|
71
72
|
removeToken(): Promise<void>;
|
|
73
|
+
/**
|
|
74
|
+
* A {@link TombstoneStore} over this cache's storage area — where the ids of
|
|
75
|
+
* sessions the extension signed out of are kept, so no surface re-adopts one.
|
|
76
|
+
*/
|
|
77
|
+
tombstoneStore(): TombstoneStore;
|
|
72
78
|
}
|
|
79
|
+
/**
|
|
80
|
+
* A {@link TombstoneStore} over `chrome.storage.local` (or the given area): the
|
|
81
|
+
* sign-out tombstones `SignOutGuard` keeps (session ids, never tokens), shared by
|
|
82
|
+
* every extension surface and surviving the service worker being torn down.
|
|
83
|
+
* `chrome` is resolved on first use; with none, reads and writes reject (the
|
|
84
|
+
* guard then falls back to memory).
|
|
85
|
+
*/
|
|
86
|
+
export declare function createChromeTombstoneStore(area?: ChromeStorageArea | (() => ChromeStorageArea)): TombstoneStore;
|
|
73
87
|
/**
|
|
74
88
|
* An in-memory `ChromeStorageArea`, for tests and for prototyping outside an
|
|
75
89
|
* extension. It implements the same async contract as the real thing but keeps
|
package/dist/storage.js
CHANGED
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
*/
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
25
|
exports.StorageCache = exports.DEFAULT_TOKEN_KEY = void 0;
|
|
26
|
+
exports.createChromeTombstoneStore = createChromeTombstoneStore;
|
|
26
27
|
exports.createMemoryStorageArea = createMemoryStorageArea;
|
|
27
28
|
/** The storage key the token is kept under. Namespaced to avoid collisions. */
|
|
28
29
|
exports.DEFAULT_TOKEN_KEY = '__atlas_session_token';
|
|
@@ -69,8 +70,34 @@ class StorageCache {
|
|
|
69
70
|
async removeToken() {
|
|
70
71
|
await this.storage().remove(this.key);
|
|
71
72
|
}
|
|
73
|
+
/**
|
|
74
|
+
* A {@link TombstoneStore} over this cache's storage area — where the ids of
|
|
75
|
+
* sessions the extension signed out of are kept, so no surface re-adopts one.
|
|
76
|
+
*/
|
|
77
|
+
tombstoneStore() {
|
|
78
|
+
return createChromeTombstoneStore(() => this.storage());
|
|
79
|
+
}
|
|
72
80
|
}
|
|
73
81
|
exports.StorageCache = StorageCache;
|
|
82
|
+
/**
|
|
83
|
+
* A {@link TombstoneStore} over `chrome.storage.local` (or the given area): the
|
|
84
|
+
* sign-out tombstones `SignOutGuard` keeps (session ids, never tokens), shared by
|
|
85
|
+
* every extension surface and surviving the service worker being torn down.
|
|
86
|
+
* `chrome` is resolved on first use; with none, reads and writes reject (the
|
|
87
|
+
* guard then falls back to memory).
|
|
88
|
+
*/
|
|
89
|
+
function createChromeTombstoneStore(area) {
|
|
90
|
+
const resolve = () => typeof area === 'function' ? area() : (area ?? resolveChromeLocal());
|
|
91
|
+
return {
|
|
92
|
+
getItem: async (key) => {
|
|
93
|
+
const value = (await resolve().get(key))[key];
|
|
94
|
+
return typeof value === 'string' ? value : null;
|
|
95
|
+
},
|
|
96
|
+
setItem: async (key, value) => {
|
|
97
|
+
await resolve().set({ [key]: value });
|
|
98
|
+
},
|
|
99
|
+
};
|
|
100
|
+
}
|
|
74
101
|
/**
|
|
75
102
|
* An in-memory `ChromeStorageArea`, for tests and for prototyping outside an
|
|
76
103
|
* extension. It implements the same async contract as the real thing but keeps
|
package/dist/storage.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storage.js","sourceRoot":"","sources":["../src/storage.ts"],"names":[],"mappings":";AAAA;;;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|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"exports": {
|
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
}
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@atlasauth/react": "0.
|
|
22
|
-
"@atlasauth/js": "0.
|
|
21
|
+
"@atlasauth/react": "0.7.0",
|
|
22
|
+
"@atlasauth/js": "0.8.0"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
25
25
|
"react": ">=18"
|