@atlasauth/chrome-extension 0.1.0 → 0.2.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/README.md +20 -0
- package/dist/background.d.ts +1 -0
- package/dist/background.js +1 -0
- package/dist/background.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/native-session.d.ts +49 -0
- package/dist/native-session.js +58 -0
- package/dist/native-session.js.map +1 -0
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -88,3 +88,23 @@ Add the `storage` permission and the Atlas FAPI origin as a host permission:
|
|
|
88
88
|
"host_permissions": ["https://fapi.your-instance.atlasauth.net/*"]
|
|
89
89
|
}
|
|
90
90
|
```
|
|
91
|
+
|
|
92
|
+
## Native session (first-party OAuth → session)
|
|
93
|
+
|
|
94
|
+
A first-party extension holding an Atlas OAuth access token can trade it for a
|
|
95
|
+
cookie-free session with `createNativeSessionManager`. It persists each rotated
|
|
96
|
+
refresh token in `chrome.storage` under its own key, so a woken service worker
|
|
97
|
+
rehydrates it and auto-refreshes the short-lived JWT:
|
|
98
|
+
|
|
99
|
+
```ts
|
|
100
|
+
import { createNativeSessionManager, exchangeForSession } from '@atlasauth/chrome-extension';
|
|
101
|
+
|
|
102
|
+
const mgr = await createNativeSessionManager({
|
|
103
|
+
frontendApi: 'https://fapi.your-instance.atlasauth.net',
|
|
104
|
+
publishableKey: 'pk_...',
|
|
105
|
+
});
|
|
106
|
+
const session = await exchangeForSession({ baseUrl, clientId, accessToken });
|
|
107
|
+
if (session) mgr.setSession(session);
|
|
108
|
+
|
|
109
|
+
const headers = await mgr.authHeaders(); // { Authorization, 'x-publishable-key' }
|
|
110
|
+
```
|
package/dist/background.d.ts
CHANGED
package/dist/background.js
CHANGED
package/dist/background.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"background.js","sourceRoot":"","sources":["../src/background.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,4CAA0B;AAC1B,2CAAyB"}
|
|
1
|
+
{"version":3,"file":"background.js","sourceRoot":"","sources":["../src/background.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,4CAA0B;AAC1B,2CAAyB;AACzB,mDAAiC"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;GAYG;AACH,4CAA0B;AAC1B,2CAAyB"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;GAYG;AACH,4CAA0B;AAC1B,2CAAyB;AACzB,mDAAiC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Native session for a Chrome / MV3 extension.
|
|
3
|
+
*
|
|
4
|
+
* A thin wiring of the framework-agnostic {@link NativeSessionManager} from
|
|
5
|
+
* `@atlasauth/js` to this package's {@link TokenStore} over `chrome.storage`.
|
|
6
|
+
* The core manager owns the exchange/refresh/rotation; this file persists each
|
|
7
|
+
* rotated session into `chrome.storage.local` (so the rotating refresh token
|
|
8
|
+
* survives the service worker being torn down AND is readable from every
|
|
9
|
+
* extension surface) and rehydrates the manager from it on each cold start.
|
|
10
|
+
*
|
|
11
|
+
* The whole session is stored as one JSON string under its OWN key, separate
|
|
12
|
+
* from {@link StorageCache}'s session-token slot, so the two coexist.
|
|
13
|
+
*/
|
|
14
|
+
import { NativeSessionManager } from '@atlasauth/js';
|
|
15
|
+
import { type TokenStore } from './storage';
|
|
16
|
+
/** The `chrome.storage` key the serialized native session is kept under. */
|
|
17
|
+
export declare const DEFAULT_NATIVE_SESSION_KEY = "__atlas_native_session";
|
|
18
|
+
export interface NativeSessionOptions {
|
|
19
|
+
/** The instance's FAPI origin, e.g. `https://fapi.acme.atlasauth.net`. */
|
|
20
|
+
frontendApi: string;
|
|
21
|
+
/** The publishable key — sent on the refresh call and in `authHeaders()`. */
|
|
22
|
+
publishableKey: string;
|
|
23
|
+
/** The first-party OAuth client id (for a later in-manager exchange). */
|
|
24
|
+
clientId?: string;
|
|
25
|
+
/**
|
|
26
|
+
* Where the session is persisted. Defaults to a {@link StorageCache} over
|
|
27
|
+
* `chrome.storage.local` under {@link DEFAULT_NATIVE_SESSION_KEY}. Inject a
|
|
28
|
+
* memory-backed store (see `createMemoryStorageArea`) in tests.
|
|
29
|
+
*/
|
|
30
|
+
store?: TokenStore;
|
|
31
|
+
/** Injectable for tests; defaults to the platform `fetch`. */
|
|
32
|
+
fetchImpl?: typeof fetch;
|
|
33
|
+
/** Injectable clock, epoch ms. Defaults to `Date.now`. */
|
|
34
|
+
now?: () => number;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Build a {@link NativeSessionManager} wired to `chrome.storage`.
|
|
38
|
+
*
|
|
39
|
+
* Async because `chrome.storage` is async: it reads whatever session the store
|
|
40
|
+
* holds and seeds the manager, so a freshly-woken service worker (or a reopened
|
|
41
|
+
* popup) is signed in before its first request. Thereafter every rotation is
|
|
42
|
+
* written straight back through the manager's `persist` hook, so the next
|
|
43
|
+
* surface — and the next cold start — picks up the rotated refresh token.
|
|
44
|
+
*/
|
|
45
|
+
export declare function createNativeSessionManager(options: NativeSessionOptions): Promise<NativeSessionManager>;
|
|
46
|
+
/** Clear the persisted native session (sign-out). */
|
|
47
|
+
export declare function clearNativeSession(store: TokenStore): Promise<void>;
|
|
48
|
+
export { NativeSessionManager, type NativeSession } from '@atlasauth/js';
|
|
49
|
+
export { exchangeForSession, refreshNativeSession } from '@atlasauth/js';
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Native session for a Chrome / MV3 extension.
|
|
4
|
+
*
|
|
5
|
+
* A thin wiring of the framework-agnostic {@link NativeSessionManager} from
|
|
6
|
+
* `@atlasauth/js` to this package's {@link TokenStore} over `chrome.storage`.
|
|
7
|
+
* The core manager owns the exchange/refresh/rotation; this file persists each
|
|
8
|
+
* rotated session into `chrome.storage.local` (so the rotating refresh token
|
|
9
|
+
* survives the service worker being torn down AND is readable from every
|
|
10
|
+
* extension surface) and rehydrates the manager from it on each cold start.
|
|
11
|
+
*
|
|
12
|
+
* The whole session is stored as one JSON string under its OWN key, separate
|
|
13
|
+
* from {@link StorageCache}'s session-token slot, so the two coexist.
|
|
14
|
+
*/
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.refreshNativeSession = exports.exchangeForSession = exports.NativeSessionManager = exports.DEFAULT_NATIVE_SESSION_KEY = void 0;
|
|
17
|
+
exports.createNativeSessionManager = createNativeSessionManager;
|
|
18
|
+
exports.clearNativeSession = clearNativeSession;
|
|
19
|
+
const js_1 = require("@atlasauth/js");
|
|
20
|
+
const storage_1 = require("./storage");
|
|
21
|
+
/** The `chrome.storage` key the serialized native session is kept under. */
|
|
22
|
+
exports.DEFAULT_NATIVE_SESSION_KEY = '__atlas_native_session';
|
|
23
|
+
/**
|
|
24
|
+
* Build a {@link NativeSessionManager} wired to `chrome.storage`.
|
|
25
|
+
*
|
|
26
|
+
* Async because `chrome.storage` is async: it reads whatever session the store
|
|
27
|
+
* holds and seeds the manager, so a freshly-woken service worker (or a reopened
|
|
28
|
+
* popup) is signed in before its first request. Thereafter every rotation is
|
|
29
|
+
* written straight back through the manager's `persist` hook, so the next
|
|
30
|
+
* surface — and the next cold start — picks up the rotated refresh token.
|
|
31
|
+
*/
|
|
32
|
+
async function createNativeSessionManager(options) {
|
|
33
|
+
const store = options.store ?? new storage_1.StorageCache({ key: exports.DEFAULT_NATIVE_SESSION_KEY });
|
|
34
|
+
const initial = (0, js_1.parseNativeSession)(await store.getToken()) ?? undefined;
|
|
35
|
+
return new js_1.NativeSessionManager({
|
|
36
|
+
baseUrl: options.frontendApi,
|
|
37
|
+
publishableKey: options.publishableKey,
|
|
38
|
+
clientId: options.clientId,
|
|
39
|
+
initial,
|
|
40
|
+
fetchImpl: options.fetchImpl,
|
|
41
|
+
now: options.now,
|
|
42
|
+
// Fire-and-forget: `chrome.storage` writes are async and a failure must not
|
|
43
|
+
// break the live session held in memory.
|
|
44
|
+
persist: (session) => {
|
|
45
|
+
void store.setToken((0, js_1.serializeNativeSession)(session)).catch(() => undefined);
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
/** Clear the persisted native session (sign-out). */
|
|
50
|
+
async function clearNativeSession(store) {
|
|
51
|
+
await store.removeToken();
|
|
52
|
+
}
|
|
53
|
+
var js_2 = require("@atlasauth/js");
|
|
54
|
+
Object.defineProperty(exports, "NativeSessionManager", { enumerable: true, get: function () { return js_2.NativeSessionManager; } });
|
|
55
|
+
var js_3 = require("@atlasauth/js");
|
|
56
|
+
Object.defineProperty(exports, "exchangeForSession", { enumerable: true, get: function () { return js_3.exchangeForSession; } });
|
|
57
|
+
Object.defineProperty(exports, "refreshNativeSession", { enumerable: true, get: function () { return js_3.refreshNativeSession; } });
|
|
58
|
+
//# sourceMappingURL=native-session.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"native-session.js","sourceRoot":"","sources":["../src/native-session.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;GAYG;;;AAyCH,gEAmBC;AAGD,gDAEC;AA/DD,sCAKuB;AACvB,uCAA0D;AAE1D,4EAA4E;AAC/D,QAAA,0BAA0B,GAAG,wBAAwB,CAAC;AAqBnE;;;;;;;;GAQG;AACI,KAAK,UAAU,0BAA0B,CAC9C,OAA6B;IAE7B,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,IAAI,IAAI,sBAAY,CAAC,EAAE,GAAG,EAAE,kCAA0B,EAAE,CAAC,CAAC;IACrF,MAAM,OAAO,GAAG,IAAA,uBAAkB,EAAC,MAAM,KAAK,CAAC,QAAQ,EAAE,CAAC,IAAI,SAAS,CAAC;IAExE,OAAO,IAAI,yBAAoB,CAAC;QAC9B,OAAO,EAAE,OAAO,CAAC,WAAW;QAC5B,cAAc,EAAE,OAAO,CAAC,cAAc;QACtC,QAAQ,EAAE,OAAO,CAAC,QAAQ;QAC1B,OAAO;QACP,SAAS,EAAE,OAAO,CAAC,SAAS;QAC5B,GAAG,EAAE,OAAO,CAAC,GAAG;QAChB,4EAA4E;QAC5E,yCAAyC;QACzC,OAAO,EAAE,CAAC,OAAsB,EAAE,EAAE;YAClC,KAAK,KAAK,CAAC,QAAQ,CAAC,IAAA,2BAAsB,EAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;QAC9E,CAAC;KACF,CAAC,CAAC;AACL,CAAC;AAED,qDAAqD;AAC9C,KAAK,UAAU,kBAAkB,CAAC,KAAiB;IACxD,MAAM,KAAK,CAAC,WAAW,EAAE,CAAC;AAC5B,CAAC;AAED,oCAAyE;AAAhE,0GAAA,oBAAoB,OAAA;AAC7B,oCAAyE;AAAhE,wGAAA,kBAAkB,OAAA;AAAE,0GAAA,oBAAoB,OAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlasauth/chrome-extension",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.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/js": "0.
|
|
22
|
-
"@atlasauth/react": "0.1.
|
|
21
|
+
"@atlasauth/js": "0.2.0",
|
|
22
|
+
"@atlasauth/react": "0.1.30"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
25
25
|
"react": ">=18"
|