eocene-auth-sdk 0.2.2 → 0.4.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 +43 -0
- package/README.md +51 -10
- package/dist/index.d.ts +50 -14
- package/dist/index.js +346 -43
- package/dist/index.js.map +1 -1
- package/dist/styles.css +20 -23
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,48 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.4.0
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- **Persistent session recovery.** `AuthClient.restoreSession()` and the matching
|
|
8
|
+
`useAuth()` method restore a usable local access token or use the project-managed
|
|
9
|
+
refresh cookie. Concurrent calls share one refresh flow. `<AuthProvider>` now
|
|
10
|
+
finishes startup recovery before setting `ready` to `true`.
|
|
11
|
+
- **Refresh-cookie logout.** `logout()` starts a credentialed request to revoke the
|
|
12
|
+
server-side refresh session before synchronously clearing local access state.
|
|
13
|
+
|
|
14
|
+
### Changed
|
|
15
|
+
|
|
16
|
+
- Local tokens that are expired, malformed, missing `exp`, or within one minute of
|
|
17
|
+
expiry are refreshed rather than treated as a successful local restore.
|
|
18
|
+
- Session lifetime and refresh policy come from the server-side project
|
|
19
|
+
`sessionPolicy`; refresh and logout requests include cookies and `projectId`.
|
|
20
|
+
|
|
21
|
+
## 0.3.0
|
|
22
|
+
|
|
23
|
+
### Added
|
|
24
|
+
|
|
25
|
+
- **Telegram login.** `AuthSocialMethod` gains `'telegram'`:
|
|
26
|
+
- Web: `login('telegram')` runs the standard OAuth redirect (control-plane
|
|
27
|
+
speaks Telegram OIDC; requires `TELEGRAM_CLIENT_ID/SECRET` on eocene-worker).
|
|
28
|
+
- Mini App: `loginTelegramMiniApp()` (also on `useAuth()`) exchanges the
|
|
29
|
+
bot-signed `window.Telegram.WebApp.initData` for a session — no redirect.
|
|
30
|
+
`login('telegram')` automatically takes this path inside the Telegram
|
|
31
|
+
webview.
|
|
32
|
+
- New exports `isTelegramMiniApp()` / `getTelegramInitData()` for hosts that
|
|
33
|
+
want to auto-login on entry.
|
|
34
|
+
- New label `loginTelegram` (default `'Telegram'`).
|
|
35
|
+
- Older control-planes simply never advertise `providers.telegram`, so the
|
|
36
|
+
button stays hidden — no version coupling.
|
|
37
|
+
|
|
38
|
+
### Changed
|
|
39
|
+
|
|
40
|
+
- Auth UI palette aligned to the Eocene mark (`#3B82D6` / `#1D3E90` / `#85CEEA`); navy-tinted surfaces, cyan glows.
|
|
41
|
+
- Auth UI lockup now reads **EOCENE Research** (stacked wordmark) instead of the old mixed-case "Eocene" wordmark.
|
|
42
|
+
- Login panel asks for confirmation before redirecting to Google / GitHub / X / Apple.
|
|
43
|
+
- `authConfigFromViteEnv` reads `VITE_EOCENE_*` (stock Vite).
|
|
44
|
+
- Dev mock identities use `{provider}@eocene.local`.
|
|
45
|
+
|
|
3
46
|
## 0.2.2
|
|
4
47
|
|
|
5
48
|
### Fixed
|
package/README.md
CHANGED
|
@@ -24,11 +24,28 @@ Environment variables (Vite):
|
|
|
24
24
|
|
|
25
25
|
| Key | Description |
|
|
26
26
|
|---|---|
|
|
27
|
-
| `
|
|
28
|
-
| `
|
|
29
|
-
| `
|
|
30
|
-
| `
|
|
31
|
-
| `
|
|
27
|
+
| `VITE_EOCENE_PROJECT_ID` | Public project id (required for end-user OAuth) |
|
|
28
|
+
| `VITE_EOCENE_CONTROL_URL` | Optional. Default `https://api.eocene.io` |
|
|
29
|
+
| `VITE_EOCENE_OAUTH_RETURN_TO` | Optional. Default `{origin}/login/eocene-callback` |
|
|
30
|
+
| `VITE_EOCENE_CHAIN_ID` | Optional. Default `1` |
|
|
31
|
+
| `VITE_EOCENE_OAUTH_FALLBACK_DEV` | Optional. Local mock `{provider}@eocene.local` when IdP is off |
|
|
32
|
+
|
|
33
|
+
Unprefixed `EOCENE_*` still works if you set Vite `envPrefix` to include `EOCENE_`.
|
|
34
|
+
|
|
35
|
+
The built-in `AuthLoginPanel` confirms before redirecting to the IdP.
|
|
36
|
+
|
|
37
|
+
**Telegram** (`'telegram'` method, control-plane must have `TELEGRAM_CLIENT_ID/SECRET` + `TELEGRAM_BOT_TOKEN`):
|
|
38
|
+
web login uses the same OAuth redirect as the other providers; inside a
|
|
39
|
+
Telegram Mini App the signed `initData` is exchanged directly — call
|
|
40
|
+
`loginTelegramMiniApp()` from `useAuth()` (or just `login('telegram')`, which
|
|
41
|
+
detects the webview), and use `isTelegramMiniApp()` to auto-login on entry:
|
|
42
|
+
|
|
43
|
+
```tsx
|
|
44
|
+
const { loginTelegramMiniApp } = useAuth()
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
if (isTelegramMiniApp()) void loginTelegramMiniApp()
|
|
47
|
+
}, [])
|
|
48
|
+
```
|
|
32
49
|
|
|
33
50
|
Production control default: `https://api.eocene.io`
|
|
34
51
|
|
|
@@ -51,17 +68,41 @@ read -rs NPM_TOKEN && export NPM_TOKEN && npm run publish:token
|
|
|
51
68
|
The token is only exported to the npm subprocess; the temp `.npmrc` references
|
|
52
69
|
`${NPM_TOKEN}`, never the literal value.
|
|
53
70
|
|
|
54
|
-
###
|
|
71
|
+
### Persistent sessions and startup recovery
|
|
72
|
+
|
|
73
|
+
`AuthProvider` automatically restores the session on startup and sets `ready` to
|
|
74
|
+
`true` only after that attempt finishes. A local token with an address is used
|
|
75
|
+
when it is valid for more than one minute; otherwise the SDK calls
|
|
76
|
+
`POST {controlBaseUrl}/auth/session/refresh` with `credentials: 'include'` and the
|
|
77
|
+
configured `projectId`. A missing or rejected refresh cookie leaves the app signed
|
|
78
|
+
out without triggering a redirect. `restoreSession(): Promise<boolean>` is also
|
|
79
|
+
available from `useAuth()` for an explicit retry; concurrent calls share one flow.
|
|
80
|
+
|
|
81
|
+
```tsx
|
|
82
|
+
const { ready, authenticated, restoreSession } = useAuth()
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Access tokens remain in `sessionStorage`. Refresh cookies are managed by Eocene
|
|
86
|
+
per project, and access/refresh lifetime and rotation are controlled by the
|
|
87
|
+
server-side project `sessionPolicy`, not by SDK configuration. The refresh and
|
|
88
|
+
logout endpoints require credentialed CORS: allow the exact application origin and
|
|
89
|
+
`Access-Control-Allow-Credentials` (a wildcard origin is insufficient). Cross-site
|
|
90
|
+
cookies also require browser-compatible `Secure` / `SameSite=None` settings and may
|
|
91
|
+
be blocked by third-party-cookie policy; a same-site proxy avoids that restriction.
|
|
92
|
+
|
|
93
|
+
### Session expiry and logout
|
|
55
94
|
|
|
56
|
-
|
|
57
|
-
|
|
95
|
+
A 401 from an access-token request clears local access state and flips
|
|
96
|
+
`authenticated` to `false`, but does not revoke the refresh cookie. Route the user
|
|
97
|
+
back to login when appropriate:
|
|
58
98
|
|
|
59
99
|
```tsx
|
|
60
100
|
<AuthProvider config={config} onSessionExpired={() => nav('/login')}>
|
|
61
101
|
```
|
|
62
102
|
|
|
63
|
-
|
|
64
|
-
|
|
103
|
+
`logout()` remains synchronous for local state. It starts the credentialed remote
|
|
104
|
+
revocation request first, then clears the access token and wallet state; the remote
|
|
105
|
+
request is best-effort and failures are not surfaced to the synchronous caller.
|
|
65
106
|
|
|
66
107
|
### Multi-chain
|
|
67
108
|
|
package/dist/index.d.ts
CHANGED
|
@@ -50,9 +50,10 @@ type WaasSignApprovalResult = boolean | {
|
|
|
50
50
|
type WaasClientOptions = {
|
|
51
51
|
controlBaseUrl: string;
|
|
52
52
|
/**
|
|
53
|
-
* Called when the control-plane rejects the session (401).
|
|
54
|
-
*
|
|
55
|
-
*
|
|
53
|
+
* Called when the control-plane rejects the session (401). Access tokens
|
|
54
|
+
* default to one hour. POST /auth/session/refresh can rotate the project
|
|
55
|
+
* refresh cookie or slide a still-valid Bearer token; an expired Bearer
|
|
56
|
+
* token cannot be refreshed.
|
|
56
57
|
*/
|
|
57
58
|
onSessionExpired?: () => void;
|
|
58
59
|
};
|
|
@@ -188,9 +189,14 @@ type AuthSdkLabels = {
|
|
|
188
189
|
loginTwitter: string;
|
|
189
190
|
loginGithub: string;
|
|
190
191
|
loginApple: string;
|
|
192
|
+
loginTelegram: string;
|
|
191
193
|
loginConnecting: string;
|
|
192
194
|
loginError: string;
|
|
193
195
|
loginNoMethods: string;
|
|
196
|
+
loginConfirmTitle: string;
|
|
197
|
+
loginConfirmBody: string;
|
|
198
|
+
loginConfirmContinue: string;
|
|
199
|
+
loginConfirmCancel: string;
|
|
194
200
|
oauthWorking: string;
|
|
195
201
|
oauthFailed: string;
|
|
196
202
|
oauthBack: string;
|
|
@@ -254,14 +260,14 @@ type AuthSdkComponents = {
|
|
|
254
260
|
LoginPanel?: ComponentType<LoginPanelProps>;
|
|
255
261
|
};
|
|
256
262
|
|
|
257
|
-
type AuthSocialMethod = 'google' | 'twitter' | 'github' | 'apple';
|
|
263
|
+
type AuthSocialMethod = 'google' | 'twitter' | 'github' | 'apple' | 'telegram';
|
|
258
264
|
type AuthSdkConfig = {
|
|
259
265
|
controlBaseUrl: string;
|
|
260
266
|
/** Full URL control-plane redirects to after OAuth (host route). */
|
|
261
267
|
oauthReturnTo: string;
|
|
262
268
|
/**
|
|
263
269
|
* When IdP credentials are missing on control-plane, allow `loginDev`
|
|
264
|
-
* mock `{provider}@
|
|
270
|
+
* mock `{provider}@eocene.local`. Default false.
|
|
265
271
|
*/
|
|
266
272
|
allowDevLoginFallback?: boolean;
|
|
267
273
|
/** Scope end-user OAuth / wallets to this project. */
|
|
@@ -303,8 +309,8 @@ type AuthClientOptions = {
|
|
|
303
309
|
config: AuthSdkConfig;
|
|
304
310
|
requestApproval?: (req: WaasSignApprovalRequest) => Promise<WaasSignApprovalResult>;
|
|
305
311
|
/**
|
|
306
|
-
* Called when the control-plane rejects the session (401).
|
|
307
|
-
*
|
|
312
|
+
* Called when the control-plane rejects the session (401). Access-token TTL is
|
|
313
|
+
* project-configurable; hosts may restore through the persistent refresh cookie.
|
|
308
314
|
*/
|
|
309
315
|
onSessionExpired?: () => void;
|
|
310
316
|
/** Initial EVM chain for the EIP-1193 provider. Default 1 (Ethereum). */
|
|
@@ -318,6 +324,7 @@ declare class AuthClient {
|
|
|
318
324
|
private provider;
|
|
319
325
|
private chainId;
|
|
320
326
|
private active;
|
|
327
|
+
private restorePromise;
|
|
321
328
|
private requestApproval?;
|
|
322
329
|
private onSessionExpired?;
|
|
323
330
|
constructor(options: AuthClientOptions);
|
|
@@ -340,15 +347,42 @@ declare class AuthClient {
|
|
|
340
347
|
*/
|
|
341
348
|
listAvailableMethods(): Promise<AuthSocialMethod[]>;
|
|
342
349
|
login(method: AuthSocialMethod): Promise<AuthLoginResult>;
|
|
350
|
+
/**
|
|
351
|
+
* Silent login for apps running inside the Telegram webview: no redirect,
|
|
352
|
+
* no popup — the bot-signed `initData` is exchanged directly for a session.
|
|
353
|
+
* `initData` defaults to `window.Telegram.WebApp.initData`; pass it
|
|
354
|
+
* explicitly only in tests.
|
|
355
|
+
*/
|
|
356
|
+
loginTelegramMiniApp(initData?: string): Promise<AuthLoginResult>;
|
|
343
357
|
completeOAuthFromHash(hashOrSearch: string): Promise<AuthLoginResult>;
|
|
344
358
|
takeOAuthReturnPath(): string | null;
|
|
345
359
|
markActive(on: boolean): void;
|
|
360
|
+
private restoreLocalSession;
|
|
361
|
+
private localSessionNeedsRefresh;
|
|
346
362
|
restoreIfNeeded(): boolean;
|
|
363
|
+
restoreSession(): Promise<boolean>;
|
|
364
|
+
private performRestoreSession;
|
|
347
365
|
logout(): void;
|
|
348
366
|
setPassword(password: string, currentPassword?: string): Promise<void>;
|
|
349
367
|
clearPassword(password: string): Promise<void>;
|
|
350
368
|
}
|
|
351
369
|
|
|
370
|
+
/**
|
|
371
|
+
* Telegram Mini App detection.
|
|
372
|
+
*
|
|
373
|
+
* Inside the Telegram webview `window.Telegram.WebApp` is injected by
|
|
374
|
+
* telegram-web-app.js and `initData` carries the bot-signed login payload.
|
|
375
|
+
* Only the raw string is ever read here — the parsed `initDataUnsafe` object
|
|
376
|
+
* is not trustworthy and never leaves the client.
|
|
377
|
+
*/
|
|
378
|
+
/**
|
|
379
|
+
* True when running inside Telegram with a signed login payload available.
|
|
380
|
+
* Hosts use this to switch the login screen to the silent Mini App path.
|
|
381
|
+
*/
|
|
382
|
+
declare function isTelegramMiniApp(): boolean;
|
|
383
|
+
/** The raw signed initData string, or null outside Telegram. */
|
|
384
|
+
declare function getTelegramInitData(): string | null;
|
|
385
|
+
|
|
352
386
|
/** Thin wrapper — prefer AuthClient.getProvider(); exported for advanced hosts. */
|
|
353
387
|
declare function createAuthEip1193Provider(client: WaasClient, requestApproval?: (req: WaasSignApprovalRequest) => Promise<WaasSignApprovalResult>): WaasEip1193Provider;
|
|
354
388
|
|
|
@@ -363,9 +397,12 @@ type AuthContextValue = {
|
|
|
363
397
|
login: (args: {
|
|
364
398
|
method: AuthSocialMethod;
|
|
365
399
|
}) => Promise<AuthLoginResult>;
|
|
400
|
+
/** Silent Telegram Mini App login (inside the Telegram webview only). */
|
|
401
|
+
loginTelegramMiniApp: () => Promise<AuthLoginResult>;
|
|
366
402
|
logout: () => void;
|
|
367
403
|
markActive: (on: boolean) => void;
|
|
368
404
|
restoreIfNeeded: () => boolean;
|
|
405
|
+
restoreSession: () => Promise<boolean>;
|
|
369
406
|
completeOAuthFromHash: (hashOrSearch: string) => Promise<AuthLoginResult>;
|
|
370
407
|
takeOAuthReturnPath: () => string | null;
|
|
371
408
|
getProvider: () => WaasEip1193Provider;
|
|
@@ -385,9 +422,9 @@ type AuthProviderProps = {
|
|
|
385
422
|
components?: AuthSdkComponents;
|
|
386
423
|
onRequestSignApproval?: (req: WaasSignApprovalRequest) => Promise<WaasSignApprovalResult>;
|
|
387
424
|
/**
|
|
388
|
-
* Called when the session
|
|
389
|
-
*
|
|
390
|
-
*
|
|
425
|
+
* Called when the session is rejected (401). The provider has already cleared
|
|
426
|
+
* local access state. Hosts may restore through the persistent refresh cookie;
|
|
427
|
+
* only a failed restore requires the user to connect the signer again.
|
|
391
428
|
*/
|
|
392
429
|
onSessionExpired?: () => void;
|
|
393
430
|
children: ReactNode;
|
|
@@ -413,7 +450,7 @@ type AuthOAuthCallbackProps = {
|
|
|
413
450
|
*/
|
|
414
451
|
declare function AuthOAuthCallback({ hashOrSearch, onWalletReady, children, onBackHref, }: AuthOAuthCallbackProps): react.JSX.Element;
|
|
415
452
|
|
|
416
|
-
/** Build AuthSdkConfig from Vite `
|
|
453
|
+
/** Build AuthSdkConfig from Vite `VITE_EOCENE_*` (and unprefixed / legacy WAAS aliases). */
|
|
417
454
|
declare function authConfigFromViteEnv(env?: object): AuthSdkConfig;
|
|
418
455
|
|
|
419
456
|
declare function SignConfirmModal({ open, request, labels, password, busy, error, locked, onPasswordChange, onApprove, onReject, onOpenSetPassword, }: SignApprovalProps): react.JSX.Element | null;
|
|
@@ -421,8 +458,7 @@ declare function SignConfirmModal({ open, request, labels, password, busy, error
|
|
|
421
458
|
declare function SetPasswordModal({ open, passwordEnabled, labels, busy, error, onSubmitSet, onSubmitClear, onClose, }: PasswordSettingsProps): react.JSX.Element | null;
|
|
422
459
|
|
|
423
460
|
/**
|
|
424
|
-
*
|
|
425
|
-
* brand refresh. Inline for npm consumers (no asset fetch); transparent
|
|
461
|
+
* EOCENE Research mark and lockup. Inline SVG (no asset fetch); transparent
|
|
426
462
|
* background so it sits on either theme.
|
|
427
463
|
*/
|
|
428
464
|
declare function EoceneMark({ size, title, ...props }: SVGProps<SVGSVGElement> & {
|
|
@@ -434,4 +470,4 @@ declare function EoceneWordmark({ className, markSize, }: {
|
|
|
434
470
|
markSize?: number;
|
|
435
471
|
}): react.JSX.Element;
|
|
436
472
|
|
|
437
|
-
export { AuthClient, type AuthConnectorShim, type AuthContextValue, AuthLoginPanel, type AuthLoginResult, AuthOAuthCallback, type AuthOAuthCallbackProps, AuthProvider, type AuthProviderProps, type AuthSdkComponents, type AuthSdkConfig, type AuthSdkLabels, type AuthSocialMethod, type AuthUser, DEFAULT_CONTROL_BASE_URL, DEFAULT_LABELS, DEFAULT_OAUTH_PENDING_KEY, DEFAULT_STORAGE_KEY, EoceneMark, EoceneWordmark, type LoginPanelProps, type PasswordSettingsProps, SetPasswordModal, type SignApprovalProps, SignConfirmModal, type WaasEip1193Provider, WaasHttpError, type WaasSignApprovalRequest, type WaasSignApprovalResult, type WaasSignAuthError, authConfigFromViteEnv, createAuthEip1193Provider, isWaasHttpError, resolveControlAbsoluteUrl, useAuthContext as useAuth };
|
|
473
|
+
export { AuthClient, type AuthConnectorShim, type AuthContextValue, AuthLoginPanel, type AuthLoginResult, AuthOAuthCallback, type AuthOAuthCallbackProps, AuthProvider, type AuthProviderProps, type AuthSdkComponents, type AuthSdkConfig, type AuthSdkLabels, type AuthSocialMethod, type AuthUser, DEFAULT_CONTROL_BASE_URL, DEFAULT_LABELS, DEFAULT_OAUTH_PENDING_KEY, DEFAULT_STORAGE_KEY, EoceneMark, EoceneWordmark, type LoginPanelProps, type PasswordSettingsProps, SetPasswordModal, type SignApprovalProps, SignConfirmModal, type WaasEip1193Provider, WaasHttpError, type WaasSignApprovalRequest, type WaasSignApprovalResult, type WaasSignAuthError, authConfigFromViteEnv, createAuthEip1193Provider, getTelegramInitData, isTelegramMiniApp, isWaasHttpError, resolveControlAbsoluteUrl, useAuthContext as useAuth };
|