@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,43 @@
1
+ import { OAuthTokenConsumer } from './tokenconsumer';
2
+
3
+ /**
4
+ * Options for {@link OAuthResourceServer}
5
+ */
6
+ export interface OAuthResourceServerOptions {
7
+ }
8
+ /**
9
+ * An OAuth resource server
10
+ *
11
+ * The purpose of this class is for validating access tokens
12
+ */
13
+ export declare class OAuthResourceServer {
14
+ /** The token consumer that validates the access tokens. Required */
15
+ tokenConsumers: {
16
+ [key: string]: OAuthTokenConsumer;
17
+ };
18
+ /**
19
+ * Constructor
20
+ * @param tokenConsumers one or more consumers that will process
21
+ * the access tokens
22
+ * @param _options See {@link OAuthResourceServerOptions}. Unused
23
+ * at present
24
+ */
25
+ constructor(tokenConsumers: OAuthTokenConsumer[], _options?: OAuthResourceServerOptions);
26
+ /**
27
+ * Returns a token payload if the access token has a valid signature
28
+ * and the `type` claim in the payload is `access`, undefined otherwise.
29
+ *
30
+ * The `aud` token also has to match the `resourceServerName` value
31
+ * passed to the constructor.
32
+ *
33
+ * Doesn't throw exceptions.
34
+ *
35
+ * @param accessToken the access token JWT to validate
36
+ * @returns The JWT payload as an object or undefinedf if the JWT is
37
+ * invalid
38
+ */
39
+ accessTokenAuthorized(accessToken: string): Promise<{
40
+ [key: string]: any;
41
+ } | undefined>;
42
+ }
43
+ //# sourceMappingURL=resserver.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resserver.d.ts","sourceRoot":"","sources":["../../src/oauth/resserver.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAGrD;;GAEG;AACH,MAAM,WAAW,0BAA0B;CAC1C;AAED;;;;GAIG;AACH,qBAAa,mBAAmB;IAE5B,qEAAqE;IACrE,cAAc,EAAG;QAAC,CAAC,GAAG,EAAC,MAAM,GAAI,kBAAkB,CAAA;KAAC,CAAM;IAE1D;;;;;;OAMG;gBACS,cAAc,EAAG,kBAAkB,EAAE,EAAE,QAAQ,GAAG,0BAA+B;IAQ7F;;;;;;;;;;;;OAYG;IACG,qBAAqB,CAAC,WAAW,EAAE,MAAM,GACzC,OAAO,CAAC;QAAC,CAAC,GAAG,EAAC,MAAM,GAAG,GAAG,CAAA;KAAC,GAAC,SAAS,CAAC;CAY/C"}
@@ -0,0 +1,58 @@
1
+ import { OAuthAuthorizationServer } from '../authserver';
2
+ import { InMemoryKeyStorage } from '../../storage/inmemorystorage';
3
+ import { OAuthClientStorage } from '../../storage';
4
+ import { OAuthClient } from '@crossauth/common';
5
+
6
+ export declare function createClient(secretRequired?: boolean): Promise<{
7
+ clientStorage: OAuthClientStorage;
8
+ client: OAuthClient;
9
+ }>;
10
+ export declare function getAuthServer({ aud, persistAccessToken, emptyScopeIsValid, secretRequired, rollingRefreshToken, idTokenClaims, }?: {
11
+ challenge?: boolean;
12
+ aud?: string;
13
+ persistAccessToken?: boolean;
14
+ emptyScopeIsValid?: boolean;
15
+ secretRequired?: boolean;
16
+ rollingRefreshToken?: boolean;
17
+ idTokenClaims?: {
18
+ scope?: string | string[] | {
19
+ [key: string]: string;
20
+ };
21
+ };
22
+ }): Promise<{
23
+ client: OAuthClient;
24
+ clientStorage: OAuthClientStorage;
25
+ authServer: OAuthAuthorizationServer;
26
+ keyStorage: InMemoryKeyStorage;
27
+ userStorage: import('../..').InMemoryUserStorage;
28
+ }>;
29
+ export declare function getAuthorizationCode({ challenge, aud, persistAccessToken, rollingRefreshToken, scopes, idTokenClaims, }?: {
30
+ challenge?: boolean;
31
+ aud?: string;
32
+ persistAccessToken?: boolean;
33
+ rollingRefreshToken?: boolean;
34
+ scopes?: string;
35
+ idTokenClaims?: {
36
+ [key: string]: string[] | {
37
+ [key: string]: string;
38
+ };
39
+ };
40
+ }): Promise<{
41
+ code: string | undefined;
42
+ client: OAuthClient;
43
+ clientStorage: OAuthClientStorage;
44
+ authServer: OAuthAuthorizationServer;
45
+ keyStorage: InMemoryKeyStorage;
46
+ }>;
47
+ export declare function getAccessToken(): Promise<{
48
+ authServer: OAuthAuthorizationServer;
49
+ client: OAuthClient;
50
+ code: string | undefined;
51
+ clientStorage: OAuthClientStorage;
52
+ access_token: string | undefined;
53
+ error: string | undefined;
54
+ error_description: string | undefined;
55
+ refresh_token: string | undefined;
56
+ expires_in: number | undefined;
57
+ }>;
58
+ //# sourceMappingURL=common.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../../src/oauth/tests/common.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,wBAAwB,EAAwC,MAAM,eAAe,CAAC;AAC/F,OAAO,EAA8B,kBAAkB,EAAqC,MAAM,+BAA+B,CAAC;AAClI,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAEnD,OAAO,EAAE,WAAW,EAAc,MAAM,mBAAmB,CAAC;AAK5D,wBAAsB,YAAY,CAAC,cAAc,UAAO,GAAI,OAAO,CAAC;IAAC,aAAa,EAAG,kBAAkB,CAAC;IAAC,MAAM,EAAG,WAAW,CAAA;CAAC,CAAC,CAkB9H;AAED,wBAAsB,aAAa,CAAC,EAChC,GAAG,EACH,kBAAkB,EAClB,iBAAiB,EACjB,cAAc,EACd,mBAAmB,EACnB,aAAa,GACZ,GAAG;IACJ,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,kBAAkB,CAAC,EAAG,OAAO,CAAC;IAC9B,iBAAiB,CAAC,EAAG,OAAO,CAAC;IAC7B,cAAc,CAAC,EAAG,OAAO,CAAC;IAC1B,mBAAmB,CAAC,EAAG,OAAO,CAAC;IAC/B,aAAa,CAAC,EAAI;QAAC,KAAK,CAAC,EAAG,MAAM,GAAC,MAAM,EAAE,GAAC;YAAC,CAAC,GAAG,EAAC,MAAM,GAAE,MAAM,CAAA;SAAC,CAAA;KAAC,CAAC;CACjE;;;;;;GAkCL;AAED,wBAAsB,oBAAoB,CAAC,EACvC,SAAS,EACT,GAAG,EACH,kBAAkB,EAClB,mBAAmB,EACnB,MAAqB,EACrB,aAAa,GAChB,GAAG;IAAC,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,kBAAkB,CAAC,EAAG,OAAO,CAAC;IAC9B,mBAAmB,CAAC,EAAG,OAAO,CAAC;IAC/B,MAAM,CAAC,EAAG,MAAM,CAAC;IACjB,aAAa,CAAC,EAAI;QAAC,CAAC,GAAG,EAAC,MAAM,GAAI,MAAM,EAAE,GAAC;YAAC,CAAC,GAAG,EAAC,MAAM,GAAE,MAAM,CAAA;SAAC,CAAA;KAAC,CAAC;CAC7D;;;;;;GAgCT;AAED,wBAAsB,cAAc;;;;;;;;;;GAUnC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=oauthauthserver_authzcode.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oauthauthserver_authzcode.test.d.ts","sourceRoot":"","sources":["../../../src/oauth/tests/oauthauthserver_authzcode.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=oauthauthserver_clientcred.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oauthauthserver_clientcred.test.d.ts","sourceRoot":"","sources":["../../../src/oauth/tests/oauthauthserver_clientcred.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=oauthauthserver_device.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oauthauthserver_device.test.d.ts","sourceRoot":"","sources":["../../../src/oauth/tests/oauthauthserver_device.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,5 @@
1
+ export declare var emailTokenData: {
2
+ to: string;
3
+ otp: string;
4
+ };
5
+ //# sourceMappingURL=oauthauthserver_mfa.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oauthauthserver_mfa.test.d.ts","sourceRoot":"","sources":["../../../src/oauth/tests/oauthauthserver_mfa.test.ts"],"names":[],"mappings":"AAkBA,eAAO,IAAI,cAAc,EAAI;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,GAAG,EAAG,MAAM,CAAA;CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=oauthauthserver_password.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oauthauthserver_password.test.d.ts","sourceRoot":"","sources":["../../../src/oauth/tests/oauthauthserver_password.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=oauthclient.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oauthclient.test.d.ts","sourceRoot":"","sources":["../../../src/oauth/tests/oauthclient.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=oauthresserver.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oauthresserver.test.d.ts","sourceRoot":"","sources":["../../../src/oauth/tests/oauthresserver.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,80 @@
1
+ import { KeyStorage } from '../storage';
2
+ import { OAuthTokenConsumerBase, OAuthTokenConsumerBaseOptions } from '@crossauth/common';
3
+
4
+ /**
5
+ * Options for {@link OAuthTokenConsumer}
6
+ */
7
+ export interface OAuthTokenConsumerOptions extends OAuthTokenConsumerBaseOptions {
8
+ /** Whether to persist access tokens in key storage. Default false.
9
+ *
10
+ * If you set this to true, you must also set `keyStorage`.
11
+ */
12
+ persistAccessToken?: boolean;
13
+ /** If persisting tokens, you need to provide a storage to persist them to */
14
+ keyStorage?: KeyStorage;
15
+ /** Filename with secret key if using a symmetric cipher for signing the
16
+ * JWT. Either this or `jwtSecretKey` is required when using this kind
17
+ * of cipher */
18
+ jwtSecretKeyFile?: string;
19
+ /** Filename for the public key if using a public key cipher for signing the
20
+ * JWT. Either this or `jwtPublicKey` is required when using this kind of
21
+ * cipher. privateKey or privateKeyFile is also required. */
22
+ jwtPublicKeyFile?: string;
23
+ /**
24
+ * The aud claim needs to match this value.
25
+ * No default (required)
26
+ */
27
+ audience?: string;
28
+ }
29
+ /**
30
+ * This class validates access tokens.
31
+ *
32
+ * It is separated into its own class as the functionality is used in both
33
+ * the OAuth resource server and OAuth client
34
+ */
35
+ export declare class OAuthTokenConsumer extends OAuthTokenConsumerBase {
36
+ /**
37
+ * Value passed to the constructor. The `aud` claim must match it
38
+ */
39
+ protected readonly audience: string;
40
+ /**
41
+ * Value passed to the constructor. If true, access tokens are saved
42
+ * in storage,
43
+ */
44
+ protected readonly persistAccessToken = false;
45
+ private keyStorage?;
46
+ private jwtSecretKeyFile;
47
+ private jwtPublicKeyFile;
48
+ /**
49
+ * Constructor
50
+ *
51
+ * @param options see {@link OAuthTokenConsumerOptions}
52
+ */
53
+ constructor(options?: OAuthTokenConsumerOptions);
54
+ /**
55
+ * Uses {@link Crypto.hash} to hash the given string.
56
+ *
57
+ * @param plaintext the string to hash
58
+ * @returns Base64-url-encoded hash
59
+ */
60
+ hash(plaintext: string): Promise<string>;
61
+ /**
62
+ * If the given token is valid, the paylaod is returned. Otherwise
63
+ * undefined is returned.
64
+ *
65
+ * The signature must be valid, the expiry must not have passed and,
66
+ * if `tokenType` is defined,. the `type` claim in the payload must
67
+ * match it.
68
+ *
69
+ * Doesn't throw exceptions.
70
+ *
71
+ * @param token The token to validate
72
+ * @param tokenType If defined, the `type` claim in the payload must
73
+ * match this value
74
+ * @returns
75
+ */
76
+ tokenAuthorized(token: string, tokenType: "access" | "refresh" | "id"): Promise<{
77
+ [key: string]: any;
78
+ } | undefined>;
79
+ }
80
+ //# sourceMappingURL=tokenconsumer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tokenconsumer.d.ts","sourceRoot":"","sources":["../../src/oauth/tokenconsumer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAMxC,OAAO,EACH,sBAAsB,EACtB,KAAK,6BAA6B,EAAE,MAAM,mBAAmB,CAAC;AAElE;;GAEG;AACH,MAAM,WAAW,yBACb,SAAQ,6BAA6B;IAErC;;;OAGG;IACH,kBAAkB,CAAC,EAAG,OAAO,CAAC;IAE9B,6EAA6E;IAC7E,UAAU,CAAC,EAAG,UAAU,CAAC;IAEzB;;mBAEe;IACf,gBAAgB,CAAC,EAAG,MAAM,CAAC;IAE3B;;iEAE6D;IAC7D,gBAAgB,CAAC,EAAG,MAAM,CAAC;IAE3B;;;OAGG;IACH,QAAQ,CAAC,EAAG,MAAM,CAAC;CACtB;AAED;;;;;GAKG;AACH,qBAAa,kBAAmB,SAAQ,sBAAsB;IAE1D;;OAEG;IACH,SAAS,CAAC,QAAQ,CAAC,QAAQ,EAAG,MAAM,CAAC;IAErC;;;OAGG;IACH,SAAS,CAAC,QAAQ,CAAC,kBAAkB,SAAS;IAE9C,OAAO,CAAC,UAAU,CAAC,CAAc;IACjC,OAAO,CAAC,gBAAgB,CAAM;IAC9B,OAAO,CAAC,gBAAgB,CAAM;IAE9B;;;;OAIG;gBACS,OAAO,GAAG,yBAA8B;IAiDpD;;;;;OAKG;IACG,IAAI,CAAC,SAAS,EAAG,MAAM,GAAI,OAAO,CAAC,MAAM,CAAC;IAIhD;;;;;;;;;;;;;;OAcG;IACG,eAAe,CAAC,KAAK,EAAE,MAAM,EAC/B,SAAS,EAAE,QAAQ,GAAG,SAAS,GAAG,IAAI,GACtC,OAAO,CAAC;QAAC,CAAC,GAAG,EAAC,MAAM,GAAG,GAAG,CAAA;KAAC,GAAC,SAAS,CAAC;CAwB7C"}