@etohq/auth-emailpass 1.0.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 ADDED
File without changes
@@ -0,0 +1,3 @@
1
+ declare const _default: import("@etohq/types").ModuleProviderExports;
2
+ export default _default;
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAKA,wBAEE"}
package/dist/index.js ADDED
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const utils_1 = require("@etohq/framework/utils");
4
+ const emailpass_1 = require("./services/emailpass");
5
+ const services = [emailpass_1.EmailPassAuthService];
6
+ exports.default = (0, utils_1.ModuleProvider)(utils_1.Modules.AUTH, {
7
+ services,
8
+ });
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAAA,kDAAgE;AAChE,oDAA2D;AAE3D,MAAM,QAAQ,GAAG,CAAC,gCAAoB,CAAC,CAAA;AAEvC,kBAAe,IAAA,sBAAc,EAAC,eAAO,CAAC,IAAI,EAAE;IAC1C,QAAQ;CACT,CAAC,CAAA"}
@@ -0,0 +1,40 @@
1
+ import { AuthenticationInput, AuthenticationResponse, AuthIdentityProviderService, EmailPassAuthProviderOptions, Logger } from "@etohq/framework/types";
2
+ import { AbstractAuthModuleProvider } from "@etohq/framework/utils";
3
+ type InjectedDependencies = {
4
+ logger: Logger;
5
+ };
6
+ interface LocalServiceConfig extends EmailPassAuthProviderOptions {
7
+ }
8
+ export declare class EmailPassAuthService extends AbstractAuthModuleProvider {
9
+ static identifier: string;
10
+ static DISPLAY_NAME: string;
11
+ protected config_: LocalServiceConfig;
12
+ protected logger_: Logger;
13
+ constructor({ logger }: InjectedDependencies, options: EmailPassAuthProviderOptions);
14
+ protected hashPassword(password: string): Promise<string>;
15
+ update(data: {
16
+ password: string;
17
+ entity_id: string;
18
+ }, authIdentityService: AuthIdentityProviderService): Promise<{
19
+ success: boolean;
20
+ error?: undefined;
21
+ authIdentity?: undefined;
22
+ } | {
23
+ success: boolean;
24
+ error: any;
25
+ authIdentity?: undefined;
26
+ } | {
27
+ success: boolean;
28
+ authIdentity: any;
29
+ error?: undefined;
30
+ }>;
31
+ protected createAuthIdentity({ email, password, authIdentityService }: {
32
+ email: any;
33
+ password: any;
34
+ authIdentityService: any;
35
+ }): Promise<any>;
36
+ authenticate(userData: AuthenticationInput, authIdentityService: AuthIdentityProviderService): Promise<AuthenticationResponse>;
37
+ register(userData: AuthenticationInput, authIdentityService: AuthIdentityProviderService): Promise<AuthenticationResponse>;
38
+ }
39
+ export {};
40
+ //# sourceMappingURL=emailpass.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"emailpass.d.ts","sourceRoot":"","sources":["../../src/services/emailpass.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,sBAAsB,EAEtB,2BAA2B,EAC3B,4BAA4B,EAC5B,MAAM,EACP,MAAM,wBAAwB,CAAA;AAC/B,OAAO,EACL,0BAA0B,EAG3B,MAAM,wBAAwB,CAAA;AAG/B,KAAK,oBAAoB,GAAG;IAC1B,MAAM,EAAE,MAAM,CAAA;CACf,CAAA;AAED,UAAU,kBAAmB,SAAQ,4BAA4B;CAAG;AAEpE,qBAAa,oBAAqB,SAAQ,0BAA0B;IAClE,MAAM,CAAC,UAAU,SAAc;IAC/B,MAAM,CAAC,YAAY,SAAkC;IAErD,SAAS,CAAC,OAAO,EAAE,kBAAkB,CAAA;IACrC,SAAS,CAAC,OAAO,EAAE,MAAM,CAAA;gBAGvB,EAAE,MAAM,EAAE,EAAE,oBAAoB,EAChC,OAAO,EAAE,4BAA4B;cAQvB,YAAY,CAAC,QAAQ,EAAE,MAAM;IAMvC,MAAM,CACV,IAAI,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,EAC7C,mBAAmB,EAAE,2BAA2B;;;;;;;;;;;;;cAmClC,kBAAkB,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,mBAAmB,EAAE;;;;KAAA;IAmBrE,YAAY,CAChB,QAAQ,EAAE,mBAAmB,EAC7B,mBAAmB,EAAE,2BAA2B,GAC/C,OAAO,CAAC,sBAAsB,CAAC;IA+D5B,QAAQ,CACZ,QAAQ,EAAE,mBAAmB,EAC7B,mBAAmB,EAAE,2BAA2B,GAC/C,OAAO,CAAC,sBAAsB,CAAC;CA2CnC"}
@@ -0,0 +1,153 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.EmailPassAuthService = void 0;
7
+ const utils_1 = require("@etohq/framework/utils");
8
+ const scrypt_kdf_1 = __importDefault(require("scrypt-kdf"));
9
+ class EmailPassAuthService extends utils_1.AbstractAuthModuleProvider {
10
+ constructor({ logger }, options) {
11
+ // @ts-ignore
12
+ super(...arguments);
13
+ this.config_ = options;
14
+ this.logger_ = logger;
15
+ }
16
+ async hashPassword(password) {
17
+ const hashConfig = this.config_.hashConfig ?? { logN: 15, r: 8, p: 1 };
18
+ const passwordHash = await scrypt_kdf_1.default.kdf(password, hashConfig);
19
+ return passwordHash.toString("base64");
20
+ }
21
+ async update(data, authIdentityService) {
22
+ const { password, entity_id } = data ?? {};
23
+ if (!entity_id) {
24
+ return {
25
+ success: false,
26
+ error: `Cannot update ${this.provider} provider identity without entity_id`,
27
+ };
28
+ }
29
+ if (!password || !(0, utils_1.isString)(password)) {
30
+ return { success: true };
31
+ }
32
+ let authIdentity;
33
+ try {
34
+ const passwordHash = await this.hashPassword(password);
35
+ authIdentity = await authIdentityService.update(entity_id, {
36
+ provider_metadata: {
37
+ password: passwordHash,
38
+ },
39
+ });
40
+ }
41
+ catch (error) {
42
+ return { success: false, error: error.message };
43
+ }
44
+ return {
45
+ success: true,
46
+ authIdentity,
47
+ };
48
+ }
49
+ async createAuthIdentity({ email, password, authIdentityService }) {
50
+ const passwordHash = await this.hashPassword(password);
51
+ const createdAuthIdentity = await authIdentityService.create({
52
+ entity_id: email,
53
+ provider_metadata: {
54
+ password: passwordHash,
55
+ },
56
+ });
57
+ const copy = JSON.parse(JSON.stringify(createdAuthIdentity));
58
+ const providerIdentity = copy.provider_identities?.find((pi) => pi.provider === this.provider);
59
+ delete providerIdentity.provider_metadata?.password;
60
+ return copy;
61
+ }
62
+ async authenticate(userData, authIdentityService) {
63
+ const { email, password } = userData.body ?? {};
64
+ if (!password || !(0, utils_1.isString)(password)) {
65
+ return {
66
+ success: false,
67
+ error: "Password should be a string",
68
+ };
69
+ }
70
+ if (!email || !(0, utils_1.isString)(email)) {
71
+ return {
72
+ success: false,
73
+ error: "Email should be a string",
74
+ };
75
+ }
76
+ let authIdentity;
77
+ try {
78
+ authIdentity = await authIdentityService.retrieve({
79
+ entity_id: email,
80
+ });
81
+ }
82
+ catch (error) {
83
+ if (error.type === utils_1.EtoError.Types.NOT_FOUND) {
84
+ return {
85
+ success: false,
86
+ error: "Invalid email or password",
87
+ };
88
+ }
89
+ return { success: false, error: error.message };
90
+ }
91
+ const providerIdentity = authIdentity.provider_identities?.find((pi) => pi.provider === this.provider);
92
+ const passwordHash = providerIdentity.provider_metadata?.password;
93
+ if ((0, utils_1.isString)(passwordHash)) {
94
+ const buf = Buffer.from(passwordHash, "base64");
95
+ const success = await scrypt_kdf_1.default.verify(buf, password);
96
+ if (success) {
97
+ const copy = JSON.parse(JSON.stringify(authIdentity));
98
+ const providerIdentity = copy.provider_identities?.find((pi) => pi.provider === this.provider);
99
+ delete providerIdentity.provider_metadata?.password;
100
+ return {
101
+ success,
102
+ authIdentity: copy,
103
+ };
104
+ }
105
+ }
106
+ return {
107
+ success: false,
108
+ error: "Invalid email or password",
109
+ };
110
+ }
111
+ async register(userData, authIdentityService) {
112
+ const { email, password } = userData.body ?? {};
113
+ if (!password || !(0, utils_1.isString)(password)) {
114
+ return {
115
+ success: false,
116
+ error: "Password should be a string",
117
+ };
118
+ }
119
+ if (!email || !(0, utils_1.isString)(email)) {
120
+ return {
121
+ success: false,
122
+ error: "Email should be a string",
123
+ };
124
+ }
125
+ try {
126
+ await authIdentityService.retrieve({
127
+ entity_id: email,
128
+ });
129
+ return {
130
+ success: false,
131
+ error: "Identity with email already exists",
132
+ };
133
+ }
134
+ catch (error) {
135
+ if (error.type === utils_1.EtoError.Types.NOT_FOUND) {
136
+ const createdAuthIdentity = await this.createAuthIdentity({
137
+ email,
138
+ password,
139
+ authIdentityService,
140
+ });
141
+ return {
142
+ success: true,
143
+ authIdentity: createdAuthIdentity,
144
+ };
145
+ }
146
+ return { success: false, error: error.message };
147
+ }
148
+ }
149
+ }
150
+ exports.EmailPassAuthService = EmailPassAuthService;
151
+ EmailPassAuthService.identifier = "emailpass";
152
+ EmailPassAuthService.DISPLAY_NAME = "Email/Password Authentication";
153
+ //# sourceMappingURL=emailpass.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"emailpass.js","sourceRoot":"","sources":["../../src/services/emailpass.ts"],"names":[],"mappings":";;;;;;AAQA,kDAI+B;AAC/B,4DAA+B;AAQ/B,MAAa,oBAAqB,SAAQ,kCAA0B;IAOlE,YACE,EAAE,MAAM,EAAwB,EAChC,OAAqC;QAErC,aAAa;QACb,KAAK,CAAC,GAAG,SAAS,CAAC,CAAA;QACnB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAA;IACvB,CAAC;IAES,KAAK,CAAC,YAAY,CAAC,QAAgB;QAC3C,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,IAAI,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE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;QAE/C,IAAI,CAAC,QAAQ,IAAI,CAAC,IAAA,gBAAQ,EAAC,QAAQ,CAAC,EAAE,CAAC;YACrC,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE,6BAA6B;aACrC,CAAA;QACH,CAAC;QAED,IAAI,CAAC,KAAK,IAAI,CAAC,IAAA,gBAAQ,EAAC,KAAK,CAAC,EAAE,CAAC;YAC/B,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE,0BAA0B;aAClC,CAAA;QACH,CAAC;QAED,IAAI,CAAC;YACH,MAAM,mBAAmB,CAAC,QAAQ,CAAC;gBACjC,SAAS,EAAE,KAAK;aACjB,CAAC,CAAA;YAEF,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE,oCAAoC;aAC5C,CAAA;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,KAAK,CAAC,IAAI,KAAK,gBAAQ,CAAC,KAAK,CAAC,SAAS,EAAE,CAAC;gBAC5C,MAAM,mBAAmB,GAAG,MAAM,IAAI,CAAC,kBAAkB,CAAC;oBACxD,KAAK;oBACL,QAAQ;oBACR,mBAAmB;iBACpB,CAAC,CAAA;gBAEF,OAAO;oBACL,OAAO,EAAE,IAAI;oBACb,YAAY,EAAE,mBAAmB;iBAClC,CAAA;YACH,CAAC;YAED,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,OAAO,EAAE,CAAA;QACjD,CAAC;IACH,CAAC;;AA9LH,oDA+LC;AA9LQ,+BAAU,GAAG,WAAW,CAAA;AACxB,iCAAY,GAAG,+BAA+B,CAAA"}
@@ -0,0 +1 @@
1
+ {"root":["../src/index.ts","../src/services/emailpass.ts"],"version":"5.6.2"}
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "@etohq/auth-emailpass",
3
+ "version": "1.0.0",
4
+ "description": "Email and password credential authentication provider for Eto",
5
+ "main": "dist/index.js",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/etohq/eto",
9
+ "directory": "packages/modules/providers/auth-emailpass"
10
+ },
11
+ "files": [
12
+ "dist",
13
+ "!dist/**/__tests__",
14
+ "!dist/**/__mocks__",
15
+ "!dist/**/__fixtures__"
16
+ ],
17
+ "engines": {
18
+ "node": ">=20"
19
+ },
20
+ "author": "Eto",
21
+ "license": "MIT",
22
+ "scripts": {
23
+ "test": "jest --passWithNoTests src",
24
+ "test:integration": "jest --forceExit -- integration-tests/**/__tests__/**/*.spec.ts",
25
+ "build": "rimraf dist && tsc --build",
26
+ "watch": "tsc --watch"
27
+ },
28
+ "devDependencies": {
29
+ "@etohq/framework": "^1.0.0",
30
+ "@swc/core": "^1.7.28",
31
+ "@swc/jest": "^0.2.36",
32
+ "@types/jest": "^29.5.14",
33
+ "jest": "^29.7.0",
34
+ "rimraf": "^5.0.2",
35
+ "typescript": "^5.6.2"
36
+ },
37
+ "dependencies": {
38
+ "scrypt-kdf": "^2.0.1"
39
+ },
40
+ "peerDependencies": {
41
+ "@etohq/framework": "^1.0.0"
42
+ },
43
+ "keywords": [
44
+ "eto-provider",
45
+ "eto-provider-auth-userpass"
46
+ ]
47
+ }