@crossauth/backend 0.0.2

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.
Files changed (109) hide show
  1. package/LICENSE +203 -0
  2. package/README.md +14 -0
  3. package/dist/apikey.d.ts +100 -0
  4. package/dist/apikey.d.ts.map +1 -0
  5. package/dist/auth.d.ts +131 -0
  6. package/dist/auth.d.ts.map +1 -0
  7. package/dist/authenticators/dummyfactor2.d.ts +129 -0
  8. package/dist/authenticators/dummyfactor2.d.ts.map +1 -0
  9. package/dist/authenticators/emailauth.d.ts +176 -0
  10. package/dist/authenticators/emailauth.d.ts.map +1 -0
  11. package/dist/authenticators/ldapauth.d.ts +89 -0
  12. package/dist/authenticators/ldapauth.d.ts.map +1 -0
  13. package/dist/authenticators/passwordauth.d.ts +159 -0
  14. package/dist/authenticators/passwordauth.d.ts.map +1 -0
  15. package/dist/authenticators/smsauth.d.ts +160 -0
  16. package/dist/authenticators/smsauth.d.ts.map +1 -0
  17. package/dist/authenticators/tests/ldapauth.test.d.ts +2 -0
  18. package/dist/authenticators/tests/ldapauth.test.d.ts.map +1 -0
  19. package/dist/authenticators/totpauth.d.ts +117 -0
  20. package/dist/authenticators/totpauth.d.ts.map +1 -0
  21. package/dist/authenticators/twilioauth.d.ts +29 -0
  22. package/dist/authenticators/twilioauth.d.ts.map +1 -0
  23. package/dist/cookieauth.d.ts +269 -0
  24. package/dist/cookieauth.d.ts.map +1 -0
  25. package/dist/crypto.d.ts +196 -0
  26. package/dist/crypto.d.ts.map +1 -0
  27. package/dist/emailtokens.d.ts +178 -0
  28. package/dist/emailtokens.d.ts.map +1 -0
  29. package/dist/index.cjs +9107 -0
  30. package/dist/index.d.ts +46 -0
  31. package/dist/index.d.ts.map +1 -0
  32. package/dist/index.js +9090 -0
  33. package/dist/oauth/authserver.d.ts +490 -0
  34. package/dist/oauth/authserver.d.ts.map +1 -0
  35. package/dist/oauth/client.d.ts +72 -0
  36. package/dist/oauth/client.d.ts.map +1 -0
  37. package/dist/oauth/clientmanager.d.ts +73 -0
  38. package/dist/oauth/clientmanager.d.ts.map +1 -0
  39. package/dist/oauth/resserver.d.ts +43 -0
  40. package/dist/oauth/resserver.d.ts.map +1 -0
  41. package/dist/oauth/tests/common.d.ts +58 -0
  42. package/dist/oauth/tests/common.d.ts.map +1 -0
  43. package/dist/oauth/tests/oauthauthserver_authzcode.test.d.ts +2 -0
  44. package/dist/oauth/tests/oauthauthserver_authzcode.test.d.ts.map +1 -0
  45. package/dist/oauth/tests/oauthauthserver_clientcred.test.d.ts +2 -0
  46. package/dist/oauth/tests/oauthauthserver_clientcred.test.d.ts.map +1 -0
  47. package/dist/oauth/tests/oauthauthserver_device.test.d.ts +2 -0
  48. package/dist/oauth/tests/oauthauthserver_device.test.d.ts.map +1 -0
  49. package/dist/oauth/tests/oauthauthserver_mfa.test.d.ts +5 -0
  50. package/dist/oauth/tests/oauthauthserver_mfa.test.d.ts.map +1 -0
  51. package/dist/oauth/tests/oauthauthserver_password.test.d.ts +2 -0
  52. package/dist/oauth/tests/oauthauthserver_password.test.d.ts.map +1 -0
  53. package/dist/oauth/tests/oauthclient.test.d.ts +2 -0
  54. package/dist/oauth/tests/oauthclient.test.d.ts.map +1 -0
  55. package/dist/oauth/tests/oauthresserver.test.d.ts +2 -0
  56. package/dist/oauth/tests/oauthresserver.test.d.ts.map +1 -0
  57. package/dist/oauth/tokenconsumer.d.ts +80 -0
  58. package/dist/oauth/tokenconsumer.d.ts.map +1 -0
  59. package/dist/session.d.ts +491 -0
  60. package/dist/session.d.ts.map +1 -0
  61. package/dist/storage/dbconnection.d.ts +19 -0
  62. package/dist/storage/dbconnection.d.ts.map +1 -0
  63. package/dist/storage/dbstorage.d.ts +319 -0
  64. package/dist/storage/dbstorage.d.ts.map +1 -0
  65. package/dist/storage/inmemorystorage.d.ts +225 -0
  66. package/dist/storage/inmemorystorage.d.ts.map +1 -0
  67. package/dist/storage/ldapstorage.d.ts +143 -0
  68. package/dist/storage/ldapstorage.d.ts.map +1 -0
  69. package/dist/storage/postgresconnection.d.ts +27 -0
  70. package/dist/storage/postgresconnection.d.ts.map +1 -0
  71. package/dist/storage/postgresstorage.d.ts +83 -0
  72. package/dist/storage/postgresstorage.d.ts.map +1 -0
  73. package/dist/storage/prismastorage.d.ts +361 -0
  74. package/dist/storage/prismastorage.d.ts.map +1 -0
  75. package/dist/storage/sqliteconnection.d.ts +35 -0
  76. package/dist/storage/sqliteconnection.d.ts.map +1 -0
  77. package/dist/storage/sqlitestorage.d.ts +83 -0
  78. package/dist/storage/sqlitestorage.d.ts.map +1 -0
  79. package/dist/storage/tests/dbtests.d.ts +5 -0
  80. package/dist/storage/tests/dbtests.d.ts.map +1 -0
  81. package/dist/storage/tests/inmemorystorage.test.d.ts +5 -0
  82. package/dist/storage/tests/inmemorystorage.test.d.ts.map +1 -0
  83. package/dist/storage/tests/inmemorytestdata.d.ts +4 -0
  84. package/dist/storage/tests/inmemorytestdata.d.ts.map +1 -0
  85. package/dist/storage/tests/ldapstorage.test.d.ts +2 -0
  86. package/dist/storage/tests/ldapstorage.test.d.ts.map +1 -0
  87. package/dist/storage/tests/postgresstorage.test.d.ts +2 -0
  88. package/dist/storage/tests/postgresstorage.test.d.ts.map +1 -0
  89. package/dist/storage/tests/prismastorage.test.d.ts +4 -0
  90. package/dist/storage/tests/prismastorage.test.d.ts.map +1 -0
  91. package/dist/storage/tests/sqlitestorage.test.d.ts +2 -0
  92. package/dist/storage/tests/sqlitestorage.test.d.ts.map +1 -0
  93. package/dist/storage.d.ts +411 -0
  94. package/dist/storage.d.ts.map +1 -0
  95. package/dist/tests/cookieauth.test.d.ts +4 -0
  96. package/dist/tests/cookieauth.test.d.ts.map +1 -0
  97. package/dist/tests/crypto.test.d.ts +2 -0
  98. package/dist/tests/crypto.test.d.ts.map +1 -0
  99. package/dist/tests/email.test.d.ts +4 -0
  100. package/dist/tests/email.test.d.ts.map +1 -0
  101. package/dist/tests/password.test.d.ts +5 -0
  102. package/dist/tests/password.test.d.ts.map +1 -0
  103. package/dist/tests/tmp.test.d.ts +2 -0
  104. package/dist/tests/tmp.test.d.ts.map +1 -0
  105. package/dist/tests/utils.test.d.ts +2 -0
  106. package/dist/tests/utils.test.d.ts.map +1 -0
  107. package/dist/utils.d.ts +41 -0
  108. package/dist/utils.d.ts.map +1 -0
  109. package/package.json +71 -0
