cauthy-auth 0.2.0 → 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/README.md +12 -1
- package/dist/{cauthy-BrIMaoj1.d.mts → cauthy-C5_lopMQ.d.ts} +7 -1
- package/dist/{cauthy-CCZc9w8r.d.ts → cauthy-mNADGlNl.d.mts} +7 -1
- package/dist/cli.js +123 -2
- package/dist/fastify.d.mts +2 -2
- package/dist/fastify.d.ts +2 -2
- package/dist/index.d.mts +46 -2
- package/dist/index.d.ts +46 -2
- package/dist/index.js +243 -29
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +237 -26
- package/dist/index.mjs.map +1 -1
- package/dist/react.d.mts +3 -2
- package/dist/react.d.ts +3 -2
- package/dist/system-BWLddIt2.d.mts +233 -0
- package/dist/system-BWLddIt2.d.ts +233 -0
- package/package.json +1 -1
- package/dist/types-CYmUVWzY.d.mts +0 -106
- package/dist/types-CYmUVWzY.d.ts +0 -106
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import { JWK } from 'jose';
|
|
2
|
+
|
|
3
|
+
/** How an application is set up to sign its people in with Cauthy. */
|
|
4
|
+
interface CauthyOptions {
|
|
5
|
+
/** Cauthy's public address, e.g. `https://id.example.com`. Default: `CAUTHY_ISSUER`. */
|
|
6
|
+
issuer?: string;
|
|
7
|
+
/** The application's OAuth client id. Default: `CAUTHY_CLIENT_ID`. */
|
|
8
|
+
clientId?: string;
|
|
9
|
+
/** Its secret, when the client is confidential. Default: `CAUTHY_CLIENT_SECRET`. */
|
|
10
|
+
clientSecret?: string;
|
|
11
|
+
/**
|
|
12
|
+
* The key the session cookie is encrypted with: any string of 32 characters
|
|
13
|
+
* or more, kept on the server. Default: `CAUTHY_SECRET`.
|
|
14
|
+
*/
|
|
15
|
+
secret?: string;
|
|
16
|
+
/**
|
|
17
|
+
* The system this application is, as its organizations are filed under in
|
|
18
|
+
* Cauthy (`"pondari"`). When set, a session's organizations are that
|
|
19
|
+
* system's. Default: `CAUTHY_SYSTEM`.
|
|
20
|
+
*/
|
|
21
|
+
system?: string;
|
|
22
|
+
/** Where the routes are mounted. Default: `/api/auth`. */
|
|
23
|
+
basePath?: string;
|
|
24
|
+
/**
|
|
25
|
+
* The application's own public origin (`https://app.example.com`), for the
|
|
26
|
+
* redirect URI. Default: the origin of each request, which is right unless
|
|
27
|
+
* a proxy hides it.
|
|
28
|
+
*/
|
|
29
|
+
baseURL?: string;
|
|
30
|
+
/** Where a person lands after signing in, when no `return_to` was asked. Default: `/`. */
|
|
31
|
+
afterSignIn?: string;
|
|
32
|
+
/** Where a person lands after signing out. Default: `/`. */
|
|
33
|
+
afterSignOut?: string;
|
|
34
|
+
/** Name of the session cookie. Default: `cauthy_session`. */
|
|
35
|
+
cookieName?: string;
|
|
36
|
+
/**
|
|
37
|
+
* A key the application proves who it is with when it acts on its own
|
|
38
|
+
* (`auth.system`), instead of its secret. Default: `CAUTHY_SYSTEM_KEY` and
|
|
39
|
+
* `CAUTHY_SYSTEM_KEY_ID`.
|
|
40
|
+
*/
|
|
41
|
+
systemKey?: SystemKey;
|
|
42
|
+
/** `fetch` to reach Cauthy with. Default: the global one. */
|
|
43
|
+
fetch?: typeof fetch;
|
|
44
|
+
}
|
|
45
|
+
/** The person signed in. Every moment is UTC. */
|
|
46
|
+
interface SessionUser {
|
|
47
|
+
id: string;
|
|
48
|
+
email: string;
|
|
49
|
+
name: string;
|
|
50
|
+
emailVerified: boolean;
|
|
51
|
+
/**
|
|
52
|
+
* True when the account ran out of time to confirm its address: let it read
|
|
53
|
+
* and refuse its writes.
|
|
54
|
+
*/
|
|
55
|
+
restricted: boolean;
|
|
56
|
+
/** When an unconfirmed address stops being enough (ISO 8601, UTC), if there is a deadline. */
|
|
57
|
+
emailVerifyBy?: string;
|
|
58
|
+
/** The language the person reads in ("es", "en-US"), when Cauthy knows it. */
|
|
59
|
+
locale?: string;
|
|
60
|
+
}
|
|
61
|
+
/** A value JSON can carry. What crosses from server to browser is typed as this, never `unknown`. */
|
|
62
|
+
type JsonValue = string | number | boolean | null | JsonValue[] | {
|
|
63
|
+
[key: string]: JsonValue;
|
|
64
|
+
};
|
|
65
|
+
/** An organization the person belongs to, with their role in it. */
|
|
66
|
+
interface SessionOrganization {
|
|
67
|
+
id: string;
|
|
68
|
+
system: string;
|
|
69
|
+
name: string;
|
|
70
|
+
kind: string;
|
|
71
|
+
externalId?: string;
|
|
72
|
+
role: string;
|
|
73
|
+
/** What the system keeps about the organization, as it filed it in Cauthy. */
|
|
74
|
+
metadata: Record<string, JsonValue>;
|
|
75
|
+
/**
|
|
76
|
+
* What the person may do here, as "resource:action" entries ("*" is any):
|
|
77
|
+
* their role's permissions, what it inherits, and anything given to them
|
|
78
|
+
* apart from it. Absent when the system keeps no catalog of roles in Cauthy.
|
|
79
|
+
* Check with `can(organization, resource, action)`.
|
|
80
|
+
*/
|
|
81
|
+
permissions?: string[];
|
|
82
|
+
/** What the person is denied here, whatever else allows it. */
|
|
83
|
+
denied?: string[];
|
|
84
|
+
}
|
|
85
|
+
/** A signed-in person, as the server sees them. */
|
|
86
|
+
interface Session {
|
|
87
|
+
user: SessionUser;
|
|
88
|
+
/** The Cauthy tenant the account is of. */
|
|
89
|
+
tenantId: string;
|
|
90
|
+
/** The roles the account holds in that tenant. */
|
|
91
|
+
roles: string[];
|
|
92
|
+
/**
|
|
93
|
+
* Cauthy's access token for this person: send it as `Authorization: Bearer`
|
|
94
|
+
* to another service that verifies Cauthy's tokens. Never give it to the browser.
|
|
95
|
+
*/
|
|
96
|
+
accessToken: string;
|
|
97
|
+
/** When the access token expires and the session is checked with Cauthy again (ISO 8601, UTC). */
|
|
98
|
+
expiresAt: string;
|
|
99
|
+
}
|
|
100
|
+
/** What the browser is told of a session: who, and their organizations — never a token. */
|
|
101
|
+
interface PublicSession {
|
|
102
|
+
user: SessionUser;
|
|
103
|
+
tenantId: string;
|
|
104
|
+
roles: string[];
|
|
105
|
+
organizations: SessionOrganization[];
|
|
106
|
+
expiresAt: string;
|
|
107
|
+
}
|
|
108
|
+
/** Why there is no session. */
|
|
109
|
+
type SessionStatus = 'authenticated' | 'unauthenticated' | 'expired';
|
|
110
|
+
declare class CauthyConfigError extends Error {
|
|
111
|
+
constructor(message: string);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** The key an application signs its assertions with. */
|
|
115
|
+
interface SystemKey {
|
|
116
|
+
/** The private key: PKCS#8 PEM, or a JWK (as an object or its JSON). RSA, for RS256. */
|
|
117
|
+
privateKey: string | JWK;
|
|
118
|
+
/** The id the public key is published under (`kid`). */
|
|
119
|
+
keyId: string;
|
|
120
|
+
}
|
|
121
|
+
interface SystemOptions {
|
|
122
|
+
/** Cauthy's address. Default: `CAUTHY_ISSUER`. */
|
|
123
|
+
issuer?: string;
|
|
124
|
+
/** The application's client id. Default: `CAUTHY_CLIENT_ID`. */
|
|
125
|
+
clientId?: string;
|
|
126
|
+
/** Its secret. Default: `CAUTHY_CLIENT_SECRET`. Not needed with `key`. */
|
|
127
|
+
clientSecret?: string;
|
|
128
|
+
/**
|
|
129
|
+
* The key to prove who the application is with, instead of the secret.
|
|
130
|
+
* Default: `CAUTHY_SYSTEM_KEY` (the private key) and `CAUTHY_SYSTEM_KEY_ID`.
|
|
131
|
+
*/
|
|
132
|
+
key?: SystemKey;
|
|
133
|
+
fetch?: typeof fetch;
|
|
134
|
+
}
|
|
135
|
+
/** Cauthy refused a request of the application's own. */
|
|
136
|
+
declare class CauthyApiError extends Error {
|
|
137
|
+
readonly status: number;
|
|
138
|
+
/** Cauthy's code for what went wrong: `organization_not_found`, `other_system`, `outside_system_scope`… */
|
|
139
|
+
readonly code: string;
|
|
140
|
+
constructor(status: number,
|
|
141
|
+
/** Cauthy's code for what went wrong: `organization_not_found`, `other_system`, `outside_system_scope`… */
|
|
142
|
+
code: string, message: string);
|
|
143
|
+
}
|
|
144
|
+
/** An organization of the application's system. Every moment is UTC. */
|
|
145
|
+
interface Organization {
|
|
146
|
+
id: string;
|
|
147
|
+
system: string;
|
|
148
|
+
name: string;
|
|
149
|
+
kind: string;
|
|
150
|
+
/** The id the application knows it by. */
|
|
151
|
+
externalId?: string;
|
|
152
|
+
status: 'active' | 'archived';
|
|
153
|
+
metadata: Record<string, JsonValue>;
|
|
154
|
+
members: number;
|
|
155
|
+
createdAt: string;
|
|
156
|
+
updatedAt: string;
|
|
157
|
+
}
|
|
158
|
+
interface OrganizationMember {
|
|
159
|
+
userId: string;
|
|
160
|
+
email: string;
|
|
161
|
+
name: string;
|
|
162
|
+
/** The account's status: a disabled member is still listed. */
|
|
163
|
+
status: string;
|
|
164
|
+
role: string;
|
|
165
|
+
/** True when the address had no account: one was made and invited. */
|
|
166
|
+
invited?: boolean;
|
|
167
|
+
}
|
|
168
|
+
/** Who to add: an account by its id, or anybody by their address (invited when new). */
|
|
169
|
+
type NewMember = {
|
|
170
|
+
role: string;
|
|
171
|
+
name?: string;
|
|
172
|
+
locale?: string;
|
|
173
|
+
} & ({
|
|
174
|
+
userId: string;
|
|
175
|
+
email?: undefined;
|
|
176
|
+
} | {
|
|
177
|
+
email: string;
|
|
178
|
+
userId?: undefined;
|
|
179
|
+
});
|
|
180
|
+
interface CauthySystem {
|
|
181
|
+
/** The application's own token, asked for when needed and kept until it is about to run out. */
|
|
182
|
+
token(): Promise<string>;
|
|
183
|
+
/** Any route the application's token may call; answers what Cauthy put under `data`. */
|
|
184
|
+
request<T = unknown>(method: string, path: string, body?: unknown): Promise<T>;
|
|
185
|
+
organizations: {
|
|
186
|
+
list(query?: {
|
|
187
|
+
q?: string;
|
|
188
|
+
status?: 'active' | 'archived';
|
|
189
|
+
limit?: number;
|
|
190
|
+
offset?: number;
|
|
191
|
+
}): Promise<{
|
|
192
|
+
items: Organization[];
|
|
193
|
+
total: number;
|
|
194
|
+
}>;
|
|
195
|
+
create(input: {
|
|
196
|
+
name: string;
|
|
197
|
+
kind?: string;
|
|
198
|
+
externalId?: string;
|
|
199
|
+
metadata?: Record<string, JsonValue>;
|
|
200
|
+
}): Promise<Organization>;
|
|
201
|
+
get(id: string): Promise<Organization>;
|
|
202
|
+
update(id: string, patch: {
|
|
203
|
+
name?: string;
|
|
204
|
+
kind?: string;
|
|
205
|
+
status?: 'active' | 'archived';
|
|
206
|
+
metadata?: Record<string, JsonValue>;
|
|
207
|
+
}): Promise<Organization>;
|
|
208
|
+
/** Removes the organization and every membership of it, for good. */
|
|
209
|
+
remove(id: string): Promise<void>;
|
|
210
|
+
};
|
|
211
|
+
members: {
|
|
212
|
+
list(organizationId: string): Promise<OrganizationMember[]>;
|
|
213
|
+
add(organizationId: string, member: NewMember): Promise<OrganizationMember>;
|
|
214
|
+
setRole(organizationId: string, userId: string, role: string): Promise<OrganizationMember>;
|
|
215
|
+
remove(organizationId: string, userId: string): Promise<void>;
|
|
216
|
+
};
|
|
217
|
+
/** Invites a person who has no account yet; answers the account made for them. */
|
|
218
|
+
invite(person: {
|
|
219
|
+
email: string;
|
|
220
|
+
name?: string;
|
|
221
|
+
locale?: string;
|
|
222
|
+
}): Promise<{
|
|
223
|
+
id: string;
|
|
224
|
+
email: string;
|
|
225
|
+
}>;
|
|
226
|
+
/** The public half of `key`, to serve at the address Cauthy was given (`jwks_uri`). Empty with a secret. */
|
|
227
|
+
publicJwks(): Promise<{
|
|
228
|
+
keys: JWK[];
|
|
229
|
+
}>;
|
|
230
|
+
}
|
|
231
|
+
declare function createSystem(given?: SystemOptions): CauthySystem;
|
|
232
|
+
|
|
233
|
+
export { CauthyApiError as C, type JsonValue as J, type NewMember as N, type Organization as O, type PublicSession as P, type Session as S, CauthyConfigError as a, type CauthyOptions as b, type CauthySystem as c, type OrganizationMember as d, type SessionOrganization as e, type SessionStatus as f, type SessionUser as g, type SystemKey as h, type SystemOptions as i, createSystem as j };
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import { JWK } from 'jose';
|
|
2
|
+
|
|
3
|
+
/** How an application is set up to sign its people in with Cauthy. */
|
|
4
|
+
interface CauthyOptions {
|
|
5
|
+
/** Cauthy's public address, e.g. `https://id.example.com`. Default: `CAUTHY_ISSUER`. */
|
|
6
|
+
issuer?: string;
|
|
7
|
+
/** The application's OAuth client id. Default: `CAUTHY_CLIENT_ID`. */
|
|
8
|
+
clientId?: string;
|
|
9
|
+
/** Its secret, when the client is confidential. Default: `CAUTHY_CLIENT_SECRET`. */
|
|
10
|
+
clientSecret?: string;
|
|
11
|
+
/**
|
|
12
|
+
* The key the session cookie is encrypted with: any string of 32 characters
|
|
13
|
+
* or more, kept on the server. Default: `CAUTHY_SECRET`.
|
|
14
|
+
*/
|
|
15
|
+
secret?: string;
|
|
16
|
+
/**
|
|
17
|
+
* The system this application is, as its organizations are filed under in
|
|
18
|
+
* Cauthy (`"pondari"`). When set, a session's organizations are that
|
|
19
|
+
* system's. Default: `CAUTHY_SYSTEM`.
|
|
20
|
+
*/
|
|
21
|
+
system?: string;
|
|
22
|
+
/** Where the routes are mounted. Default: `/api/auth`. */
|
|
23
|
+
basePath?: string;
|
|
24
|
+
/**
|
|
25
|
+
* The application's own public origin (`https://app.example.com`), for the
|
|
26
|
+
* redirect URI. Default: the origin of each request, which is right unless
|
|
27
|
+
* a proxy hides it.
|
|
28
|
+
*/
|
|
29
|
+
baseURL?: string;
|
|
30
|
+
/** Where a person lands after signing in, when no `return_to` was asked. Default: `/`. */
|
|
31
|
+
afterSignIn?: string;
|
|
32
|
+
/** Where a person lands after signing out. Default: `/`. */
|
|
33
|
+
afterSignOut?: string;
|
|
34
|
+
/** Name of the session cookie. Default: `cauthy_session`. */
|
|
35
|
+
cookieName?: string;
|
|
36
|
+
/**
|
|
37
|
+
* A key the application proves who it is with when it acts on its own
|
|
38
|
+
* (`auth.system`), instead of its secret. Default: `CAUTHY_SYSTEM_KEY` and
|
|
39
|
+
* `CAUTHY_SYSTEM_KEY_ID`.
|
|
40
|
+
*/
|
|
41
|
+
systemKey?: SystemKey;
|
|
42
|
+
/** `fetch` to reach Cauthy with. Default: the global one. */
|
|
43
|
+
fetch?: typeof fetch;
|
|
44
|
+
}
|
|
45
|
+
/** The person signed in. Every moment is UTC. */
|
|
46
|
+
interface SessionUser {
|
|
47
|
+
id: string;
|
|
48
|
+
email: string;
|
|
49
|
+
name: string;
|
|
50
|
+
emailVerified: boolean;
|
|
51
|
+
/**
|
|
52
|
+
* True when the account ran out of time to confirm its address: let it read
|
|
53
|
+
* and refuse its writes.
|
|
54
|
+
*/
|
|
55
|
+
restricted: boolean;
|
|
56
|
+
/** When an unconfirmed address stops being enough (ISO 8601, UTC), if there is a deadline. */
|
|
57
|
+
emailVerifyBy?: string;
|
|
58
|
+
/** The language the person reads in ("es", "en-US"), when Cauthy knows it. */
|
|
59
|
+
locale?: string;
|
|
60
|
+
}
|
|
61
|
+
/** A value JSON can carry. What crosses from server to browser is typed as this, never `unknown`. */
|
|
62
|
+
type JsonValue = string | number | boolean | null | JsonValue[] | {
|
|
63
|
+
[key: string]: JsonValue;
|
|
64
|
+
};
|
|
65
|
+
/** An organization the person belongs to, with their role in it. */
|
|
66
|
+
interface SessionOrganization {
|
|
67
|
+
id: string;
|
|
68
|
+
system: string;
|
|
69
|
+
name: string;
|
|
70
|
+
kind: string;
|
|
71
|
+
externalId?: string;
|
|
72
|
+
role: string;
|
|
73
|
+
/** What the system keeps about the organization, as it filed it in Cauthy. */
|
|
74
|
+
metadata: Record<string, JsonValue>;
|
|
75
|
+
/**
|
|
76
|
+
* What the person may do here, as "resource:action" entries ("*" is any):
|
|
77
|
+
* their role's permissions, what it inherits, and anything given to them
|
|
78
|
+
* apart from it. Absent when the system keeps no catalog of roles in Cauthy.
|
|
79
|
+
* Check with `can(organization, resource, action)`.
|
|
80
|
+
*/
|
|
81
|
+
permissions?: string[];
|
|
82
|
+
/** What the person is denied here, whatever else allows it. */
|
|
83
|
+
denied?: string[];
|
|
84
|
+
}
|
|
85
|
+
/** A signed-in person, as the server sees them. */
|
|
86
|
+
interface Session {
|
|
87
|
+
user: SessionUser;
|
|
88
|
+
/** The Cauthy tenant the account is of. */
|
|
89
|
+
tenantId: string;
|
|
90
|
+
/** The roles the account holds in that tenant. */
|
|
91
|
+
roles: string[];
|
|
92
|
+
/**
|
|
93
|
+
* Cauthy's access token for this person: send it as `Authorization: Bearer`
|
|
94
|
+
* to another service that verifies Cauthy's tokens. Never give it to the browser.
|
|
95
|
+
*/
|
|
96
|
+
accessToken: string;
|
|
97
|
+
/** When the access token expires and the session is checked with Cauthy again (ISO 8601, UTC). */
|
|
98
|
+
expiresAt: string;
|
|
99
|
+
}
|
|
100
|
+
/** What the browser is told of a session: who, and their organizations — never a token. */
|
|
101
|
+
interface PublicSession {
|
|
102
|
+
user: SessionUser;
|
|
103
|
+
tenantId: string;
|
|
104
|
+
roles: string[];
|
|
105
|
+
organizations: SessionOrganization[];
|
|
106
|
+
expiresAt: string;
|
|
107
|
+
}
|
|
108
|
+
/** Why there is no session. */
|
|
109
|
+
type SessionStatus = 'authenticated' | 'unauthenticated' | 'expired';
|
|
110
|
+
declare class CauthyConfigError extends Error {
|
|
111
|
+
constructor(message: string);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** The key an application signs its assertions with. */
|
|
115
|
+
interface SystemKey {
|
|
116
|
+
/** The private key: PKCS#8 PEM, or a JWK (as an object or its JSON). RSA, for RS256. */
|
|
117
|
+
privateKey: string | JWK;
|
|
118
|
+
/** The id the public key is published under (`kid`). */
|
|
119
|
+
keyId: string;
|
|
120
|
+
}
|
|
121
|
+
interface SystemOptions {
|
|
122
|
+
/** Cauthy's address. Default: `CAUTHY_ISSUER`. */
|
|
123
|
+
issuer?: string;
|
|
124
|
+
/** The application's client id. Default: `CAUTHY_CLIENT_ID`. */
|
|
125
|
+
clientId?: string;
|
|
126
|
+
/** Its secret. Default: `CAUTHY_CLIENT_SECRET`. Not needed with `key`. */
|
|
127
|
+
clientSecret?: string;
|
|
128
|
+
/**
|
|
129
|
+
* The key to prove who the application is with, instead of the secret.
|
|
130
|
+
* Default: `CAUTHY_SYSTEM_KEY` (the private key) and `CAUTHY_SYSTEM_KEY_ID`.
|
|
131
|
+
*/
|
|
132
|
+
key?: SystemKey;
|
|
133
|
+
fetch?: typeof fetch;
|
|
134
|
+
}
|
|
135
|
+
/** Cauthy refused a request of the application's own. */
|
|
136
|
+
declare class CauthyApiError extends Error {
|
|
137
|
+
readonly status: number;
|
|
138
|
+
/** Cauthy's code for what went wrong: `organization_not_found`, `other_system`, `outside_system_scope`… */
|
|
139
|
+
readonly code: string;
|
|
140
|
+
constructor(status: number,
|
|
141
|
+
/** Cauthy's code for what went wrong: `organization_not_found`, `other_system`, `outside_system_scope`… */
|
|
142
|
+
code: string, message: string);
|
|
143
|
+
}
|
|
144
|
+
/** An organization of the application's system. Every moment is UTC. */
|
|
145
|
+
interface Organization {
|
|
146
|
+
id: string;
|
|
147
|
+
system: string;
|
|
148
|
+
name: string;
|
|
149
|
+
kind: string;
|
|
150
|
+
/** The id the application knows it by. */
|
|
151
|
+
externalId?: string;
|
|
152
|
+
status: 'active' | 'archived';
|
|
153
|
+
metadata: Record<string, JsonValue>;
|
|
154
|
+
members: number;
|
|
155
|
+
createdAt: string;
|
|
156
|
+
updatedAt: string;
|
|
157
|
+
}
|
|
158
|
+
interface OrganizationMember {
|
|
159
|
+
userId: string;
|
|
160
|
+
email: string;
|
|
161
|
+
name: string;
|
|
162
|
+
/** The account's status: a disabled member is still listed. */
|
|
163
|
+
status: string;
|
|
164
|
+
role: string;
|
|
165
|
+
/** True when the address had no account: one was made and invited. */
|
|
166
|
+
invited?: boolean;
|
|
167
|
+
}
|
|
168
|
+
/** Who to add: an account by its id, or anybody by their address (invited when new). */
|
|
169
|
+
type NewMember = {
|
|
170
|
+
role: string;
|
|
171
|
+
name?: string;
|
|
172
|
+
locale?: string;
|
|
173
|
+
} & ({
|
|
174
|
+
userId: string;
|
|
175
|
+
email?: undefined;
|
|
176
|
+
} | {
|
|
177
|
+
email: string;
|
|
178
|
+
userId?: undefined;
|
|
179
|
+
});
|
|
180
|
+
interface CauthySystem {
|
|
181
|
+
/** The application's own token, asked for when needed and kept until it is about to run out. */
|
|
182
|
+
token(): Promise<string>;
|
|
183
|
+
/** Any route the application's token may call; answers what Cauthy put under `data`. */
|
|
184
|
+
request<T = unknown>(method: string, path: string, body?: unknown): Promise<T>;
|
|
185
|
+
organizations: {
|
|
186
|
+
list(query?: {
|
|
187
|
+
q?: string;
|
|
188
|
+
status?: 'active' | 'archived';
|
|
189
|
+
limit?: number;
|
|
190
|
+
offset?: number;
|
|
191
|
+
}): Promise<{
|
|
192
|
+
items: Organization[];
|
|
193
|
+
total: number;
|
|
194
|
+
}>;
|
|
195
|
+
create(input: {
|
|
196
|
+
name: string;
|
|
197
|
+
kind?: string;
|
|
198
|
+
externalId?: string;
|
|
199
|
+
metadata?: Record<string, JsonValue>;
|
|
200
|
+
}): Promise<Organization>;
|
|
201
|
+
get(id: string): Promise<Organization>;
|
|
202
|
+
update(id: string, patch: {
|
|
203
|
+
name?: string;
|
|
204
|
+
kind?: string;
|
|
205
|
+
status?: 'active' | 'archived';
|
|
206
|
+
metadata?: Record<string, JsonValue>;
|
|
207
|
+
}): Promise<Organization>;
|
|
208
|
+
/** Removes the organization and every membership of it, for good. */
|
|
209
|
+
remove(id: string): Promise<void>;
|
|
210
|
+
};
|
|
211
|
+
members: {
|
|
212
|
+
list(organizationId: string): Promise<OrganizationMember[]>;
|
|
213
|
+
add(organizationId: string, member: NewMember): Promise<OrganizationMember>;
|
|
214
|
+
setRole(organizationId: string, userId: string, role: string): Promise<OrganizationMember>;
|
|
215
|
+
remove(organizationId: string, userId: string): Promise<void>;
|
|
216
|
+
};
|
|
217
|
+
/** Invites a person who has no account yet; answers the account made for them. */
|
|
218
|
+
invite(person: {
|
|
219
|
+
email: string;
|
|
220
|
+
name?: string;
|
|
221
|
+
locale?: string;
|
|
222
|
+
}): Promise<{
|
|
223
|
+
id: string;
|
|
224
|
+
email: string;
|
|
225
|
+
}>;
|
|
226
|
+
/** The public half of `key`, to serve at the address Cauthy was given (`jwks_uri`). Empty with a secret. */
|
|
227
|
+
publicJwks(): Promise<{
|
|
228
|
+
keys: JWK[];
|
|
229
|
+
}>;
|
|
230
|
+
}
|
|
231
|
+
declare function createSystem(given?: SystemOptions): CauthySystem;
|
|
232
|
+
|
|
233
|
+
export { CauthyApiError as C, type JsonValue as J, type NewMember as N, type Organization as O, type PublicSession as P, type Session as S, CauthyConfigError as a, type CauthyOptions as b, type CauthySystem as c, type OrganizationMember as d, type SessionOrganization as e, type SessionStatus as f, type SessionUser as g, type SystemKey as h, type SystemOptions as i, createSystem as j };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cauthy-auth",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Sign in with Cauthy: one route to mount, getSession on the server, useSession in the browser. No database, no screens to build.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
/** How an application is set up to sign its people in with Cauthy. */
|
|
2
|
-
interface CauthyOptions {
|
|
3
|
-
/** Cauthy's public address, e.g. `https://id.example.com`. Default: `CAUTHY_ISSUER`. */
|
|
4
|
-
issuer?: string;
|
|
5
|
-
/** The application's OAuth client id. Default: `CAUTHY_CLIENT_ID`. */
|
|
6
|
-
clientId?: string;
|
|
7
|
-
/** Its secret, when the client is confidential. Default: `CAUTHY_CLIENT_SECRET`. */
|
|
8
|
-
clientSecret?: string;
|
|
9
|
-
/**
|
|
10
|
-
* The key the session cookie is encrypted with: any string of 32 characters
|
|
11
|
-
* or more, kept on the server. Default: `CAUTHY_SECRET`.
|
|
12
|
-
*/
|
|
13
|
-
secret?: string;
|
|
14
|
-
/**
|
|
15
|
-
* The system this application is, as its organizations are filed under in
|
|
16
|
-
* Cauthy (`"pondari"`). When set, a session's organizations are that
|
|
17
|
-
* system's. Default: `CAUTHY_SYSTEM`.
|
|
18
|
-
*/
|
|
19
|
-
system?: string;
|
|
20
|
-
/** Where the routes are mounted. Default: `/api/auth`. */
|
|
21
|
-
basePath?: string;
|
|
22
|
-
/**
|
|
23
|
-
* The application's own public origin (`https://app.example.com`), for the
|
|
24
|
-
* redirect URI. Default: the origin of each request, which is right unless
|
|
25
|
-
* a proxy hides it.
|
|
26
|
-
*/
|
|
27
|
-
baseURL?: string;
|
|
28
|
-
/** Where a person lands after signing in, when no `return_to` was asked. Default: `/`. */
|
|
29
|
-
afterSignIn?: string;
|
|
30
|
-
/** Where a person lands after signing out. Default: `/`. */
|
|
31
|
-
afterSignOut?: string;
|
|
32
|
-
/** Name of the session cookie. Default: `cauthy_session`. */
|
|
33
|
-
cookieName?: string;
|
|
34
|
-
/** `fetch` to reach Cauthy with. Default: the global one. */
|
|
35
|
-
fetch?: typeof fetch;
|
|
36
|
-
}
|
|
37
|
-
/** The person signed in. Every moment is UTC. */
|
|
38
|
-
interface SessionUser {
|
|
39
|
-
id: string;
|
|
40
|
-
email: string;
|
|
41
|
-
name: string;
|
|
42
|
-
emailVerified: boolean;
|
|
43
|
-
/**
|
|
44
|
-
* True when the account ran out of time to confirm its address: let it read
|
|
45
|
-
* and refuse its writes.
|
|
46
|
-
*/
|
|
47
|
-
restricted: boolean;
|
|
48
|
-
/** When an unconfirmed address stops being enough (ISO 8601, UTC), if there is a deadline. */
|
|
49
|
-
emailVerifyBy?: string;
|
|
50
|
-
/** The language the person reads in ("es", "en-US"), when Cauthy knows it. */
|
|
51
|
-
locale?: string;
|
|
52
|
-
}
|
|
53
|
-
/** A value JSON can carry. What crosses from server to browser is typed as this, never `unknown`. */
|
|
54
|
-
type JsonValue = string | number | boolean | null | JsonValue[] | {
|
|
55
|
-
[key: string]: JsonValue;
|
|
56
|
-
};
|
|
57
|
-
/** An organization the person belongs to, with their role in it. */
|
|
58
|
-
interface SessionOrganization {
|
|
59
|
-
id: string;
|
|
60
|
-
system: string;
|
|
61
|
-
name: string;
|
|
62
|
-
kind: string;
|
|
63
|
-
externalId?: string;
|
|
64
|
-
role: string;
|
|
65
|
-
/** What the system keeps about the organization, as it filed it in Cauthy. */
|
|
66
|
-
metadata: Record<string, JsonValue>;
|
|
67
|
-
/**
|
|
68
|
-
* What the person may do here, as "resource:action" entries ("*" is any):
|
|
69
|
-
* their role's permissions, what it inherits, and anything given to them
|
|
70
|
-
* apart from it. Absent when the system keeps no catalog of roles in Cauthy.
|
|
71
|
-
* Check with `can(organization, resource, action)`.
|
|
72
|
-
*/
|
|
73
|
-
permissions?: string[];
|
|
74
|
-
/** What the person is denied here, whatever else allows it. */
|
|
75
|
-
denied?: string[];
|
|
76
|
-
}
|
|
77
|
-
/** A signed-in person, as the server sees them. */
|
|
78
|
-
interface Session {
|
|
79
|
-
user: SessionUser;
|
|
80
|
-
/** The Cauthy tenant the account is of. */
|
|
81
|
-
tenantId: string;
|
|
82
|
-
/** The roles the account holds in that tenant. */
|
|
83
|
-
roles: string[];
|
|
84
|
-
/**
|
|
85
|
-
* Cauthy's access token for this person: send it as `Authorization: Bearer`
|
|
86
|
-
* to another service that verifies Cauthy's tokens. Never give it to the browser.
|
|
87
|
-
*/
|
|
88
|
-
accessToken: string;
|
|
89
|
-
/** When the access token expires and the session is checked with Cauthy again (ISO 8601, UTC). */
|
|
90
|
-
expiresAt: string;
|
|
91
|
-
}
|
|
92
|
-
/** What the browser is told of a session: who, and their organizations — never a token. */
|
|
93
|
-
interface PublicSession {
|
|
94
|
-
user: SessionUser;
|
|
95
|
-
tenantId: string;
|
|
96
|
-
roles: string[];
|
|
97
|
-
organizations: SessionOrganization[];
|
|
98
|
-
expiresAt: string;
|
|
99
|
-
}
|
|
100
|
-
/** Why there is no session. */
|
|
101
|
-
type SessionStatus = 'authenticated' | 'unauthenticated' | 'expired';
|
|
102
|
-
declare class CauthyConfigError extends Error {
|
|
103
|
-
constructor(message: string);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
export { CauthyConfigError as C, type JsonValue as J, type PublicSession as P, type Session as S, type CauthyOptions as a, type SessionOrganization as b, type SessionStatus as c, type SessionUser as d };
|
package/dist/types-CYmUVWzY.d.ts
DELETED
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
/** How an application is set up to sign its people in with Cauthy. */
|
|
2
|
-
interface CauthyOptions {
|
|
3
|
-
/** Cauthy's public address, e.g. `https://id.example.com`. Default: `CAUTHY_ISSUER`. */
|
|
4
|
-
issuer?: string;
|
|
5
|
-
/** The application's OAuth client id. Default: `CAUTHY_CLIENT_ID`. */
|
|
6
|
-
clientId?: string;
|
|
7
|
-
/** Its secret, when the client is confidential. Default: `CAUTHY_CLIENT_SECRET`. */
|
|
8
|
-
clientSecret?: string;
|
|
9
|
-
/**
|
|
10
|
-
* The key the session cookie is encrypted with: any string of 32 characters
|
|
11
|
-
* or more, kept on the server. Default: `CAUTHY_SECRET`.
|
|
12
|
-
*/
|
|
13
|
-
secret?: string;
|
|
14
|
-
/**
|
|
15
|
-
* The system this application is, as its organizations are filed under in
|
|
16
|
-
* Cauthy (`"pondari"`). When set, a session's organizations are that
|
|
17
|
-
* system's. Default: `CAUTHY_SYSTEM`.
|
|
18
|
-
*/
|
|
19
|
-
system?: string;
|
|
20
|
-
/** Where the routes are mounted. Default: `/api/auth`. */
|
|
21
|
-
basePath?: string;
|
|
22
|
-
/**
|
|
23
|
-
* The application's own public origin (`https://app.example.com`), for the
|
|
24
|
-
* redirect URI. Default: the origin of each request, which is right unless
|
|
25
|
-
* a proxy hides it.
|
|
26
|
-
*/
|
|
27
|
-
baseURL?: string;
|
|
28
|
-
/** Where a person lands after signing in, when no `return_to` was asked. Default: `/`. */
|
|
29
|
-
afterSignIn?: string;
|
|
30
|
-
/** Where a person lands after signing out. Default: `/`. */
|
|
31
|
-
afterSignOut?: string;
|
|
32
|
-
/** Name of the session cookie. Default: `cauthy_session`. */
|
|
33
|
-
cookieName?: string;
|
|
34
|
-
/** `fetch` to reach Cauthy with. Default: the global one. */
|
|
35
|
-
fetch?: typeof fetch;
|
|
36
|
-
}
|
|
37
|
-
/** The person signed in. Every moment is UTC. */
|
|
38
|
-
interface SessionUser {
|
|
39
|
-
id: string;
|
|
40
|
-
email: string;
|
|
41
|
-
name: string;
|
|
42
|
-
emailVerified: boolean;
|
|
43
|
-
/**
|
|
44
|
-
* True when the account ran out of time to confirm its address: let it read
|
|
45
|
-
* and refuse its writes.
|
|
46
|
-
*/
|
|
47
|
-
restricted: boolean;
|
|
48
|
-
/** When an unconfirmed address stops being enough (ISO 8601, UTC), if there is a deadline. */
|
|
49
|
-
emailVerifyBy?: string;
|
|
50
|
-
/** The language the person reads in ("es", "en-US"), when Cauthy knows it. */
|
|
51
|
-
locale?: string;
|
|
52
|
-
}
|
|
53
|
-
/** A value JSON can carry. What crosses from server to browser is typed as this, never `unknown`. */
|
|
54
|
-
type JsonValue = string | number | boolean | null | JsonValue[] | {
|
|
55
|
-
[key: string]: JsonValue;
|
|
56
|
-
};
|
|
57
|
-
/** An organization the person belongs to, with their role in it. */
|
|
58
|
-
interface SessionOrganization {
|
|
59
|
-
id: string;
|
|
60
|
-
system: string;
|
|
61
|
-
name: string;
|
|
62
|
-
kind: string;
|
|
63
|
-
externalId?: string;
|
|
64
|
-
role: string;
|
|
65
|
-
/** What the system keeps about the organization, as it filed it in Cauthy. */
|
|
66
|
-
metadata: Record<string, JsonValue>;
|
|
67
|
-
/**
|
|
68
|
-
* What the person may do here, as "resource:action" entries ("*" is any):
|
|
69
|
-
* their role's permissions, what it inherits, and anything given to them
|
|
70
|
-
* apart from it. Absent when the system keeps no catalog of roles in Cauthy.
|
|
71
|
-
* Check with `can(organization, resource, action)`.
|
|
72
|
-
*/
|
|
73
|
-
permissions?: string[];
|
|
74
|
-
/** What the person is denied here, whatever else allows it. */
|
|
75
|
-
denied?: string[];
|
|
76
|
-
}
|
|
77
|
-
/** A signed-in person, as the server sees them. */
|
|
78
|
-
interface Session {
|
|
79
|
-
user: SessionUser;
|
|
80
|
-
/** The Cauthy tenant the account is of. */
|
|
81
|
-
tenantId: string;
|
|
82
|
-
/** The roles the account holds in that tenant. */
|
|
83
|
-
roles: string[];
|
|
84
|
-
/**
|
|
85
|
-
* Cauthy's access token for this person: send it as `Authorization: Bearer`
|
|
86
|
-
* to another service that verifies Cauthy's tokens. Never give it to the browser.
|
|
87
|
-
*/
|
|
88
|
-
accessToken: string;
|
|
89
|
-
/** When the access token expires and the session is checked with Cauthy again (ISO 8601, UTC). */
|
|
90
|
-
expiresAt: string;
|
|
91
|
-
}
|
|
92
|
-
/** What the browser is told of a session: who, and their organizations — never a token. */
|
|
93
|
-
interface PublicSession {
|
|
94
|
-
user: SessionUser;
|
|
95
|
-
tenantId: string;
|
|
96
|
-
roles: string[];
|
|
97
|
-
organizations: SessionOrganization[];
|
|
98
|
-
expiresAt: string;
|
|
99
|
-
}
|
|
100
|
-
/** Why there is no session. */
|
|
101
|
-
type SessionStatus = 'authenticated' | 'unauthenticated' | 'expired';
|
|
102
|
-
declare class CauthyConfigError extends Error {
|
|
103
|
-
constructor(message: string);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
export { CauthyConfigError as C, type JsonValue as J, type PublicSession as P, type Session as S, type CauthyOptions as a, type SessionOrganization as b, type SessionStatus as c, type SessionUser as d };
|