@authoric/js 0.0.0-stage → 0.1.1
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/LICENSE +21 -0
- package/README.md +94 -3
- package/bin/authoric.mjs +345 -0
- package/dist/cjs/app-actions.js +40 -0
- package/dist/cjs/app-actions.js.map +1 -0
- package/dist/cjs/auth.js +335 -0
- package/dist/cjs/auth.js.map +1 -0
- package/dist/cjs/client.js +121 -0
- package/dist/cjs/client.js.map +1 -0
- package/dist/cjs/cookies.js +137 -0
- package/dist/cjs/cookies.js.map +1 -0
- package/dist/cjs/data.js +197 -0
- package/dist/cjs/data.js.map +1 -0
- package/dist/cjs/errors.js +70 -0
- package/dist/cjs/errors.js.map +1 -0
- package/dist/cjs/files.js +188 -0
- package/dist/cjs/files.js.map +1 -0
- package/dist/cjs/generated/error-codes.js +435 -0
- package/dist/cjs/generated/error-codes.js.map +1 -0
- package/dist/cjs/index.js +31 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/realtime.js +191 -0
- package/dist/cjs/realtime.js.map +1 -0
- package/dist/cjs/routes.js +113 -0
- package/dist/cjs/routes.js.map +1 -0
- package/dist/cjs/session.js +430 -0
- package/dist/cjs/session.js.map +1 -0
- package/dist/cjs/storage-adapters.js +83 -0
- package/dist/cjs/storage-adapters.js.map +1 -0
- package/dist/cjs/teams.js +152 -0
- package/dist/cjs/teams.js.map +1 -0
- package/dist/cjs/transport.js +189 -0
- package/dist/cjs/transport.js.map +1 -0
- package/dist/cjs/types.js +7 -0
- package/dist/cjs/types.js.map +1 -0
- package/dist/esm/app-actions.d.ts +32 -0
- package/dist/esm/app-actions.d.ts.map +1 -0
- package/dist/esm/app-actions.js +37 -0
- package/dist/esm/app-actions.js.map +1 -0
- package/dist/esm/auth.d.ts +259 -0
- package/dist/esm/auth.d.ts.map +1 -0
- package/dist/esm/auth.js +331 -0
- package/dist/esm/auth.js.map +1 -0
- package/dist/esm/client.d.ts +82 -0
- package/dist/esm/client.d.ts.map +1 -0
- package/dist/esm/client.js +115 -0
- package/dist/esm/client.js.map +1 -0
- package/dist/esm/cookies.d.ts +66 -0
- package/dist/esm/cookies.d.ts.map +1 -0
- package/dist/esm/cookies.js +129 -0
- package/dist/esm/cookies.js.map +1 -0
- package/dist/esm/data.d.ts +211 -0
- package/dist/esm/data.d.ts.map +1 -0
- package/dist/esm/data.js +191 -0
- package/dist/esm/data.js.map +1 -0
- package/dist/esm/errors.d.ts +61 -0
- package/dist/esm/errors.d.ts.map +1 -0
- package/dist/esm/errors.js +63 -0
- package/dist/esm/errors.js.map +1 -0
- package/dist/esm/files.d.ts +76 -0
- package/dist/esm/files.d.ts.map +1 -0
- package/dist/esm/files.js +184 -0
- package/dist/esm/files.js.map +1 -0
- package/dist/esm/generated/error-codes.d.ts +5 -0
- package/dist/esm/generated/error-codes.d.ts.map +1 -0
- package/dist/esm/generated/error-codes.js +432 -0
- package/dist/esm/generated/error-codes.js.map +1 -0
- package/dist/esm/index.d.ts +22 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +9 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/realtime.d.ts +33 -0
- package/dist/esm/realtime.d.ts.map +1 -0
- package/dist/esm/realtime.js +186 -0
- package/dist/esm/realtime.js.map +1 -0
- package/dist/esm/routes.d.ts +75 -0
- package/dist/esm/routes.d.ts.map +1 -0
- package/dist/esm/routes.js +108 -0
- package/dist/esm/routes.js.map +1 -0
- package/dist/esm/session.d.ts +99 -0
- package/dist/esm/session.d.ts.map +1 -0
- package/dist/esm/session.js +425 -0
- package/dist/esm/session.js.map +1 -0
- package/dist/esm/storage-adapters.d.ts +31 -0
- package/dist/esm/storage-adapters.d.ts.map +1 -0
- package/dist/esm/storage-adapters.js +76 -0
- package/dist/esm/storage-adapters.js.map +1 -0
- package/dist/esm/teams.d.ts +157 -0
- package/dist/esm/teams.d.ts.map +1 -0
- package/dist/esm/teams.js +146 -0
- package/dist/esm/teams.js.map +1 -0
- package/dist/esm/transport.d.ts +56 -0
- package/dist/esm/transport.d.ts.map +1 -0
- package/dist/esm/transport.js +185 -0
- package/dist/esm/transport.js.map +1 -0
- package/dist/esm/types.d.ts +203 -0
- package/dist/esm/types.d.ts.map +1 -0
- package/dist/esm/types.js +6 -0
- package/dist/esm/types.js.map +1 -0
- package/package.json +54 -6
|
@@ -0,0 +1,425 @@
|
|
|
1
|
+
// The signed-in session: where its tokens live, how they are refreshed, and how it ends.
|
|
2
|
+
//
|
|
3
|
+
// The rules (notes/client-sdk-plan.md, "Tokens"):
|
|
4
|
+
// - The ACCESS token lives in memory only. Only the refresh token and the session's public facts are
|
|
5
|
+
// persisted, through the storage adapter. The one exception is a SERVER client
|
|
6
|
+
// (createServerClient, §2.2): a server has no memory between requests, so its cookie carries the
|
|
7
|
+
// 15-minute access token too, or every page load would spend the single-use refresh token.
|
|
8
|
+
// - Refresh tokens are single-use. The server gives a second tab the current token when it presents
|
|
9
|
+
// the immediately previous one within its grace window, but anything older is treated as THEFT and
|
|
10
|
+
// ends the session. So one refresh at a time, ACROSS TABS: a refresh takes a Web Lock named for the
|
|
11
|
+
// app, re-reads storage inside it, and announces the result over a BroadcastChannel.
|
|
12
|
+
// - `SESSION_ENDED` is terminal: clear everything, tell the app, never retry.
|
|
13
|
+
import { AuthoricError, clientError } from "./errors.js";
|
|
14
|
+
const RECORD_VERSION = 1;
|
|
15
|
+
// Refresh this long before the access token expires, so a request never leaves with one about to lapse.
|
|
16
|
+
const EXPIRY_SKEW_MS = 60000;
|
|
17
|
+
const decodeJwtExpiry = (token) => {
|
|
18
|
+
const part = token.split(".")[1];
|
|
19
|
+
if (!part)
|
|
20
|
+
return null;
|
|
21
|
+
try {
|
|
22
|
+
const json = typeof atob === "function"
|
|
23
|
+
? atob(part.replace(/-/g, "+").replace(/_/g, "/").padEnd(Math.ceil(part.length / 4) * 4, "="))
|
|
24
|
+
: "";
|
|
25
|
+
const exp = JSON.parse(json)?.exp;
|
|
26
|
+
return typeof exp === "number" ? exp * 1000 : null;
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
const asRecord = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : null;
|
|
33
|
+
const ACCOUNT_FIELDS = ["uid", "email", "fname", "lname", "status", "created_at", "updated_at"];
|
|
34
|
+
// An allow-list: the session keeps the account fields the API publishes and nothing else, so a field
|
|
35
|
+
// added to a response later is not silently persisted.
|
|
36
|
+
const toAccount = (value) => {
|
|
37
|
+
const source = asRecord(value);
|
|
38
|
+
if (!source || typeof source.uid !== "string" || !source.uid)
|
|
39
|
+
return null;
|
|
40
|
+
const account = {};
|
|
41
|
+
for (const key of ACCOUNT_FIELDS)
|
|
42
|
+
if (source[key] !== undefined)
|
|
43
|
+
account[key] = source[key];
|
|
44
|
+
return account;
|
|
45
|
+
};
|
|
46
|
+
const toOrg = (value) => {
|
|
47
|
+
const source = asRecord(value);
|
|
48
|
+
if (!source)
|
|
49
|
+
return null;
|
|
50
|
+
return {
|
|
51
|
+
uid: typeof source.uid === "string" ? source.uid : null,
|
|
52
|
+
name: typeof source.name === "string" ? source.name : null,
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Every Authoric secret is labelled: `au_agent_` (an agent API key), `au_deploy_` (a deploy key),
|
|
57
|
+
* `au_approver_` (an approver token), and the legacy `plak_` agent key. None of them ever belongs in
|
|
58
|
+
* a client, which speaks only for an app's own signed-in users.
|
|
59
|
+
*/
|
|
60
|
+
export const SECRET_SHAPE = /^\s*(bearer\s+)?(au_[a-z]+_|plak_)/i;
|
|
61
|
+
/** Refuse anything that is a secret rather than an end user's token. */
|
|
62
|
+
export const assertNotSecret = (token) => {
|
|
63
|
+
if (typeof token === "string" && SECRET_SHAPE.test(token)) {
|
|
64
|
+
throw clientError("AUTHORIC_SECRET_IN_CLIENT", "That is an Authoric secret (`au_…`): an agent key, deploy key or approver token. It must never be used in a client: keep it on a server.");
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
// Whether a failed REFRESH means the session is over. Any refusal of the refresh token itself is:
|
|
68
|
+
// ended, revoked or reused (401 SESSION_ENDED), expired or unreadable (401 / 400), the user's access
|
|
69
|
+
// withdrawn (403), the app gone (404). A network failure, a 5xx or a rate limit is not: the session is
|
|
70
|
+
// still good, and the next request tries again.
|
|
71
|
+
const isTerminal = (error) => error instanceof AuthoricError &&
|
|
72
|
+
(error.code === "SESSION_ENDED" || [400, 401, 403, 404].includes(error.status ?? 0));
|
|
73
|
+
const locks = () => {
|
|
74
|
+
const nav = globalThis.navigator;
|
|
75
|
+
return nav?.locks && typeof nav.locks.request === "function" ? nav.locks : null;
|
|
76
|
+
};
|
|
77
|
+
export class SessionManager {
|
|
78
|
+
constructor(options) {
|
|
79
|
+
this.listeners = new Set();
|
|
80
|
+
this.accessToken = null;
|
|
81
|
+
this.accessExpiresAt = null;
|
|
82
|
+
this.record = null;
|
|
83
|
+
this.loaded = null;
|
|
84
|
+
this.inflight = null;
|
|
85
|
+
this.appUid = options.appUid;
|
|
86
|
+
this.storage = options.storage;
|
|
87
|
+
this.exchange = options.exchange;
|
|
88
|
+
this.now = options.now ?? (() => Date.now());
|
|
89
|
+
this.persistAccessToken = options.persistAccessToken === true;
|
|
90
|
+
this.storageKey = `authoric.session.${options.appUid}`;
|
|
91
|
+
this.deviceKey = `authoric.device.${options.appUid}`;
|
|
92
|
+
this.channel = options.channel === undefined ? openChannel(options.appUid) : options.channel;
|
|
93
|
+
this.channel?.addEventListener("message", (event) => this.onBroadcast(event.data));
|
|
94
|
+
}
|
|
95
|
+
// ── Reading ────────────────────────────────────────────────────────────────────────────────────
|
|
96
|
+
async load() {
|
|
97
|
+
if (!this.loaded) {
|
|
98
|
+
this.loaded = (async () => {
|
|
99
|
+
this.record = await this.readStored();
|
|
100
|
+
// A server client picks up the access token its cookie carries; a browser never stores one.
|
|
101
|
+
if (this.persistAccessToken && typeof this.record?.at === "string" && this.record.at) {
|
|
102
|
+
assertNotSecret(this.record.at);
|
|
103
|
+
this.accessToken = this.record.at;
|
|
104
|
+
this.accessExpiresAt = decodeJwtExpiry(this.record.at);
|
|
105
|
+
}
|
|
106
|
+
})();
|
|
107
|
+
}
|
|
108
|
+
await this.loaded;
|
|
109
|
+
}
|
|
110
|
+
async readStored() {
|
|
111
|
+
let raw = null;
|
|
112
|
+
try {
|
|
113
|
+
raw = await this.storage.getItem(this.storageKey);
|
|
114
|
+
}
|
|
115
|
+
catch {
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
if (!raw)
|
|
119
|
+
return null;
|
|
120
|
+
try {
|
|
121
|
+
const parsed = JSON.parse(raw);
|
|
122
|
+
if (parsed?.v !== RECORD_VERSION || typeof parsed.refreshToken !== "string" || !toAccount(parsed.user)) {
|
|
123
|
+
return null;
|
|
124
|
+
}
|
|
125
|
+
return parsed;
|
|
126
|
+
}
|
|
127
|
+
catch {
|
|
128
|
+
return null;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
snapshot() {
|
|
132
|
+
if (!this.record)
|
|
133
|
+
return null;
|
|
134
|
+
return {
|
|
135
|
+
user: { ...this.record.user },
|
|
136
|
+
activeOrgUid: this.record.activeOrgUid,
|
|
137
|
+
org: this.record.org ? { ...this.record.org } : null,
|
|
138
|
+
mfaEnrollmentRequired: this.record.mfaEnrollmentRequired,
|
|
139
|
+
mfaEnrollment: this.record.mfaEnrollment,
|
|
140
|
+
accessTokenExpiresAt: this.accessToken ? this.accessExpiresAt : null,
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
async getSession() {
|
|
144
|
+
await this.load();
|
|
145
|
+
return this.snapshot();
|
|
146
|
+
}
|
|
147
|
+
/** A usable access token, refreshed first when it is missing or about to expire. Null when signed out. */
|
|
148
|
+
async getAccessToken() {
|
|
149
|
+
await this.load();
|
|
150
|
+
if (!this.record)
|
|
151
|
+
return null;
|
|
152
|
+
if (this.accessToken && (this.accessExpiresAt == null || this.accessExpiresAt - this.now() > EXPIRY_SKEW_MS)) {
|
|
153
|
+
return this.accessToken;
|
|
154
|
+
}
|
|
155
|
+
const session = await this.refresh();
|
|
156
|
+
return session ? this.accessToken : null;
|
|
157
|
+
}
|
|
158
|
+
async getDeviceToken() {
|
|
159
|
+
try {
|
|
160
|
+
return (await this.storage.getItem(this.deviceKey)) || null;
|
|
161
|
+
}
|
|
162
|
+
catch {
|
|
163
|
+
return null;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
onChange(listener) {
|
|
167
|
+
this.listeners.add(listener);
|
|
168
|
+
return () => {
|
|
169
|
+
this.listeners.delete(listener);
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
emit(change) {
|
|
173
|
+
for (const listener of [...this.listeners]) {
|
|
174
|
+
try {
|
|
175
|
+
listener(change);
|
|
176
|
+
}
|
|
177
|
+
catch {
|
|
178
|
+
// A listener's own bug must not break the session.
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
// ── Writing ────────────────────────────────────────────────────────────────────────────────────
|
|
183
|
+
/**
|
|
184
|
+
* Adopt a session payload from a sign-in door (`{ …account, org, auth: { accessToken,
|
|
185
|
+
* refreshToken, activeOrgUid } }`) or from a refresh (`{ accessToken, refreshToken, activeOrgUid,
|
|
186
|
+
* org }`), the two shapes the API answers with.
|
|
187
|
+
*/
|
|
188
|
+
async adopt(payload, event) {
|
|
189
|
+
await this.load();
|
|
190
|
+
const auth = asRecord(payload.auth) ?? payload;
|
|
191
|
+
const accessToken = auth.accessToken;
|
|
192
|
+
const refreshToken = auth.refreshToken;
|
|
193
|
+
if (typeof accessToken !== "string" || typeof refreshToken !== "string") {
|
|
194
|
+
throw clientError("AUTHORIC_BAD_RESPONSE", "The sign-in response carried no tokens.");
|
|
195
|
+
}
|
|
196
|
+
assertNotSecret(accessToken);
|
|
197
|
+
assertNotSecret(refreshToken);
|
|
198
|
+
if (payload.subjectType !== undefined && payload.subjectType !== "user") {
|
|
199
|
+
throw clientError("AUTHORIC_INVALID_CONFIG", "This session is not an app user's. The client SDK signs in an app's own users only.");
|
|
200
|
+
}
|
|
201
|
+
const user = toAccount(payload.auth ? payload : null) ?? this.record?.user ?? null;
|
|
202
|
+
if (!user)
|
|
203
|
+
throw clientError("AUTHORIC_BAD_RESPONSE", "The sign-in response named no account.");
|
|
204
|
+
const activeOrgUid = (typeof auth.activeOrgUid === "string" && auth.activeOrgUid) ||
|
|
205
|
+
(typeof payload.activeOrgUid === "string" && payload.activeOrgUid) ||
|
|
206
|
+
null;
|
|
207
|
+
const record = {
|
|
208
|
+
v: RECORD_VERSION,
|
|
209
|
+
refreshToken,
|
|
210
|
+
user,
|
|
211
|
+
activeOrgUid,
|
|
212
|
+
org: payload.org !== undefined ? toOrg(payload.org) : (this.record?.org ?? null),
|
|
213
|
+
mfaEnrollmentRequired: payload.mfaEnrollmentRequired === true,
|
|
214
|
+
mfaEnrollment: asRecord(payload.mfaEnrollment) ?? null,
|
|
215
|
+
};
|
|
216
|
+
const trusted = asRecord(payload.trustedDevice);
|
|
217
|
+
if (trusted && typeof trusted.deviceToken === "string") {
|
|
218
|
+
assertNotSecret(trusted.deviceToken);
|
|
219
|
+
await this.safeSet(this.deviceKey, trusted.deviceToken);
|
|
220
|
+
}
|
|
221
|
+
this.setTokens(record, accessToken);
|
|
222
|
+
await this.persist();
|
|
223
|
+
this.broadcast({ type: "session", accessToken, record });
|
|
224
|
+
const session = this.snapshot();
|
|
225
|
+
this.emit({ event, session });
|
|
226
|
+
return session;
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Restore a session from a refresh token the app holds itself (server-side rendering, a native
|
|
230
|
+
* secure store). The next request mints an access token from it.
|
|
231
|
+
*/
|
|
232
|
+
async setRefreshToken(refreshToken, user) {
|
|
233
|
+
assertNotSecret(refreshToken);
|
|
234
|
+
const account = toAccount(user);
|
|
235
|
+
if (!account)
|
|
236
|
+
throw clientError("AUTHORIC_INVALID_ARGUMENT", "setSession needs the account's uid.");
|
|
237
|
+
await this.load();
|
|
238
|
+
this.record = {
|
|
239
|
+
v: RECORD_VERSION,
|
|
240
|
+
refreshToken,
|
|
241
|
+
user: account,
|
|
242
|
+
activeOrgUid: null,
|
|
243
|
+
org: null,
|
|
244
|
+
mfaEnrollmentRequired: false,
|
|
245
|
+
mfaEnrollment: null,
|
|
246
|
+
};
|
|
247
|
+
this.accessToken = null;
|
|
248
|
+
this.accessExpiresAt = null;
|
|
249
|
+
await this.persist();
|
|
250
|
+
}
|
|
251
|
+
setTokens(record, accessToken) {
|
|
252
|
+
this.record = record;
|
|
253
|
+
this.accessToken = accessToken;
|
|
254
|
+
this.accessExpiresAt = decodeJwtExpiry(accessToken);
|
|
255
|
+
}
|
|
256
|
+
async persist() {
|
|
257
|
+
if (!this.record)
|
|
258
|
+
return;
|
|
259
|
+
const { at: _never, ...record } = this.record;
|
|
260
|
+
const stored = this.persistAccessToken && this.accessToken ? { ...record, at: this.accessToken } : record;
|
|
261
|
+
await this.safeSet(this.storageKey, JSON.stringify(stored));
|
|
262
|
+
}
|
|
263
|
+
async safeSet(key, value) {
|
|
264
|
+
try {
|
|
265
|
+
await this.storage.setItem(key, value);
|
|
266
|
+
}
|
|
267
|
+
catch (error) {
|
|
268
|
+
// The SDK's own refusal (a server cookie that would not fit) must be heard: swallowing it
|
|
269
|
+
// would sign the user out on the next request with no reason given.
|
|
270
|
+
if (error instanceof AuthoricError)
|
|
271
|
+
throw error;
|
|
272
|
+
// Anything else: not persisted; the session still works in this page.
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
async safeRemove(key) {
|
|
276
|
+
try {
|
|
277
|
+
await this.storage.removeItem(key);
|
|
278
|
+
}
|
|
279
|
+
catch {
|
|
280
|
+
// Nothing to remove.
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
// ── Refreshing ─────────────────────────────────────────────────────────────────────────────────
|
|
284
|
+
/**
|
|
285
|
+
* Trade the refresh token for a fresh pair. One at a time in this page, and one at a time across
|
|
286
|
+
* every tab of the app. `force` refreshes even when the access token is still good (after the user
|
|
287
|
+
* adds a 2FA factor); `activeOrgUid` makes the exchange an org switch.
|
|
288
|
+
*/
|
|
289
|
+
refresh(options = {}) {
|
|
290
|
+
// A plain refresh joins the one already running. A forced one or an org switch must make its
|
|
291
|
+
// own exchange, so it queues behind it instead: two exchanges never leave at once.
|
|
292
|
+
if (this.inflight && !options.force && !options.activeOrgUid)
|
|
293
|
+
return this.inflight;
|
|
294
|
+
const previous = this.inflight;
|
|
295
|
+
const run = async () => {
|
|
296
|
+
if (previous)
|
|
297
|
+
await previous.catch(() => null);
|
|
298
|
+
const startedWith = this.accessToken;
|
|
299
|
+
const work = () => this.refreshLocked(options, startedWith);
|
|
300
|
+
const manager = locks();
|
|
301
|
+
return manager ? manager.request(`authoric:refresh:${this.appUid}`, work) : work();
|
|
302
|
+
};
|
|
303
|
+
const promise = run().finally(() => {
|
|
304
|
+
if (this.inflight === promise)
|
|
305
|
+
this.inflight = null;
|
|
306
|
+
});
|
|
307
|
+
this.inflight = promise;
|
|
308
|
+
return promise;
|
|
309
|
+
}
|
|
310
|
+
async refreshLocked(options, startedWith) {
|
|
311
|
+
// Inside the lock, storage is the truth: another tab may have rotated while this one waited.
|
|
312
|
+
const stored = await this.readStored();
|
|
313
|
+
if (!stored) {
|
|
314
|
+
if (this.record)
|
|
315
|
+
await this.end("signed_out");
|
|
316
|
+
return null;
|
|
317
|
+
}
|
|
318
|
+
// Another tab already refreshed and told this one (BroadcastChannel) while it waited for the
|
|
319
|
+
// lock: use that, and spend nothing.
|
|
320
|
+
if (!options.force &&
|
|
321
|
+
!options.activeOrgUid &&
|
|
322
|
+
this.accessToken &&
|
|
323
|
+
this.accessToken !== startedWith &&
|
|
324
|
+
this.record?.refreshToken === stored.refreshToken &&
|
|
325
|
+
(this.accessExpiresAt == null || this.accessExpiresAt - this.now() > EXPIRY_SKEW_MS)) {
|
|
326
|
+
return this.snapshot();
|
|
327
|
+
}
|
|
328
|
+
this.record = stored;
|
|
329
|
+
let payload;
|
|
330
|
+
try {
|
|
331
|
+
payload = await this.exchange(stored.refreshToken, options.activeOrgUid);
|
|
332
|
+
}
|
|
333
|
+
catch (error) {
|
|
334
|
+
if (isTerminal(error)) {
|
|
335
|
+
const reason = asRecord(error.details)?.reason ?? "expired";
|
|
336
|
+
await this.end(reason);
|
|
337
|
+
return null;
|
|
338
|
+
}
|
|
339
|
+
throw error;
|
|
340
|
+
}
|
|
341
|
+
return this.adopt(payload, options.activeOrgUid ? "orgSwitched" : "tokenRefreshed");
|
|
342
|
+
}
|
|
343
|
+
// ── Ending ─────────────────────────────────────────────────────────────────────────────────────
|
|
344
|
+
/** Forget the session in this page and every other tab. Local only: `auth.signOut()` also tells the server. */
|
|
345
|
+
async end(reason = "signed_out", { forgetDevice = false } = {}) {
|
|
346
|
+
await this.load();
|
|
347
|
+
const hadSession = this.record !== null;
|
|
348
|
+
this.record = null;
|
|
349
|
+
this.accessToken = null;
|
|
350
|
+
this.accessExpiresAt = null;
|
|
351
|
+
await this.safeRemove(this.storageKey);
|
|
352
|
+
if (forgetDevice)
|
|
353
|
+
await this.safeRemove(this.deviceKey);
|
|
354
|
+
this.broadcast({ type: "signedOut", reason });
|
|
355
|
+
if (hadSession)
|
|
356
|
+
this.emit({ event: "signedOut", session: null, reason });
|
|
357
|
+
}
|
|
358
|
+
/** Keep the remembered account in step after the user changes it (a new name). */
|
|
359
|
+
async updateUser(fields) {
|
|
360
|
+
await this.load();
|
|
361
|
+
if (!this.record)
|
|
362
|
+
return;
|
|
363
|
+
this.record = { ...this.record, user: { ...this.record.user, ...fields } };
|
|
364
|
+
await this.persist();
|
|
365
|
+
this.broadcast({ type: "session", accessToken: this.accessToken, record: this.record });
|
|
366
|
+
}
|
|
367
|
+
/** The refresh token, for `auth.signOut()` to end the session on the server. Internal. */
|
|
368
|
+
async currentRefreshToken() {
|
|
369
|
+
await this.load();
|
|
370
|
+
return this.record?.refreshToken ?? null;
|
|
371
|
+
}
|
|
372
|
+
// ── Other tabs ─────────────────────────────────────────────────────────────────────────────────
|
|
373
|
+
broadcast(message) {
|
|
374
|
+
try {
|
|
375
|
+
this.channel?.postMessage(message);
|
|
376
|
+
}
|
|
377
|
+
catch {
|
|
378
|
+
// A closed channel: this tab is going away.
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
onBroadcast(data) {
|
|
382
|
+
const message = asRecord(data);
|
|
383
|
+
if (!message)
|
|
384
|
+
return;
|
|
385
|
+
if (message.type === "signedOut") {
|
|
386
|
+
const had = this.record !== null;
|
|
387
|
+
this.record = null;
|
|
388
|
+
this.accessToken = null;
|
|
389
|
+
this.accessExpiresAt = null;
|
|
390
|
+
if (had)
|
|
391
|
+
this.emit({ event: "signedOut", session: null, reason: String(message.reason ?? "signed_out") });
|
|
392
|
+
return;
|
|
393
|
+
}
|
|
394
|
+
if (message.type === "session") {
|
|
395
|
+
const record = asRecord(message.record);
|
|
396
|
+
if (!record ||
|
|
397
|
+
record.v !== RECORD_VERSION ||
|
|
398
|
+
typeof record.refreshToken !== "string" ||
|
|
399
|
+
typeof message.accessToken !== "string" ||
|
|
400
|
+
!toAccount(record.user)) {
|
|
401
|
+
return;
|
|
402
|
+
}
|
|
403
|
+
const wasSignedIn = this.record !== null;
|
|
404
|
+
this.setTokens({ ...record, user: toAccount(record.user) }, message.accessToken);
|
|
405
|
+
this.loaded = Promise.resolve();
|
|
406
|
+
this.emit({ event: wasSignedIn ? "tokenRefreshed" : "signedIn", session: this.snapshot() });
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
close() {
|
|
410
|
+
this.channel?.close();
|
|
411
|
+
this.listeners.clear();
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
const openChannel = (appUid) => {
|
|
415
|
+
const Ctor = globalThis.BroadcastChannel;
|
|
416
|
+
if (typeof Ctor !== "function" || typeof window === "undefined")
|
|
417
|
+
return null;
|
|
418
|
+
try {
|
|
419
|
+
return new Ctor(`authoric:${appUid}`);
|
|
420
|
+
}
|
|
421
|
+
catch {
|
|
422
|
+
return null;
|
|
423
|
+
}
|
|
424
|
+
};
|
|
425
|
+
//# sourceMappingURL=session.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.js","sourceRoot":"","sources":["../../src/session.ts"],"names":[],"mappings":"AAAA,yFAAyF;AACzF,EAAE;AACF,kDAAkD;AAClD,uGAAuG;AACvG,mFAAmF;AACnF,qGAAqG;AACrG,+FAA+F;AAC/F,sGAAsG;AACtG,uGAAuG;AACvG,wGAAwG;AACxG,yFAAyF;AACzF,gFAAgF;AAChF,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAIzD,MAAM,cAAc,GAAG,CAAC,CAAC;AACzB,wGAAwG;AACxG,MAAM,cAAc,GAAG,KAAM,CAAC;AA2B9B,MAAM,eAAe,GAAG,CAAC,KAAa,EAAiB,EAAE;IACxD,MAAM,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IACjC,IAAI,CAAC,IAAI;QAAE,OAAO,IAAI,CAAC;IACvB,IAAI,CAAC;QACJ,MAAM,IAAI,GAAG,OAAO,IAAI,KAAK,UAAU;YACtC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC;YAC9F,CAAC,CAAC,EAAE,CAAC;QACN,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,GAAG,CAAC;QAClC,OAAO,OAAO,GAAG,KAAK,QAAQ,CAAC,C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CAAC;IAC7E,IAAI,CAAC;QACJ,OAAO,IAAI,IAAI,CAAC,YAAY,MAAM,EAAE,CAAC,CAAC;IACvC,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,IAAI,CAAC;IACb,CAAC;AACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where the SDK keeps a signed-in session between page loads.
|
|
3
|
+
*
|
|
4
|
+
* Only the REFRESH token and the session's public facts (the account, its active org) are ever
|
|
5
|
+
* written here. The access token lives in memory and is re-minted from the refresh token after a
|
|
6
|
+
* reload (`session.ts`).
|
|
7
|
+
*
|
|
8
|
+
* Methods may return a value or a promise, so React Native's AsyncStorage or a secure store fits
|
|
9
|
+
* without a wrapper.
|
|
10
|
+
*/
|
|
11
|
+
export interface SessionStorageAdapter {
|
|
12
|
+
getItem(key: string): string | null | Promise<string | null>;
|
|
13
|
+
setItem(key: string, value: string): void | Promise<void>;
|
|
14
|
+
removeItem(key: string): void | Promise<void>;
|
|
15
|
+
}
|
|
16
|
+
/** Nothing persists: a reload signs the user out. The default outside a browser. */
|
|
17
|
+
export declare const memoryStorage: () => SessionStorageAdapter;
|
|
18
|
+
/**
|
|
19
|
+
* `window.localStorage`: the session survives reloads and is shared by the tabs of one origin. The
|
|
20
|
+
* default in a browser.
|
|
21
|
+
*
|
|
22
|
+
* The tradeoff, stated plainly: script running on the page (an XSS bug in the app) can read it. That
|
|
23
|
+
* is true of every single-page app that holds a bearer token. Refresh tokens are single-use, so when a
|
|
24
|
+
* stolen one and the real one are both used, the server ends the session for both.
|
|
25
|
+
*/
|
|
26
|
+
export declare const localStorageAdapter: () => SessionStorageAdapter;
|
|
27
|
+
/** `window.sessionStorage`: survives reloads of ONE tab, and is gone when the tab closes. */
|
|
28
|
+
export declare const sessionStorageAdapter: () => SessionStorageAdapter;
|
|
29
|
+
export type StorageOption = "local" | "session" | "memory" | SessionStorageAdapter;
|
|
30
|
+
export declare const resolveStorage: (option: StorageOption | undefined) => SessionStorageAdapter;
|
|
31
|
+
//# sourceMappingURL=storage-adapters.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage-adapters.d.ts","sourceRoot":"","sources":["../../src/storage-adapters.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,MAAM,WAAW,qBAAqB;IACrC,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IAC7D,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1D,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9C;AAED,oFAAoF;AACpF,eAAO,MAAM,aAAa,QAAO,qBAWhC,CAAC;AAqCF;;;;;;;GAOG;AACH,eAAO,MAAM,mBAAmB,QAAO,qBAC4C,CAAC;AAEpF,6FAA6F;AAC7F,eAAO,MAAM,qBAAqB,QAAO,qBAC8C,CAAC;AAExF,MAAM,MAAM,aAAa,GAAG,OAAO,GAAG,SAAS,GAAG,QAAQ,GAAG,qBAAqB,CAAC;AAEnF,eAAO,MAAM,cAAc,GAAI,QAAQ,aAAa,GAAG,SAAS,KAAG,qBAWlE,CAAC"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/** Nothing persists: a reload signs the user out. The default outside a browser. */
|
|
2
|
+
export const memoryStorage = () => {
|
|
3
|
+
const values = new Map();
|
|
4
|
+
return {
|
|
5
|
+
getItem: (key) => values.get(key) ?? null,
|
|
6
|
+
setItem: (key, value) => {
|
|
7
|
+
values.set(key, value);
|
|
8
|
+
},
|
|
9
|
+
removeItem: (key) => {
|
|
10
|
+
values.delete(key);
|
|
11
|
+
},
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
// A Web Storage object may exist and still throw on use (Safari private mode, storage disabled, a
|
|
15
|
+
// sandboxed iframe), so every call is guarded, and a failure degrades to "not persisted".
|
|
16
|
+
const webStorage = (pick) => {
|
|
17
|
+
const store = () => {
|
|
18
|
+
try {
|
|
19
|
+
return pick();
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
return {
|
|
26
|
+
getItem: (key) => {
|
|
27
|
+
try {
|
|
28
|
+
return store()?.getItem(key) ?? null;
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
setItem: (key, value) => {
|
|
35
|
+
try {
|
|
36
|
+
store()?.setItem(key, value);
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
// Not persisted; the session still works until the page closes.
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
removeItem: (key) => {
|
|
43
|
+
try {
|
|
44
|
+
store()?.removeItem(key);
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
// Nothing to remove.
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* `window.localStorage`: the session survives reloads and is shared by the tabs of one origin. The
|
|
54
|
+
* default in a browser.
|
|
55
|
+
*
|
|
56
|
+
* The tradeoff, stated plainly: script running on the page (an XSS bug in the app) can read it. That
|
|
57
|
+
* is true of every single-page app that holds a bearer token. Refresh tokens are single-use, so when a
|
|
58
|
+
* stolen one and the real one are both used, the server ends the session for both.
|
|
59
|
+
*/
|
|
60
|
+
export const localStorageAdapter = () => webStorage(() => (typeof localStorage === "undefined" ? undefined : localStorage));
|
|
61
|
+
/** `window.sessionStorage`: survives reloads of ONE tab, and is gone when the tab closes. */
|
|
62
|
+
export const sessionStorageAdapter = () => webStorage(() => (typeof sessionStorage === "undefined" ? undefined : sessionStorage));
|
|
63
|
+
export const resolveStorage = (option) => {
|
|
64
|
+
if (option && typeof option === "object")
|
|
65
|
+
return option;
|
|
66
|
+
const inBrowser = typeof window !== "undefined" && typeof document !== "undefined";
|
|
67
|
+
switch (option ?? (inBrowser ? "local" : "memory")) {
|
|
68
|
+
case "local":
|
|
69
|
+
return localStorageAdapter();
|
|
70
|
+
case "session":
|
|
71
|
+
return sessionStorageAdapter();
|
|
72
|
+
default:
|
|
73
|
+
return memoryStorage();
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
//# sourceMappingURL=storage-adapters.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage-adapters.js","sourceRoot":"","sources":["../../src/storage-adapters.ts"],"names":[],"mappings":"AAgBA,oFAAoF;AACpF,MAAM,CAAC,MAAM,aAAa,GAAG,GAA0B,EAAE;IACxD,MAAM,MAAM,GAAG,IAAI,GAAG,EAAkB,CAAC;IACzC,OAAO;QACN,OAAO,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,IAAI;QACzC,OAAO,EAAE,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE;YACvB,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QACxB,CAAC;QACD,UAAU,EAAE,CAAC,GAAG,EAAE,EAAE;YACnB,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACpB,CAAC;KACD,CAAC;AACH,CAAC,CAAC;AAEF,kGAAkG;AAClG,0FAA0F;AAC1F,MAAM,UAAU,GAAG,CAAC,IAA+B,EAAyB,EAAE;IAC7E,MAAM,KAAK,GAAG,GAAG,EAAE;QAClB,IAAI,CAAC;YACJ,OAAO,IAAI,EAAE,CAAC;QACf,CAAC;QAAC,MAAM,CAAC;YACR,OAAO,SAAS,CAAC;QAClB,CAAC;IACF,CAAC,CAAC;IACF,OAAO;QACN,OAAO,EAAE,CAAC,GAAG,EAAE,EAAE;YAChB,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