@@ -0,0 +1,490 @@
1
+ import { OAuthClientManager, OAuthClientManagerOptions } from './clientmanager';
2
+ import { KeyStorage, UserStorage, OAuthClientStorage, OAuthAuthorizationStorage } from '../storage';
3
+ import { Authenticator } from '../auth';
4
+ import { OpenIdConfiguration, Jwks, MfaAuthenticatorResponse, OAuthClient, OAuthTokenResponse, OAuthDeviceAuthorizationResponse, OAuthDeviceResponse, User } from '@crossauth/common';
5
+
6
+ /**
7
+ * Options for {@link OAuthAuthorizationServerOptions}.
8
+ */
9
+ export interface OAuthAuthorizationServerOptions extends OAuthClientManagerOptions {
10
+ /** JWT issuer, eg https://yoursite.com. Required (no default) */
11
+ oauthIssuer?: string;
12
+ /** JWT issuer, eg https://yoursite.com. Required (no default) */
13
+ audience?: string;
14
+ /** If true, only redirect Uri's registered for the client will be
15
+ * accepted */
16
+ requireRedirectUriRegistration?: boolean;
17
+ /** If true, the authorization code flow will require either a client
18
+ * secret or PKCE challenger/verifier. Default true */
19
+ requireClientSecretOrChallenge?: boolean;
20
+ /** Authorization code length, before base64url-encoding. Default 32 */
21
+ codeLength?: number;
22
+ /** The algorithm to sign JWTs with. Default `RS256` */
23
+ jwtAlgorithm?: string;
24
+ /** Type of key in jwtPublicKey, jwtPublicKeyFile, etc, eg RS256*/
25
+ jwtKeyType?: string;
26
+ /** Secret key if using a symmetric cipher for signing the JWT.
27
+ * Either this or `jwtSecretKeyFile` is required when using this kind of
28
+ * cipher*/
29
+ jwtSecretKey?: string;
30
+ /** Filename with secret key if using a symmetric cipher for signing the
31
+ * JWT. Either this or `jwtSecretKey` is required when using this kind
32
+ * of cipher*/
33
+ jwtSecretKeyFile?: string;
34
+ /** Filename for the private key if using a public key cipher for
35
+ * signing the JWT. Either this or `jwtPrivateKey` is required when
36
+ * using this kind of cipher. publicKey or publicKeyFile is also
37
+ * required. */
38
+ jwtPrivateKeyFile?: string;
39
+ /** Tthe public key if using a public key cipher for signing the JWT.
40
+ * Either this or `jwtPrivateKey` is required when using this kind of
41
+ * cipher. publicKey or publicKeyFile is also required. */
42
+ jwtPrivateKey?: string;
43
+ /** Filename for the public key if using a public key cipher for signing
44
+ * the JWT. Either this or `jwtPublicKey` is required when using this
45
+ * kind of cipher. privateKey or privateKeyFile is also required. */
46
+ jwtPublicKeyFile?: string;
47
+ /** The public key if using a public key cipher for signing the JWT.
48
+ * Either this or `jwtPublicKeyFile` is required when using this kind of
49
+ * cipher. privateKey or privateKeyFile is also required. */
50
+ jwtPublicKey?: string;
51
+ /**
52
+ * The kid to give the jwt signing key. Default "1".
53
+ */
54
+ jwtKid?: string;
55
+ /** Whether to persist access tokens in key storage. Default false */
56
+ persistAccessToken?: boolean;
57
+ /** Whether to issue a refresh token. Default false */
58
+ issueRefreshToken?: boolean;
59
+ /** If true, access token will contain no data, just a random string.
60
+ * This will turn persistAccessToken on. Default false. */
61
+ opaqueAccessToken?: boolean;
62
+ /** Expiry for access tokens in seconds. If null, they don't expire.
63
+ * Defult 1 hour */
64
+ accessTokenExpiry?: number | null;
65
+ /** Expiry for refresh tokens in seconds. If null, they don't expire.
66
+ * Defult 1 hour */
67
+ refreshTokenExpiry?: number | null;
68
+ /** If true, a new refresh token, with new expiry, will be issued every
69
+ * time the access token is refreshed. Default true */
70
+ rollingRefreshToken?: boolean;
71
+ /** Expiry for authorization codes in seconds. If null, they don't
72
+ * expire. Defult 5 minutes */
73
+ authorizationCodeExpiry?: number | null;
74
+ /** Expiry for user codes codes in seconds. Defult 5 minutes */
75
+ userCodeExpiry?: number;
76
+ /** Milliseconds to wait after each failed code attempt
77
+ * Default 1500. A 1500ms throttle and 8 character user codes gives
78
+ * a brute force a 2^-32 chance of success at brute forcing.
79
+ */
80
+ userCodeThrottle?: number;
81
+ /** For device code flow, tell client to use a poll interval of this many seconds.
82
+ * Default 5.
83
+ */
84
+ deviceCodePollInterval?: number;
85
+ /** Length for device codes (before base64-encoding). Default 16
86
+ */
87
+ deviceCodeLength?: number;
88
+ /**
89
+ * Length for user codes codes in base 32. Default 8.
90
+ */
91
+ userCodeLength?: number;
92
+ /**
93
+ * Put a dash after this number of characters in user codes.
94
+ * null means no dashes. Dashes are ignored during validation.
95
+ * Default 4
96
+ */
97
+ userCodeDashEvery?: number;
98
+ /**
99
+ * URI to tell user to go to to enter user code in device code flow.
100
+ *
101
+ * No default - required if using the device flow.
102
+ */
103
+ deviceCodeVerificationUri?: string;
104
+ /** Expiry for authorization codes in seconds. If null, they don't
105
+ * expire. Defult 5 minutes */
106
+ mfaTokenExpiry?: number | null;
107
+ /** Number of seconds tolerance when checking expiration. Default 10 */
108
+ clockTolerance?: number;
109
+ /** If false, authorization calls without a scope will be disallowed.
110
+ * Default true */
111
+ emptyScopeIsValid?: boolean;
112
+ /** If true, a requested scope must match one in the `validScopes` list
113
+ * or an error will be returned. Default false. */
114
+ validateScopes?: boolean;
115
+ /** See `validateScopes`. This should be a comma separated list, case
116
+ * sensitive, default empty */
117
+ validScopes?: string[];
118
+ /** Flows to support. A comma-separated list from {@link @crossauth/common!OAuthFlows}.
119
+ * If [`all`], there must be none other in the list. Default [`all`] */
120
+ validFlows?: string[];
121
+ /** Required if emptyScopeIsValid is false */
122
+ authStorage?: OAuthAuthorizationStorage;
123
+ /** Required if activating the password flow */
124
+ userStorage?: UserStorage;
125
+ /** A JSON string of customs fields per scope to put in id token.
126
+ * `{"scope": "all"}` or `{"scope": {"idtokenfield" : "userfield"}}`.
127
+ * If `scope` is `all` then it applies to all scopes
128
+ */
129
+ idTokenClaims?: {
130
+ [key: string]: string | string[] | {
131
+ [key: string]: string;
132
+ };
133
+ };
134
+ /**
135
+ * The 2FA factors that are allowed for the Password MFA flow.
136
+ */
137
+ allowedFactor2?: string[];
138
+ }
139
+ /**
140
+ * OAuth authorization server.
141
+ *
142
+ * This provides framework-independent functionality for the
143
+ * authorization server. It supports the Authorization Code Flow
144
+ * with and without PKCE, the Password Flow. Refresh Token Flow,
145
+ * Client Credentials Flow and the Password MFA flow. For the later, see
146
+ * {@link https://auth0.com/docs/secure/multi-factor-authentication/multi-factor-authentication-factors}.
147
+ *
148
+ * It also supports the OpenID Connect Authorization Code Flow, with and
149
+ * without PKCE.
150
+ */
151
+ export declare class OAuthAuthorizationServer {
152
+ private clientStorage;
153
+ private keyStorage;
154
+ private userStorage?;
155
+ private authenticators;
156
+ private authStorage?;
157
+ /** For validating redirect URIs. */
158
+ clientManager: OAuthClientManager;
159
+ private oauthIssuer;
160
+ private audience;
161
+ private requireRedirectUriRegistration;
162
+ private requireClientSecretOrChallenge;
163
+ private jwtAlgorithm;
164
+ private jwtAlgorithmChecked;
165
+ private codeLength;
166
+ private jwtKeyType;
167
+ private jwtSecretKey;
168
+ private jwtPublicKey;
169
+ private jwtPrivateKey;
170
+ private jwtSecretKeyFile;
171
+ private jwtPublicKeyFile;
172
+ private jwtPrivateKeyFile;
173
+ private jwtKid;
174
+ private secretOrPrivateKey;
175
+ private secretOrPublicKey;
176
+ private persistAccessToken;
177
+ private issueRefreshToken;
178
+ private opaqueAccessToken;
179
+ private accessTokenExpiry;
180
+ private refreshTokenExpiry;
181
+ private rollingRefreshToken;
182
+ private authorizationCodeExpiry;
183
+ private mfaTokenExpiry;
184
+ private clockTolerance;
185
+ private emptyScopeIsValid;
186
+ private validateScopes;
187
+ private validScopes;
188
+ private idTokenClaims;
189
+ private userCodeExpiry;
190
+ readonly userCodeThrottle = 1500;
191
+ private deviceCodePollInterval;
192
+ private userCodeLength;
193
+ private deviceCodeLength;
194
+ private userCodeDashEvery;
195
+ private deviceCodeVerificationUri;
196
+ /** Set from options. See {@link OAuthAuthorizationServerOptions.validFlows} */
197
+ validFlows: string[];
198
+ /** Set from options. See {@link OAuthAuthorizationServerOptions.allowedFactor2} */
199
+ allowedFactor2: string[];
200
+ /**
201
+ * Constructor
202
+ *
203
+ * @param clientStorage where OAuth clients are stored
204
+ * @param keyStorage where session IDs are stored
205
+ * @param authenticators set of authenticators for validating users
206
+ * with Password and Password MFA flows
207
+ * (all factor 1 authenticators users may have plus factor 2
208
+ * authenticators for the Password MFA flow)
209
+ * @param options See {@link OAuthAuthorizationServerOptions }
210
+ */
211
+ constructor(clientStorage: OAuthClientStorage, keyStorage: KeyStorage, authenticators?: {
212
+ [key: string]: Authenticator;
213
+ }, options?: OAuthAuthorizationServerOptions);
214
+ /**
215
+ * The the OAuth2 authorize endpoint. All parameters are expected to be
216
+ * strings and have be URL-decoded.
217
+ *
218
+ * For arguments and return parameters, see OAuth2 documentation.
219
+ * @param options object whose values correspond to the OAuth `authorize`
220
+ * endpoint, plus `user` if one is logged in at the authorization
221
+ * server.
222
+ * @returns Values that correspond to the OAuth `authorize` endpoint
223
+ * JSON response.
224
+ */
225
+ authorizeGetEndpoint({ responseType, client_id, redirect_uri, scope, state, codeChallenge, codeChallengeMethod, user, }: {
226
+ responseType: string;
227
+ client_id: string;
228
+ redirect_uri: string;
229
+ scope?: string;
230
+ state: string;
231
+ codeChallenge?: string;
232
+ codeChallengeMethod?: string;
233
+ user?: User;
234
+ }): Promise<{
235
+ code?: string;
236
+ state?: string;
237
+ error?: string;
238
+ error_description?: string;
239
+ }>;
240
+ /**
241
+ * Returns whether or not the user has authorized all the passed scopes
242
+ * for the given client.
243
+ *
244
+ * @param client_id the client ID
245
+ * @param user the user logged in at the authorization server.
246
+ * @param requestedScopes the scopes that have been requested
247
+ * @returns true or false.
248
+ */
249
+ hasAllScopes(client_id: string, user: User | undefined, requestedScopes: (string | null)[]): Promise<boolean>;
250
+ validateAndPersistScope(client_id: string, scope?: string, user?: User): Promise<{
251
+ scopes?: string[] | undefined;
252
+ error?: string;
253
+ error_description?: string;
254
+ }>;
255
+ private authenticateClient;
256
+ /**
257
+ * Returns the matching client or an error if it does nto exist
258
+ * @param client_id
259
+ * @returns the client_id, or an error or `access_denied`.
260
+ */
261
+ getClientById(client_id: string): Promise<{
262
+ client?: OAuthClient;
263
+ error?: string;
264
+ error_description?: string;
265
+ }>;
266
+ /**
267
+ * The the OAuth2 authorize endpoint. All parameters are expected to be
268
+ * strings and have been URL-decoded.
269
+ *
270
+ * For arguments and return parameters, see OAuth2 documentation.
271
+ * @param options these arguments correspond to the OAuth `token`
272
+ * endpoint inputs.
273
+ * @return the return object's fields correspond to the OAuth `token`
274
+ * endpoint JSON output.
275
+ */
276
+ tokenEndpoint({ grantType, client_id, scope, code, client_secret, codeVerifier, refreshToken, username, password, mfaToken, oobCode, bindingCode, otp, deviceCode, }: {
277
+ grantType: string;
278
+ client_id: string;
279
+ scope?: string;
280
+ code?: string;
281
+ client_secret?: string;
282
+ codeVerifier?: string;
283
+ refreshToken?: string;
284
+ username?: string;
285
+ password?: string;
286
+ mfaToken?: string;
287
+ oobCode?: string;
288
+ bindingCode?: string;
289
+ otp?: string;
290
+ deviceCode?: string;
291
+ }): Promise<OAuthTokenResponse>;
292
+ private deleteDeviceCode;
293
+ private deleteUserCode;
294
+ /**
295
+ * The the OAuth2 device authorization endpoint for starting the
296
+ * device flow. All parameters are expected to be
297
+ * strings and have been URL-decoded.
298
+ *
299
+ * For arguments and return parameters, see RFC 8628.
300
+ * @param options these arguments correspond to the device authorization
301
+ * endpoint in RFC 8628 section 3.1.
302
+ * @return the return object's fields correspond to the OAuth `token`
303
+ * endpoint JSON output.
304
+ */
305
+ deviceAuthorizationEndpoint({ client_id, scope, client_secret, }: {
306
+ client_id: string;
307
+ scope?: string;
308
+ client_secret?: string;
309
+ }): Promise<OAuthDeviceAuthorizationResponse>;
310
+ /**
311
+ * The the OAuth2 device authorization endpoint for starting the
312
+ * device flow. All parameters are expected to be
313
+ * strings and have been URL-decoded.
314
+ *
315
+ * For arguments and return parameters, see RFC 8628.
316
+ * @param options these arguments correspond to the device authorization
317
+ * endpoint in RFC 8628 section 3.1.
318
+ * @return the return object's fields correspond to the OAuth `token`
319
+ * endpoint JSON output.
320
+ */
321
+ deviceEndpoint({ userCode, user, }: {
322
+ userCode: string;
323
+ user: User;
324
+ }): Promise<OAuthDeviceResponse>;
325
+ authorizeDeviceFlowScopes(userCode: string): Promise<OAuthDeviceResponse>;
326
+ createMfaRequest(user: User): Promise<{
327
+ mfa_token: string;
328
+ error: string;
329
+ error_description: string;
330
+ }>;
331
+ private validateMfaToken;
332
+ mfaAuthenticatorsEndpoint(mfaToken: string): Promise<{
333
+ authenticators?: MfaAuthenticatorResponse[];
334
+ error?: string;
335
+ error_description?: string;
336
+ }>;
337
+ /**
338
+ * The OAuth Password MFA `challenge` endpoint
339
+ * @param mfaToken as defined by the Password MFA spec
340
+ * @param client_id as defined by the Password MFA spec
341
+ * @param client_secret as defined by the Password MFA spec
342
+ * @param challengeType as defined by the Password MFA spec
343
+ * @param authenticatorId as defined by the Password MFA spec
344
+ * @returns respond as defined by the Password MFA spec
345
+ */
346
+ mfaChallengeEndpoint(mfaToken: string, client_id: string, client_secret: string | undefined, challengeType: string, authenticatorId: string): Promise<{
347
+ challenge_type?: string;
348
+ oob_code?: string;
349
+ binding_method?: string;
350
+ error?: string;
351
+ error_description?: string;
352
+ }>;
353
+ /**
354
+ * Returns the OAuth flow type that corresonds to the given
355
+ * response type, scope and value for `code_challenge`
356
+ * @param responseType OAuth `response_type`
357
+ * @param scope Requested scopes (checks if it included `openid`)
358
+ * @param codeChallenge the OAuth code challenge (checks if it is defined)
359
+ * @returns returns the flow key from {@link @crossauth/common!OAuthFlows}
360
+ */
361
+ inferFlowFromGet(responseType: string, scope: string[], codeChallenge?: string): string | undefined;
362
+ /**
363
+ * Returns the OAuth flow type that corresonds to the given
364
+ * grant type and `code_verifier`
365
+ * @param grantType OAuth `grant_type`
366
+ * @param codeVerifier the OAuth code verifier (checks if it is defined)
367
+ * @returns returns the flow key from {@link @crossauth/common!OAuthFlows}
368
+ */
369
+ inferFlowFromPost(grantType: string, codeVerifier?: string): string | undefined;
370
+ private getAuthorizationCode;
371
+ /**
372
+ * Create an access token
373
+ */
374
+ makeAccessToken({ client, code, client_secret, codeVerifier, scopes, issueRefreshToken, user }: {
375
+ client: OAuthClient;
376
+ code?: string;
377
+ client_secret?: string;
378
+ codeVerifier?: string;
379
+ scopes?: string[];
380
+ issueRefreshToken?: boolean;
381
+ user?: User;
382
+ }): Promise<OAuthTokenResponse>;
383
+ /**
384
+ * Returns whether the given authorization code is valid (in the database)
385
+ *
386
+ * @param code the authorization code to look up
387
+ * @returns true or false
388
+ */
389
+ validAuthorizationCode(code: string): Promise<boolean>;
390
+ /**
391
+ * Returns whether the given refresh token is valid (in the database)
392
+ *
393
+ * @param token the refresh token to look up
394
+ * @returns true or false
395
+ */
396
+ validRefreshToken(token: string): Promise<boolean>;
397
+ /**
398
+ * Gets the data associated with the refresh token from the database.
399
+ * @param token the refresh token to fetch
400
+ * @returns the object parsed from the stored JSON data for the token,
401
+ * or undefined if there was an error
402
+ */
403
+ getRefreshTokenData(token?: string): Promise<{
404
+ [key: string]: any;
405
+ } | undefined>;
406
+ /**
407
+ * Validates a JWT token, returning its payload or undefined if it
408
+ * is invalid.
409
+ *
410
+ * @param token the token to validate
411
+ * @returns the payload or undefinedf if there was an error
412
+ */
413
+ validIdToken(token: string): Promise<{
414
+ [key: string]: any;
415
+ } | undefined>;
416
+ /**
417
+ * Validates a JWT access token, returning its payload or undefined if it
418
+ * is invalid.
419
+ *
420
+ * @param token the token to validate
421
+ * @returns the payload or undefinedf if there was an error ir the
422
+ * `type` field in the payload is not `access`.
423
+ */
424
+ validAccessToken(token: string): Promise<{
425
+ [key: string]: any;
426
+ } | undefined>;
427
+ private validateJwt;
428
+ private validateScope;
429
+ /**
430
+ * Appends the scope and state to the redirect URI
431
+ * @param redirect_uri the redirect URI, whicvh may already contain
432
+ * query parameters
433
+ * @param code the authorization code to append
434
+ * @param state the state to append
435
+ * @returns the new URL as a string.
436
+ */
437
+ redirect_uri(redirect_uri: string, code: string, state: string): string;
438
+ /**
439
+ * @returns all the response types that are supported.
440
+ */
441
+ responseTypesSupported(): string[];
442
+ /**
443
+ * Returns an OIDC configuration object based on this authorization
444
+ * server's configuration
445
+ * @param options
446
+ * - `authorizeEndpoint` the URL for the `authorize` endpoint
447
+ * - `tokenEndpoint` the URL for the `token` endpoint
448
+ * - `jwksUri` the URL for the `jwks` endpoint
449
+ * - `additionalClaims` additional claims that can be returned
450
+ * in an ID token ("iss", "sub", "aud", "jti", "iat", "type"
451
+ * are always included)
452
+ * @returns the OIDC configuration
453
+ */
454
+ oidcConfiguration({ authorizeEndpoint, tokenEndpoint, jwksUri, additionalClaims }: {
455
+ authorizeEndpoint?: string;
456
+ tokenEndpoint?: string;
457
+ jwksUri: string;
458
+ additionalClaims?: string[];
459
+ }): OpenIdConfiguration;
460
+ /**
461
+ * Returns the public key for validating JWT signatures.
462
+ *
463
+ * If there isn't one, returns an empty array.
464
+ * @returns an array of keys with exactly one or zero entries.
465
+ */
466
+ jwks(): Jwks;
467
+ private validateState;
468
+ /**
469
+ * Validates the parameters passed to the `authorize` endpoint
470
+ *
471
+ * This doesn't query a user or look anything up in the database.
472
+ * It just checks that they have valid syntax.
473
+ *
474
+ * @param options these parameters correspond to the OAuth specification
475
+ * @returns an empty object or an error if the parameters were not valid
476
+ */
477
+ validateAuthorizeParameters({ response_type, client_id, redirect_uri, scope, state, code_challenge, code_challenge_method, }: {
478
+ response_type: string;
479
+ client_id: string;
480
+ redirect_uri: string;
481
+ scope?: string;
482
+ state: string;
483
+ code_challenge?: string;
484
+ code_challenge_method?: string;
485
+ }): {
486
+ error?: string;
487
+ error_description?: string;
488
+ };
489
+ }
490
+ //# sourceMappingURL=authserver.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authserver.d.ts","sourceRoot":"","sources":["../../src/oauth/authserver.ts"],"names":[],"mappings":"AAEA,OAAO,EACH,kBAAkB,EAClB,KAAK,y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AAM,CAAC;QAAC,iBAAiB,CAAC,EAAG,MAAM,CAAA;KAAC;CAsCzF"}
@@ -0,0 +1,72 @@
1
+ import { OAuthClientBase } from '@crossauth/common';
2
+ import { OAuthTokenConsumerOptions } from './tokenconsumer';
3
+
4
+ /**
5
+ * Options for {@link OAuthClientBackend}
6
+ */
7
+ export interface OAuthClientOptions extends OAuthTokenConsumerOptions {
8
+ /** Length of random state variable for passing to `authorize` endpoint
9
+ * (before bsae64-url-encoding)
10
+ */
11
+ stateLength?: number;
12
+ /** Length of random code verifier to generate
13
+ * (before bsae64-url-encoding)
14
+ * */
15
+ verifierLength?: number;
16
+ /**
17
+ * Client ID for this client
18
+ */
19
+ client_id?: string;
20
+ /**
21
+ * Client secret for this client (can be undefined for no secret)
22
+ */
23
+ client_secret?: string;
24
+ /**
25
+ * Redirect URI to send in `authorize` requests
26
+ */
27
+ redirect_uri?: string;
28
+ /**
29
+ * Type of code challenge for PKCE
30
+ */
31
+ codeChallengeMethod?: "plain" | "S256";
32
+ /**
33
+ * URL to call for the device_authorization endpoint, relative to
34
+ * the `authServerBaseUrl`.
35
+ *
36
+ * Default `device_authorization`
37
+ */
38
+ deviceAuthorizationUrl?: string;
39
+ }
40
+ /**
41
+ * An OAuth clientframework-independent base class)
42
+ *
43
+ * Most of the functionality is in the base class
44
+ * {@link @crossauth/common!OAuthClientBase}. However that class is designed
45
+ * to work in the browser as well as node, and therefore the cryptography
46
+ * is let out of there and added in here.
47
+ */
48
+ export declare class OAuthClientBackend extends OAuthClientBase {
49
+ protected deviceAuthorizationUrl: string;
50
+ /**
51
+ * Constructor
52
+ * @param authServerBaseUrl bsae URI for the authorization server
53
+ * expected to issue access tokens. If the `iss` field in a JWT
54
+ * does not match this, it is rejected.
55
+ * @param options See {@link OAuthClientOptions}
56
+ */
57
+ constructor(authServerBaseUrl: string, options: OAuthClientOptions);
58
+ /**
59
+ * Uses {@link @crossauth/backend!Crypto.randomValue} to create a random string
60
+ * @param length the length of the random array of bytes before
61
+ * base64-url-encoding
62
+ * @returns the Base64-URL-encoded random string
63
+ */
64
+ protected randomValue(length: number): string;
65
+ /**
66
+ * Uses {@link @crossauth/backend!Crypto.sha256} to create hash a string using SHA256
67
+ * @param plaintext the text to hash
68
+ * @returns the Base64-URL-encoded hash
69
+ */
70
+ protected sha256(plaintext: string): Promise<string>;
71
+ }
72
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/oauth/client.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAGpD,OAAO,EAEH,KAAK,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;AAE5D;;GAEG;AACH,MAAM,WAAW,kBAAmB,SAAQ,yBAAyB;IAEjE;;OAEG;IACH,WAAW,CAAC,EAAG,MAAM,CAAC;IAEtB;;SAEK;IACL,cAAc,CAAC,EAAG,MAAM,CAAC;IAEzB;;OAEG;IACH,SAAS,CAAC,EAAG,MAAM,CAAC;IAEpB;;OAEG;IACH,aAAa,CAAC,EAAG,MAAM,CAAC;IAExB;;OAEG;IACH,YAAY,CAAC,EAAG,MAAM,CAAC;IAEvB;;OAEG;IACH,mBAAmB,CAAC,EAAG,OAAO,GAAG,MAAM,CAAC;IAExC;;;;;OAKG;IACH,sBAAsB,CAAC,EAAG,MAAM,CAAC;CACpC;AAED;;;;;;;GAOG;AACH,qBAAa,kBAAmB,SAAQ,eAAe;IAEnD,SAAS,CAAC,sBAAsB,EAAG,MAAM,CAA0B;IACnE;;;;;;OAMG;gBACS,iBAAiB,EAAG,MAAM,EAAE,OAAO,EAAG,kBAAkB;IAyBpE;;;;;OAKG;IACH,SAAS,CAAC,WAAW,CAAC,MAAM,EAAG,MAAM,GAAI,MAAM;IAI/C;;;;OAIG;cACa,MAAM,CAAC,SAAS,EAAE,MAAM,GAAI,OAAO,CAAC,MAAM,CAAC;CAG9D"}
@@ -0,0 +1,73 @@
1
+ import { OAuthClientStorage } from '../storage';
2
+ import { OAuthClient } from '@crossauth/common';
3
+
4
+ /**
5
+ * Options for {@link OAuthClientManager}
6
+ */
7
+ export interface OAuthClientManagerOptions {
8
+ /** PBKDF2 HMAC for hashing client secret */
9
+ oauthPbkdf2Digest?: string;
10
+ /** PBKDF2 iterations for hashing client secret */
11
+ oauthPbkdf2Iterations?: number;
12
+ /** PBKDF2 key length for hashing client secret */
13
+ oauthPbkdf2KeyLength?: number;
14
+ clientStorage?: OAuthClientStorage;
15
+ }
16
+ /**
17
+ * Functionality for creating and updating clients, and validating
18
+ * redirect URIs.
19
+ */
20
+ export declare class OAuthClientManager {
21
+ private oauthPbkdf2Digest;
22
+ private oauthPbkdf2Iterations;
23
+ private oauthPbkdf2KeyLength;
24
+ private clientStorage;
25
+ /**
26
+ * Constructor
27
+ * @param options See {@link OAuthClientManagerOptions}
28
+ */
29
+ constructor(options?: OAuthClientManagerOptions);
30
+ /**
31
+ * Creates a client and puts it in the storage
32
+ * @param client_name friendly name for the client
33
+ * @param redirect_uri set of valid redirect URIs (may be empty)
34
+ * @param valid_flow set of OAuth flows this client is allowed to initiate
35
+ * (may be empty)
36
+ * @param confidential if true, client can keep secrets confidential
37
+ * and a client_secret will be created
38
+ * @param userid user id who owns the client, or undefined for no user
39
+ * @returns the new client. `client_id` and `client_secret` (plaintext)
40
+ * will be populated.
41
+ */
42
+ createClient(client_name: string, redirect_uri: string[], valid_flow?: string[], confidential?: boolean, userid?: string | number): Promise<OAuthClient>;
43
+ /**
44
+ * Updates a client
45
+ * @param client_id the client_id to update.
46
+ * @param client the fields to update. Anything not in here (or undefined)
47
+ * will remain unchanged
48
+ * @param resetSecret if true, generate a new client secret
49
+ * @returns the updated client. If it has a secret. it will be in
50
+ * `client_secret` as plaintext.
51
+ */
52
+ updateClient(client_id: string, client: Partial<OAuthClient>, resetSecret?: boolean): Promise<{
53
+ client: OAuthClient;
54
+ newSecret: boolean;
55
+ }>;
56
+ /**
57
+ * Create a random OAuth client id
58
+ */
59
+ static randomClientId(): string;
60
+ /**
61
+ * Create a random OAuth client secret
62
+ */
63
+ static randomClientSecret(): string;
64
+ /** If the passed redirect URI is not in the set of valid ones,
65
+ * throw {@link @crossauth/common!CrossauthError} with
66
+ * {@link @crossauth/common!CrossauthError} `BadRequest`.
67
+ * @param uri the redirect URI to validate
68
+ * @throws {@link @crossauth/common!CrossauthError} with
69
+ * {@link @crossauth/common!CrossauthError} `BadRequest`.
70
+ */
71
+ static validateUri(uri: string): void;
72
+ }
73
+ //# sourceMappingURL=clientmanager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clientmanager.d.ts","sourceRoot":"","sources":["../../src/oauth/clientmanager.ts"],"names":[],"mappings":"AACA,OAAO,EACH,kBAAkB,EACrB,MAAM,YAAY,CAAC;AAIpB,OAAO,KAAK,EACR,WAAW,EACd,MAAM,mBAAmB,CAAC;AAU3B;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACtC,4CAA4C;IAC5C,iBAAiB,CAAC,EAAG,MAAM,CAAC;IAE5B,kDAAkD;IAClD,qBAAqB,CAAC,EAAG,MAAM,CAAC;IAEhC,kDAAkD;IAClD,oBAAoB,CAAC,EAAG,MAAM,CAAC;IAE/B,aAAa,CAAC,EAAG,kBAAkB,CAAC;CACvC;AAED;;;GAGG;AACH,qBAAa,kBAAkB;IAC3B,OAAO,CAAC,iBAAiB,CAAY;IACrC,OAAO,CAAC,qBAAqB,CAAS;IACtC,OAAO,CAAC,oBAAoB,CAAM;IAClC,OAAO,CAAC,aAAa,CAAsB;IAE3C;;;OAGG;gBACS,OAAO,GAAE,yBAA8B;IAUnD;;;;;;;;;;;OAWG;IACG,YAAY,CAAC,WAAW,EAAE,MAAM,EAClC,YAAY,EAAE,MAAM,EAAE,EACtB,UAAU,CAAC,EAAE,MAAM,EAAE,EACrB,YAAY,UAAO,EACnB,MAAM,CAAC,EAAG,MAAM,GAAC,MAAM,GAAI,OAAO,CAAC,WAAW,CAAC;IA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