@finueva/auth 0.1.0 → 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/README.md +55 -5
- package/THIRD_PARTY_NOTICES.md +52 -0
- package/dist/device.d.ts +51 -0
- package/dist/device.js +936 -0
- package/dist/errors-Crd93Rah.d.ts +11 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.js +999 -46
- package/dist/server.d.ts +8 -2
- package/dist/server.js +139 -30
- package/dist/types-zEqO1_r2.d.ts +90 -0
- package/package.json +10 -2
- package/dist/errors-C-cHFWC7.d.ts +0 -55
package/README.md
CHANGED
|
@@ -16,15 +16,36 @@ const auth = createAuthClient({
|
|
|
16
16
|
appOrigin: window.location.origin,
|
|
17
17
|
});
|
|
18
18
|
|
|
19
|
+
const stop = auth.onAuthStateChange((state) => {
|
|
20
|
+
if (state.status === "cached") renderSessionHint(state.session);
|
|
21
|
+
if (state.status === "authenticated") renderVerifiedSession(state.session);
|
|
22
|
+
});
|
|
23
|
+
|
|
19
24
|
const session = await auth.getSession();
|
|
20
25
|
await auth.signIn({ email, password });
|
|
26
|
+
const organizations = await auth.listOrganizations();
|
|
27
|
+
const acceptance = await auth.acceptInvitation({ invitationId });
|
|
21
28
|
const credential = await auth.getDriveCredential({
|
|
22
29
|
workspace: { type: "personal" },
|
|
23
30
|
});
|
|
31
|
+
const organizationCredential = await auth.getDriveCredential({
|
|
32
|
+
workspace: { type: "organization", organizationId: organizations[0].id },
|
|
33
|
+
});
|
|
24
34
|
await auth.signOut();
|
|
35
|
+
stop();
|
|
25
36
|
```
|
|
26
37
|
|
|
27
|
-
The Auth session uses the Auth-owned HTTP-only cookie.
|
|
38
|
+
The Auth session uses the Auth-owned HTTP-only cookie. `getSession()` and `onSessionChange()` report Better Auth authority results only. `onAuthStateChange()` separately emits `loading`, non-authoritative `cached`, authoritative `authenticated`/`unauthenticated`, or non-authoritative `unavailable`; it verifies every cache hint immediately.
|
|
39
|
+
|
|
40
|
+
DOM browsers use local storage by default. Set `persistence` to `"session"`, `"memory"`, or a structural driver with `getItem`, `setItem`, and `removeItem`; Workers and Node default to memory. The one 16 KiB versioned snapshot contains only a normalized session and its Auth authority identity. It expires with the session and never contains cookies, passwords, Drive credentials, tokens, headers, workspace selection, Better Auth payloads, or errors. Persistence failure cannot change an Auth request result.
|
|
41
|
+
|
|
42
|
+
A workspace is either `{ type: "personal" }` or `{ type: "organization", organizationId }`; organization IDs must match `[A-Za-z0-9_-]{1,128}`. Workspace selections are strict and reject additional properties locally with `invalid_workspace_selection` before making a request.
|
|
43
|
+
|
|
44
|
+
`listOrganizations()` returns strict current `{ id, name, slug }` records from Better Auth authority. Results are not cached or persisted. Because the current upstream endpoint is unpaginated and silently capped at 100 records, the SDK fails closed rather than return an ambiguous list when that cap is reached.
|
|
45
|
+
|
|
46
|
+
`acceptInvitation({ invitationId })` performs one non-retried Better Auth acceptance and returns only `{ organizationId }`. Invitation details, recipient email, inviter identity, membership payloads, and raw authority errors are never exposed or persisted. Unknown, expired, canceled, accepted, and concurrently claimed invitations all report the same value-free `invitation_unavailable` conflict.
|
|
47
|
+
|
|
48
|
+
The browser retains at most one completed Drive credential in memory and renews it once it has two minutes remaining. Concurrent requests for the same workspace share one credential request. Selecting a different workspace never reuses the completed or in-flight credential for the previous workspace and replaces the retained credential. Passing `forceRefresh: true` requests a replacement after a Drive authentication failure; the SDK never replays a Drive request.
|
|
28
49
|
|
|
29
50
|
## Server
|
|
30
51
|
|
|
@@ -38,13 +59,42 @@ const auth = createServerAuth({
|
|
|
38
59
|
});
|
|
39
60
|
|
|
40
61
|
const session = await auth.getSession();
|
|
62
|
+
const organizations = await auth.listOrganizations();
|
|
63
|
+
const acceptance = await auth.acceptInvitation({ invitationId });
|
|
64
|
+
const credential = await auth.getDriveCredential({
|
|
65
|
+
workspace: { type: "organization", organizationId: organizations[0].id },
|
|
66
|
+
});
|
|
67
|
+
const signOut = await auth.signOut();
|
|
68
|
+
const responseHeaders = new Headers();
|
|
69
|
+
signOut.applyCookies(responseHeaders);
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
The server client is request-scoped and does not cache credentials. It forwards only reserved Better Auth cookies to Auth and never sends them to Drive. Apply cookies returned by server invitation acceptance or sign-out to the outgoing response with `acceptance.applyCookies(headers)` or `signOut.applyCookies(headers)`.
|
|
73
|
+
|
|
74
|
+
## Device
|
|
75
|
+
|
|
76
|
+
```ts
|
|
77
|
+
import { createDeviceAuth } from "@finueva/auth/device";
|
|
78
|
+
|
|
79
|
+
const auth = createDeviceAuth({
|
|
80
|
+
authOrigin: "https://auth.finueva.com",
|
|
81
|
+
clientId: "finueva-cli",
|
|
82
|
+
});
|
|
83
|
+
const authorization = await auth.requestAuthorization();
|
|
84
|
+
showCode(authorization.userCode, authorization.verificationUri);
|
|
85
|
+
const token = await auth.pollForToken(authorization, { signal });
|
|
86
|
+
const session = await auth.getSession();
|
|
87
|
+
await auth.revokeCurrentDevice(); // or revokeAllSessions()
|
|
41
88
|
```
|
|
42
89
|
|
|
43
|
-
|
|
90
|
+
Polling starts at the server-provided interval, adds five seconds after each RFC 8628 `slow_down`, has no transport retry, and stops on denial, expiry, cancellation, the configured `maxPollingMs`, malformed/bounded responses, or transport timeout. The only requested scope is `openid`.
|
|
91
|
+
|
|
92
|
+
The token is memory-only by default. Secure persistence is opt-in through a structural adapter implementing `read`, atomic `replace`, and `delete`; every operation receives an `AbortSignal` and must stop without committing when aborted. The caller owns encryption and platform credential storage. Adapter and authority failures are value-free and never include device codes or tokens. This export uses standard expiring/revocable Better Auth sessions and does not implement refresh tokens.
|
|
44
93
|
|
|
45
94
|
## Current Limits
|
|
46
95
|
|
|
47
|
-
-
|
|
48
|
-
- Cross-root SSO
|
|
49
|
-
- The package does not persist Drive credentials or expose Better Auth internals.
|
|
96
|
+
- Organization mutation and active-organization state are not exposed; callers select an organization returned by `listOrganizations()` explicitly.
|
|
97
|
+
- Cross-root SSO is not implemented.
|
|
98
|
+
- The package does not persist Drive credentials or expose Better Auth or Unstorage internals.
|
|
50
99
|
- Public errors are `AuthError` instances with stable, value-free codes.
|
|
100
|
+
- Organization contexts with more than 50 current teams fail with `organization_context_too_large` and status `422`.
|
package/THIRD_PARTY_NOTICES.md
CHANGED
|
@@ -98,3 +98,55 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
98
98
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
99
99
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
100
100
|
SOFTWARE.
|
|
101
|
+
|
|
102
|
+
## unstorage 1.17.5
|
|
103
|
+
|
|
104
|
+
Source: https://github.com/unjs/unstorage
|
|
105
|
+
|
|
106
|
+
MIT License
|
|
107
|
+
|
|
108
|
+
Copyright (c) Pooya Parsa <pooya@pi0.io>
|
|
109
|
+
|
|
110
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
111
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
112
|
+
in the Software without restriction, including without limitation the rights
|
|
113
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
114
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
115
|
+
furnished to do so, subject to the following conditions:
|
|
116
|
+
|
|
117
|
+
The above copyright notice and this permission notice shall be included in all
|
|
118
|
+
copies or substantial portions of the Software.
|
|
119
|
+
|
|
120
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
121
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
122
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
123
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
124
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
125
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
126
|
+
SOFTWARE.
|
|
127
|
+
|
|
128
|
+
## destr 2.0.5
|
|
129
|
+
|
|
130
|
+
Source: https://github.com/unjs/destr
|
|
131
|
+
|
|
132
|
+
MIT License
|
|
133
|
+
|
|
134
|
+
Copyright (c) Pooya Parsa <pooya@pi0.io>
|
|
135
|
+
|
|
136
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
137
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
138
|
+
in the Software without restriction, including without limitation the rights
|
|
139
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
140
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
141
|
+
furnished to do so, subject to the following conditions:
|
|
142
|
+
|
|
143
|
+
The above copyright notice and this permission notice shall be included in all
|
|
144
|
+
copies or substantial portions of the Software.
|
|
145
|
+
|
|
146
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
147
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
148
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
149
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
150
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
151
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
152
|
+
SOFTWARE.
|
package/dist/device.d.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { o as AuthSession } from "./types-zEqO1_r2.js";
|
|
2
|
+
//#region src/device.d.ts
|
|
3
|
+
type DeviceAuthorizationErrorCode = "device_access_denied" | "device_authorization_cancelled" | "device_code_expired" | "invalid_device_authorization" | "identity_authority_unavailable";
|
|
4
|
+
declare class DeviceAuthorizationError extends Error {
|
|
5
|
+
readonly code: DeviceAuthorizationErrorCode;
|
|
6
|
+
constructor(code: DeviceAuthorizationErrorCode);
|
|
7
|
+
}
|
|
8
|
+
interface DeviceToken {
|
|
9
|
+
accessToken: string;
|
|
10
|
+
tokenType: "Bearer";
|
|
11
|
+
expiresAt: Date;
|
|
12
|
+
scope: "openid";
|
|
13
|
+
}
|
|
14
|
+
interface DeviceTokenPersistence {
|
|
15
|
+
read(signal: AbortSignal): DeviceToken | null | Promise<DeviceToken | null>;
|
|
16
|
+
replace(token: DeviceToken, signal: AbortSignal): void | Promise<void>;
|
|
17
|
+
delete(signal: AbortSignal): void | Promise<void>;
|
|
18
|
+
}
|
|
19
|
+
interface DeviceAuthorization {
|
|
20
|
+
deviceCode: string;
|
|
21
|
+
userCode: string;
|
|
22
|
+
verificationUri: string;
|
|
23
|
+
verificationUriComplete: string;
|
|
24
|
+
expiresAt: Date;
|
|
25
|
+
intervalSeconds: number;
|
|
26
|
+
}
|
|
27
|
+
interface DeviceAuthOptions {
|
|
28
|
+
authOrigin: string;
|
|
29
|
+
clientId: string;
|
|
30
|
+
fetch?: typeof globalThis.fetch;
|
|
31
|
+
now?: () => number;
|
|
32
|
+
persistence?: DeviceTokenPersistence;
|
|
33
|
+
timeoutMs?: number;
|
|
34
|
+
maxPollingMs?: number;
|
|
35
|
+
}
|
|
36
|
+
interface PollDeviceOptions {
|
|
37
|
+
signal?: AbortSignal;
|
|
38
|
+
}
|
|
39
|
+
interface DeviceAuthClient {
|
|
40
|
+
requestAuthorization(options?: {
|
|
41
|
+
signal?: AbortSignal;
|
|
42
|
+
}): Promise<DeviceAuthorization>;
|
|
43
|
+
pollForToken(authorization: DeviceAuthorization, options?: PollDeviceOptions): Promise<DeviceToken>;
|
|
44
|
+
getSession(): Promise<AuthSession | null>;
|
|
45
|
+
getToken(): Promise<DeviceToken | null>;
|
|
46
|
+
revokeCurrentDevice(): Promise<void>;
|
|
47
|
+
revokeAllSessions(): Promise<void>;
|
|
48
|
+
}
|
|
49
|
+
declare function createDeviceAuth(options: DeviceAuthOptions): DeviceAuthClient;
|
|
50
|
+
//#endregion
|
|
51
|
+
export { DeviceAuthClient, DeviceAuthOptions, DeviceAuthorization, DeviceAuthorizationError, DeviceAuthorizationErrorCode, DeviceToken, DeviceTokenPersistence, PollDeviceOptions, createDeviceAuth };
|