@fonoster/identity 0.7.22 → 0.7.25
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/dist/apikeys/createApiKey.d.ts +0 -1
- package/dist/apikeys/deleteApiKey.d.ts +0 -1
- package/dist/apikeys/deleteApiKey.js +1 -1
- package/dist/apikeys/listApiKeys.d.ts +0 -1
- package/dist/apikeys/regenerateApiKey.d.ts +0 -1
- package/dist/apikeys/regenerateApiKey.js +1 -1
- package/dist/constants.d.ts +2 -0
- package/dist/{invites/EmailTemplatesEnum.js → constants.js} +3 -6
- package/dist/envs.d.ts +7 -0
- package/dist/envs.js +24 -3
- package/dist/exchanges/exchangeApiKey.d.ts +0 -1
- package/dist/exchanges/exchangeCredentials.d.ts +0 -1
- package/dist/exchanges/exchangeCredentials.js +28 -3
- package/dist/exchanges/exchangeOauth2Code.d.ts +6 -0
- package/dist/exchanges/exchangeOauth2Code.js +95 -0
- package/dist/exchanges/exchangeRefreshToken.d.ts +0 -1
- package/dist/exchanges/exchangeRefreshToken.js +2 -2
- package/dist/exchanges/index.d.ts +1 -0
- package/dist/exchanges/index.js +1 -0
- package/dist/exchanges/payloads/users/getAccessTokenPayload.js +5 -4
- package/dist/exchanges/types.d.ts +11 -1
- package/dist/invites/createInviteBody.d.ts +2 -7
- package/dist/invites/createInviteBody.js +5 -5
- package/dist/invites/index.d.ts +2 -1
- package/dist/invites/index.js +2 -1
- package/dist/invites/sendInvite.d.ts +2 -9
- package/dist/invites/sendInvite.js +2 -1
- package/dist/invites/types.d.ts +11 -0
- package/dist/invites/types.js +2 -0
- package/dist/service.d.ts +9 -0
- package/dist/service.js +7 -1
- package/dist/templates/TemplatesEnum.d.ts +7 -0
- package/dist/templates/TemplatesEnum.js +28 -0
- package/dist/templates/verifyEmail.hbs +39 -0
- package/dist/templates/verifyPhone.hbs +3 -0
- package/dist/users/createUser.d.ts +0 -1
- package/dist/users/deleteUser.d.ts +0 -1
- package/dist/users/deleteUser.js +1 -1
- package/dist/users/getUser.d.ts +0 -1
- package/dist/users/getUser.js +1 -1
- package/dist/users/updateUser.d.ts +0 -1
- package/dist/users/upsertDefaultUser.js +14 -3
- package/dist/utils/createCallAccessToken.js +2 -2
- package/dist/utils/createGenerateVerificationCode.d.ts +7 -0
- package/dist/utils/createGenerateVerificationCode.js +28 -0
- package/dist/utils/createIsUserContactVerified.d.ts +3 -0
- package/dist/utils/createIsUserContactVerified.js +25 -0
- package/dist/utils/createIsValidVerificationCode.d.ts +8 -0
- package/dist/utils/createIsValidVerificationCode.js +34 -0
- package/dist/{workspaces → utils}/createSendEmail.js +1 -1
- package/dist/utils/createWorkspaceInviteToken.d.ts +8 -0
- package/dist/utils/createWorkspaceInviteToken.js +54 -0
- package/dist/utils/getApiKeyByAccessKeyId.d.ts +3 -3
- package/dist/utils/getUserByEmail.d.ts +4 -4
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.js +4 -2
- package/dist/utils/updateMembershipStatus.d.ts +3 -0
- package/dist/utils/updateMembershipStatus.js +51 -0
- package/dist/verification/createBodyForVerificationEmail.d.ts +3 -0
- package/dist/verification/createBodyForVerificationEmail.js +39 -0
- package/dist/verification/createBodyForVerificationMessage.d.ts +3 -0
- package/dist/verification/createBodyForVerificationMessage.js +39 -0
- package/dist/verification/createSendVerificationCode.d.ts +6 -0
- package/dist/verification/createSendVerificationCode.js +63 -0
- package/dist/verification/createVerifyCode.d.ts +5 -0
- package/dist/verification/createVerifyCode.js +67 -0
- package/dist/verification/index.d.ts +6 -0
- package/dist/verification/index.js +40 -0
- package/dist/verification/sendVerificationEmail.d.ts +4 -0
- package/dist/verification/sendVerificationEmail.js +26 -0
- package/dist/verification/sendVerificationMessage.d.ts +4 -0
- package/dist/verification/sendVerificationMessage.js +25 -0
- package/dist/verification/types.d.ts +23 -0
- package/dist/verification/types.js +8 -0
- package/dist/workspaces/createWorkspace.d.ts +0 -1
- package/dist/workspaces/deleteWorkspace.d.ts +0 -1
- package/dist/workspaces/deleteWorkspace.js +1 -1
- package/dist/workspaces/getWorkspace.d.ts +0 -1
- package/dist/workspaces/getWorkspace.js +1 -1
- package/dist/workspaces/inviteUserToWorkspace.d.ts +1 -2
- package/dist/workspaces/inviteUserToWorkspace.js +11 -5
- package/dist/workspaces/listWorkspaces.d.ts +0 -1
- package/dist/workspaces/removeUserFromWorkspace.d.ts +0 -1
- package/dist/workspaces/resendWorkspaceMembershipInvitation.d.ts +1 -2
- package/dist/workspaces/resendWorkspaceMembershipInvitation.js +10 -4
- package/dist/workspaces/updateWorkspace.d.ts +0 -1
- package/package.json +6 -5
- package/dist/invites/EmailTemplatesEnum.d.ts +0 -5
- /package/dist/{invites/templates → templates}/inviteExistingUser.hbs +0 -0
- /package/dist/{invites/templates → templates}/inviteNewUser.hbs +0 -0
- /package/dist/{workspaces → utils}/createSendEmail.d.ts +0 -0
|
@@ -43,5 +43,5 @@ function deleteApiKey(prisma) {
|
|
|
43
43
|
});
|
|
44
44
|
callback(null, { ref });
|
|
45
45
|
});
|
|
46
|
-
return (0, common_1.withErrorHandlingAndValidation)(fn, common_1.Validators.
|
|
46
|
+
return (0, common_1.withErrorHandlingAndValidation)(fn, common_1.Validators.emptySchema);
|
|
47
47
|
}
|
|
@@ -51,5 +51,5 @@ function regenerateApiKey(prisma) {
|
|
|
51
51
|
accessKeySecret: response.accessKeySecret
|
|
52
52
|
});
|
|
53
53
|
});
|
|
54
|
-
return (0, common_1.withErrorHandlingAndValidation)(fn, common_1.Validators.
|
|
54
|
+
return (0, common_1.withErrorHandlingAndValidation)(fn, common_1.Validators.emptySchema);
|
|
55
55
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.VERIFICATION_CODE_EXPIRATION = exports.SIGN_ALGORITHM = void 0;
|
|
4
4
|
/*
|
|
5
5
|
* Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
|
|
6
6
|
* http://github.com/fonoster/fonoster
|
|
@@ -19,8 +19,5 @@ exports.EmailTemplatesEnum = void 0;
|
|
|
19
19
|
* See the License for the specific language governing permissions and
|
|
20
20
|
* limitations under the License.
|
|
21
21
|
*/
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
EmailTemplatesEnum["INVITE_NEW_USER"] = "inviteNewUser";
|
|
25
|
-
EmailTemplatesEnum["INVITE_EXISTING_USER"] = "inviteExistingUser";
|
|
26
|
-
})(EmailTemplatesEnum || (exports.EmailTemplatesEnum = EmailTemplatesEnum = {}));
|
|
22
|
+
exports.SIGN_ALGORITHM = "RS256";
|
|
23
|
+
exports.VERIFICATION_CODE_EXPIRATION = 5 * 60 * 1000;
|
package/dist/envs.d.ts
CHANGED
|
@@ -1 +1,8 @@
|
|
|
1
1
|
export declare const CLOAK_ENCRYPTION_KEY: string;
|
|
2
|
+
export declare const IDENTITY_MFA_REQUIRED: boolean;
|
|
3
|
+
export declare const IDENTITY_OAUTH2_GITHUB_CLIENT_ID: string;
|
|
4
|
+
export declare const IDENTITY_OAUTH2_GITHUB_CLIENT_SECRET: string;
|
|
5
|
+
export declare const IDENTITY_OAUTH2_GITHUB_ENABLED: boolean;
|
|
6
|
+
export declare const IDENTITY_USER_VERIFICATION_REQUIRED: boolean;
|
|
7
|
+
export declare const IDENTITY_WORKSPACE_INVITATION_URL: string;
|
|
8
|
+
export declare const IDENTITY_WORKSPACE_INVITE_EXPIRATION: string;
|
package/dist/envs.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CLOAK_ENCRYPTION_KEY = void 0;
|
|
3
|
+
exports.IDENTITY_WORKSPACE_INVITE_EXPIRATION = exports.IDENTITY_WORKSPACE_INVITATION_URL = exports.IDENTITY_USER_VERIFICATION_REQUIRED = exports.IDENTITY_OAUTH2_GITHUB_ENABLED = exports.IDENTITY_OAUTH2_GITHUB_CLIENT_SECRET = exports.IDENTITY_OAUTH2_GITHUB_CLIENT_ID = exports.IDENTITY_MFA_REQUIRED = exports.CLOAK_ENCRYPTION_KEY = void 0;
|
|
4
4
|
/*
|
|
5
5
|
* Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
|
|
6
6
|
* http://github.com/fonoster/fonoster
|
|
@@ -20,5 +20,26 @@ exports.CLOAK_ENCRYPTION_KEY = void 0;
|
|
|
20
20
|
* limitations under the License.
|
|
21
21
|
*/
|
|
22
22
|
const common_1 = require("@fonoster/common");
|
|
23
|
-
|
|
24
|
-
exports.CLOAK_ENCRYPTION_KEY =
|
|
23
|
+
const e = process.env;
|
|
24
|
+
exports.CLOAK_ENCRYPTION_KEY = e.CLOAK_ENCRYPTION_KEY;
|
|
25
|
+
exports.IDENTITY_MFA_REQUIRED = e.IDENTITY_MFA_REQUIRED === "true";
|
|
26
|
+
exports.IDENTITY_OAUTH2_GITHUB_CLIENT_ID = e.IDENTITY_OAUTH2_GITHUB_CLIENT_ID;
|
|
27
|
+
exports.IDENTITY_OAUTH2_GITHUB_CLIENT_SECRET = e.IDENTITY_OAUTH2_GITHUB_CLIENT_SECRET;
|
|
28
|
+
exports.IDENTITY_OAUTH2_GITHUB_ENABLED = e.IDENTITY_OAUTH2_GITHUB_ENABLED === "true";
|
|
29
|
+
exports.IDENTITY_USER_VERIFICATION_REQUIRED = e.IDENTITY_USER_VERIFICATION_REQUIRED === "true";
|
|
30
|
+
exports.IDENTITY_WORKSPACE_INVITATION_URL = e.IDENTITY_WORKSPACE_INVITATION_URL;
|
|
31
|
+
exports.IDENTITY_WORKSPACE_INVITE_EXPIRATION = e.IDENTITY_WORKSPACE_INVITE_EXPIRATION || "1d";
|
|
32
|
+
(0, common_1.assertEnvsAreSet)(["CLOAK_ENCRYPTION_KEY", "IDENTITY_WORKSPACE_INVITATION_URL"]);
|
|
33
|
+
if (exports.IDENTITY_USER_VERIFICATION_REQUIRED) {
|
|
34
|
+
(0, common_1.assertEnvsAreSet)([
|
|
35
|
+
"TWILIO_ACCOUNT_SID",
|
|
36
|
+
"TWILIO_AUTH_TOKEN",
|
|
37
|
+
"TWILIO_PHONE_NUMBER"
|
|
38
|
+
]);
|
|
39
|
+
}
|
|
40
|
+
if (exports.IDENTITY_OAUTH2_GITHUB_ENABLED) {
|
|
41
|
+
(0, common_1.assertEnvsAreSet)([
|
|
42
|
+
"IDENTITY_OAUTH2_GITHUB_CLIENT_ID",
|
|
43
|
+
"IDENTITY_OAUTH2_GITHUB_CLIENT_SECRET"
|
|
44
|
+
]);
|
|
45
|
+
}
|
|
@@ -55,20 +55,45 @@ const common_1 = require("@fonoster/common");
|
|
|
55
55
|
const logger_1 = require("@fonoster/logger");
|
|
56
56
|
const grpc = __importStar(require("@grpc/grpc-js"));
|
|
57
57
|
const exchangeTokens_1 = require("./exchangeTokens");
|
|
58
|
+
const envs_1 = require("../envs");
|
|
59
|
+
const createIsValidVerificationCode_1 = require("../utils/createIsValidVerificationCode");
|
|
58
60
|
const getUserByEmail_1 = require("../utils/getUserByEmail");
|
|
61
|
+
const verification_1 = require("../verification");
|
|
59
62
|
const logger = (0, logger_1.getLogger)({ service: "identity", filePath: __filename });
|
|
63
|
+
const verificationRequiredButNotProvided = (user) => envs_1.IDENTITY_USER_VERIFICATION_REQUIRED &&
|
|
64
|
+
(!user.emailVerified || !user.phoneNumberVerified);
|
|
60
65
|
function exchangeCredentials(prisma, identityConfig) {
|
|
66
|
+
const isValidVerificationCode = (0, createIsValidVerificationCode_1.createIsValidVerificationCode)(prisma);
|
|
61
67
|
const fn = (call, callback) => __awaiter(this, void 0, void 0, function* () {
|
|
62
68
|
const { request } = call;
|
|
63
|
-
const { username, password } = request;
|
|
64
|
-
logger.verbose("call to exchangeCredentials", { username });
|
|
65
|
-
const user = yield (0, getUserByEmail_1.getUserByEmail)(prisma)(
|
|
69
|
+
const { username: email, password, verificationCode } = request;
|
|
70
|
+
logger.verbose("call to exchangeCredentials", { username: email });
|
|
71
|
+
const user = yield (0, getUserByEmail_1.getUserByEmail)(prisma)(email);
|
|
66
72
|
if (!user || user.password !== (password === null || password === void 0 ? void 0 : password.trim())) {
|
|
67
73
|
return callback({
|
|
68
74
|
code: grpc.status.PERMISSION_DENIED,
|
|
69
75
|
message: "Invalid credentials"
|
|
70
76
|
});
|
|
71
77
|
}
|
|
78
|
+
if (verificationRequiredButNotProvided(user)) {
|
|
79
|
+
return callback({
|
|
80
|
+
code: grpc.status.PERMISSION_DENIED,
|
|
81
|
+
message: "User contact information not verified"
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
if (envs_1.IDENTITY_USER_VERIFICATION_REQUIRED) {
|
|
85
|
+
const isValid = yield isValidVerificationCode({
|
|
86
|
+
type: verification_1.ContactType.EMAIL,
|
|
87
|
+
value: email,
|
|
88
|
+
code: verificationCode
|
|
89
|
+
});
|
|
90
|
+
if (!isValid) {
|
|
91
|
+
return callback({
|
|
92
|
+
code: grpc.status.PERMISSION_DENIED,
|
|
93
|
+
message: "Invalid verification code"
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
}
|
|
72
97
|
callback(null, yield (0, exchangeTokens_1.exchangeTokens)(prisma, identityConfig)(user.accessKeyId));
|
|
73
98
|
});
|
|
74
99
|
return (0, common_1.withErrorHandlingAndValidation)(fn, common_1.exchangeCredentialsRequestSchema);
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { IdentityConfig } from "./types";
|
|
2
|
+
import { Prisma } from "../db";
|
|
3
|
+
declare function exchangeOauth2Code(prisma: Prisma, identityConfig: IdentityConfig): (call: {
|
|
4
|
+
request: unknown;
|
|
5
|
+
}, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
|
|
6
|
+
export { exchangeOauth2Code };
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
+
exports.exchangeOauth2Code = exchangeOauth2Code;
|
|
36
|
+
/*
|
|
37
|
+
* Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
|
|
38
|
+
* http://github.com/fonoster/fonoster
|
|
39
|
+
*
|
|
40
|
+
* This file is part of Fonoster
|
|
41
|
+
*
|
|
42
|
+
* Licensed under the MIT License (the "License");
|
|
43
|
+
* you may not use this file except in compliance with
|
|
44
|
+
* the License. You may obtain a copy of the License at
|
|
45
|
+
*
|
|
46
|
+
* https://opensource.org/licenses/MIT
|
|
47
|
+
*
|
|
48
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
49
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
50
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
51
|
+
* See the License for the specific language governing permissions and
|
|
52
|
+
* limitations under the License.
|
|
53
|
+
*/
|
|
54
|
+
const common_1 = require("@fonoster/common");
|
|
55
|
+
const logger_1 = require("@fonoster/logger");
|
|
56
|
+
const grpc = __importStar(require("@grpc/grpc-js"));
|
|
57
|
+
const exchangeTokens_1 = require("./exchangeTokens");
|
|
58
|
+
const getUserByEmail_1 = require("../utils/getUserByEmail");
|
|
59
|
+
const logger = (0, logger_1.getLogger)({ service: "identity", filePath: __filename });
|
|
60
|
+
function exchangeOauth2Code(prisma, identityConfig) {
|
|
61
|
+
const fn = (call, callback) => __awaiter(this, void 0, void 0, function* () {
|
|
62
|
+
const { request } = call;
|
|
63
|
+
const { provider, username: email, code } = request;
|
|
64
|
+
logger.verbose("call to exchangeOauth2Code", { provider });
|
|
65
|
+
const tokenResponse = yield fetch("https://github.com/login/oauth/access_token", {
|
|
66
|
+
method: "POST",
|
|
67
|
+
headers: {
|
|
68
|
+
"Content-Type": "application/json",
|
|
69
|
+
Accept: "application/json"
|
|
70
|
+
},
|
|
71
|
+
body: JSON.stringify({
|
|
72
|
+
client_id: identityConfig.githubOauth2Config.clientId,
|
|
73
|
+
client_secret: identityConfig.githubOauth2Config.clientSecret,
|
|
74
|
+
code
|
|
75
|
+
})
|
|
76
|
+
});
|
|
77
|
+
const tokenData = yield tokenResponse.json();
|
|
78
|
+
const accessToken = tokenData === null || tokenData === void 0 ? void 0 : tokenData.access_token;
|
|
79
|
+
const userResponse = yield fetch("https://api.github.com/user", {
|
|
80
|
+
headers: {
|
|
81
|
+
Authorization: `token ${accessToken}`
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
const userData = yield userResponse.json();
|
|
85
|
+
const user = yield (0, getUserByEmail_1.getUserByEmail)(prisma)(email);
|
|
86
|
+
if (userData.email !== email || !user) {
|
|
87
|
+
return callback({
|
|
88
|
+
code: grpc.status.PERMISSION_DENIED,
|
|
89
|
+
message: "Invalid credentials"
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
callback(null, yield (0, exchangeTokens_1.exchangeTokens)(prisma, identityConfig)(user.accessKeyId));
|
|
93
|
+
});
|
|
94
|
+
return (0, common_1.withErrorHandlingAndValidation)(fn, common_1.exchangeOauth2RequestSchema);
|
|
95
|
+
}
|
|
@@ -35,15 +35,15 @@ const common_1 = require("@fonoster/common");
|
|
|
35
35
|
const logger_1 = require("@fonoster/logger");
|
|
36
36
|
const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
|
|
37
37
|
const exchangeTokens_1 = require("./exchangeTokens");
|
|
38
|
+
const constants_1 = require("../constants");
|
|
38
39
|
const logger = (0, logger_1.getLogger)({ service: "identity", filePath: __filename });
|
|
39
|
-
const SIGN_ALGORITHM = "RS256";
|
|
40
40
|
function exchangeRefreshToken(prisma, identityConfig) {
|
|
41
41
|
const fn = (call, callback) => __awaiter(this, void 0, void 0, function* () {
|
|
42
42
|
const { privateKey } = identityConfig;
|
|
43
43
|
const { request } = call;
|
|
44
44
|
const { refreshToken: oldRefreshToken } = request;
|
|
45
45
|
const oldRefreshTokenDecoded = jsonwebtoken_1.default.verify(oldRefreshToken, privateKey, {
|
|
46
|
-
algorithms: [SIGN_ALGORITHM]
|
|
46
|
+
algorithms: [constants_1.SIGN_ALGORITHM]
|
|
47
47
|
});
|
|
48
48
|
const { accessKeyId } = oldRefreshTokenDecoded;
|
|
49
49
|
logger.verbose("call to exchangeRefreshToken", { accessKeyId });
|
package/dist/exchanges/index.js
CHANGED
|
@@ -35,5 +35,6 @@ __exportStar(require("./TokenUseEnum"), exports);
|
|
|
35
35
|
*/
|
|
36
36
|
__exportStar(require("./exchangeApiKey"), exports);
|
|
37
37
|
__exportStar(require("./exchangeCredentials"), exports);
|
|
38
|
+
__exportStar(require("./exchangeOauth2Code"), exports);
|
|
38
39
|
__exportStar(require("./exchangeRefreshToken"), exports);
|
|
39
40
|
__exportStar(require("./types"), exports);
|
|
@@ -55,10 +55,11 @@ function getAccessTokenPayload(prisma, identityConfig) {
|
|
|
55
55
|
role: types_1.WorkspaceRoleEnum.OWNER
|
|
56
56
|
}));
|
|
57
57
|
memberships.forEach((membership) => {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
58
|
+
membership.status === types_1.WorkspaceMemberStatus.ACTIVE &&
|
|
59
|
+
access.push({
|
|
60
|
+
accessKeyId: membership.workspace.accessKeyId,
|
|
61
|
+
role: membership.role
|
|
62
|
+
});
|
|
62
63
|
});
|
|
63
64
|
return {
|
|
64
65
|
iss: issuer,
|
|
@@ -53,9 +53,19 @@ type IdentityConfig = {
|
|
|
53
53
|
pass: string;
|
|
54
54
|
};
|
|
55
55
|
};
|
|
56
|
+
twilioSmsConfig?: {
|
|
57
|
+
accountSid: string;
|
|
58
|
+
authToken: string;
|
|
59
|
+
sender: string;
|
|
60
|
+
};
|
|
61
|
+
githubOauth2Config?: {
|
|
62
|
+
clientId: string;
|
|
63
|
+
clientSecret: string;
|
|
64
|
+
};
|
|
56
65
|
};
|
|
57
66
|
type DecodedToken<T extends TokenUseEnum> = T extends TokenUseEnum.ID ? IdToken : T extends TokenUseEnum.ACCESS ? AccessToken : T extends TokenUseEnum.REFRESH ? TokenUseEnum : never;
|
|
58
67
|
type ExchangeApiKeysRequest = z.infer<typeof V.exchangeApiKeysRequestSchema>;
|
|
68
|
+
type ExchangeOauth2CodeRequest = z.infer<typeof V.exchangeOauth2RequestSchema>;
|
|
59
69
|
type ExchangeCredentialsRequest = z.infer<typeof V.exchangeCredentialsRequestSchema>;
|
|
60
70
|
type ExchangeResponse = {
|
|
61
71
|
idToken: string;
|
|
@@ -63,4 +73,4 @@ type ExchangeResponse = {
|
|
|
63
73
|
refreshToken: string;
|
|
64
74
|
};
|
|
65
75
|
type ExchangeRefreshTokenRequest = z.infer<typeof V.exchangeRefreshTokenRequestSchema>;
|
|
66
|
-
export { Access, AccessToken, DecodedToken, ExchangeApiKeysRequest, ExchangeCredentialsRequest, ExchangeRefreshTokenRequest, ExchangeResponse, IdToken, IdentityConfig, RefreshToken, Role };
|
|
76
|
+
export { Access, AccessToken, DecodedToken, ExchangeApiKeysRequest, ExchangeCredentialsRequest, ExchangeOauth2CodeRequest, ExchangeRefreshTokenRequest, ExchangeResponse, IdToken, IdentityConfig, RefreshToken, Role };
|
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
isExistingUser: boolean;
|
|
4
|
-
workspaceName: string;
|
|
5
|
-
oneTimePassword: string;
|
|
6
|
-
inviteUrl: string;
|
|
7
|
-
}): string;
|
|
1
|
+
import { InviteParams } from "./types";
|
|
2
|
+
declare function createInviteBody(params: Omit<InviteParams, "recipient">): string;
|
|
8
3
|
export { createInviteBody };
|
|
@@ -24,13 +24,13 @@ exports.createInviteBody = createInviteBody;
|
|
|
24
24
|
*/
|
|
25
25
|
const path_1 = __importDefault(require("path"));
|
|
26
26
|
const common_1 = require("@fonoster/common");
|
|
27
|
-
const
|
|
27
|
+
const TemplatesEnum_1 = require("../templates/TemplatesEnum");
|
|
28
28
|
function createInviteBody(params) {
|
|
29
|
-
const { emailTemplateDir, isExistingUser, workspaceName, oneTimePassword, inviteUrl } = params;
|
|
29
|
+
const { templateDir: emailTemplateDir, isExistingUser, workspaceName, oneTimePassword, inviteUrl } = params;
|
|
30
30
|
const template = isExistingUser
|
|
31
|
-
?
|
|
32
|
-
:
|
|
33
|
-
const templateDir = emailTemplateDir || path_1.default.join(__dirname, "templates");
|
|
31
|
+
? TemplatesEnum_1.TemplatesEnum.INVITE_EXISTING_USER
|
|
32
|
+
: TemplatesEnum_1.TemplatesEnum.INVITE_NEW_USER;
|
|
33
|
+
const templateDir = emailTemplateDir || path_1.default.join(__dirname, "..", "templates");
|
|
34
34
|
const templatePath = `${templateDir}/${template}.hbs`;
|
|
35
35
|
return (0, common_1.compileTemplate)({
|
|
36
36
|
filePath: templatePath,
|
package/dist/invites/index.d.ts
CHANGED
package/dist/invites/index.js
CHANGED
|
@@ -14,7 +14,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./EmailTemplatesEnum"), exports);
|
|
18
17
|
/*
|
|
19
18
|
* Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
|
|
20
19
|
* http://github.com/fonoster/fonoster
|
|
@@ -33,5 +32,7 @@ __exportStar(require("./EmailTemplatesEnum"), exports);
|
|
|
33
32
|
* See the License for the specific language governing permissions and
|
|
34
33
|
* limitations under the License.
|
|
35
34
|
*/
|
|
35
|
+
__exportStar(require("../templates/TemplatesEnum"), exports);
|
|
36
36
|
__exportStar(require("./createInviteBody"), exports);
|
|
37
37
|
__exportStar(require("./sendInvite"), exports);
|
|
38
|
+
__exportStar(require("./types"), exports);
|
|
@@ -1,11 +1,4 @@
|
|
|
1
1
|
import { EmailParams } from "@fonoster/common";
|
|
2
|
-
|
|
3
|
-
recipient: string;
|
|
4
|
-
inviteUrl: string;
|
|
5
|
-
oneTimePassword?: string;
|
|
6
|
-
workspaceName: string;
|
|
7
|
-
isExistingUser: boolean;
|
|
8
|
-
};
|
|
9
|
-
type SendInvite = (sendEmail: (params: EmailParams) => Promise<void>, request: InviteParams) => Promise<void>;
|
|
2
|
+
import { InviteParams } from "./types";
|
|
10
3
|
declare function sendInvite(sendEmail: (params: EmailParams) => Promise<void>, request: InviteParams): Promise<void>;
|
|
11
|
-
export {
|
|
4
|
+
export { sendInvite };
|
|
@@ -13,11 +13,12 @@ exports.sendInvite = sendInvite;
|
|
|
13
13
|
const createInviteBody_1 = require("./createInviteBody");
|
|
14
14
|
function sendInvite(sendEmail, request) {
|
|
15
15
|
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
-
const { recipient, inviteUrl, oneTimePassword, isExistingUser, workspaceName } = request;
|
|
16
|
+
const { recipient, inviteUrl, oneTimePassword, isExistingUser, workspaceName, templateDir } = request;
|
|
17
17
|
yield sendEmail({
|
|
18
18
|
to: recipient,
|
|
19
19
|
subject: "Invite to join a Fonoster workspace",
|
|
20
20
|
html: (0, createInviteBody_1.createInviteBody)({
|
|
21
|
+
templateDir,
|
|
21
22
|
isExistingUser,
|
|
22
23
|
workspaceName,
|
|
23
24
|
oneTimePassword: isExistingUser ? undefined : oneTimePassword,
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { EmailParams } from "@fonoster/common";
|
|
2
|
+
type InviteParams = {
|
|
3
|
+
recipient: string;
|
|
4
|
+
templateDir?: string;
|
|
5
|
+
inviteUrl: string;
|
|
6
|
+
isExistingUser: boolean;
|
|
7
|
+
oneTimePassword?: string;
|
|
8
|
+
workspaceName: string;
|
|
9
|
+
};
|
|
10
|
+
type SendInvite = (sendEmail: (params: EmailParams) => Promise<void>, request: InviteParams) => Promise<void>;
|
|
11
|
+
export { InviteParams, SendInvite };
|
package/dist/service.d.ts
CHANGED
|
@@ -67,12 +67,21 @@ declare function buildIdentityService(identityConfig: IdentityConfig): {
|
|
|
67
67
|
exchangeCredentials: (call: {
|
|
68
68
|
request: unknown;
|
|
69
69
|
}, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
|
|
70
|
+
exchangeOauth2Code: (call: {
|
|
71
|
+
request: unknown;
|
|
72
|
+
}, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
|
|
70
73
|
exchangeRefreshToken: (call: {
|
|
71
74
|
request: unknown;
|
|
72
75
|
}, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
|
|
73
76
|
getPublicKey: (_: unknown, callback: (error: import("@fonoster/common").GrpcErrorMessage, response?: {
|
|
74
77
|
publicKey: string;
|
|
75
78
|
}) => void) => Promise<void>;
|
|
79
|
+
sendVerificationCode: (call: {
|
|
80
|
+
request: unknown;
|
|
81
|
+
}, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
|
|
82
|
+
verifyCode: (call: {
|
|
83
|
+
request: unknown;
|
|
84
|
+
}, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
|
|
76
85
|
};
|
|
77
86
|
};
|
|
78
87
|
export { buildIdentityService, serviceDefinitionParams };
|
package/dist/service.js
CHANGED
|
@@ -21,7 +21,9 @@ exports.buildIdentityService = buildIdentityService;
|
|
|
21
21
|
* limitations under the License.
|
|
22
22
|
*/
|
|
23
23
|
const db_1 = require("./db");
|
|
24
|
+
const exchangeOauth2Code_1 = require("./exchanges/exchangeOauth2Code");
|
|
24
25
|
const getPublicKey_1 = require("./getPublicKey");
|
|
26
|
+
const verification_1 = require("./verification");
|
|
25
27
|
const _1 = require(".");
|
|
26
28
|
const serviceDefinitionParams = {
|
|
27
29
|
serviceName: "Identity",
|
|
@@ -56,8 +58,12 @@ function buildIdentityService(identityConfig) {
|
|
|
56
58
|
// Exchanges
|
|
57
59
|
exchangeApiKey: (0, _1.exchangeApiKey)(db_1.prisma, identityConfig),
|
|
58
60
|
exchangeCredentials: (0, _1.exchangeCredentials)(db_1.prisma, identityConfig),
|
|
61
|
+
exchangeOauth2Code: (0, exchangeOauth2Code_1.exchangeOauth2Code)(db_1.prisma, identityConfig),
|
|
59
62
|
exchangeRefreshToken: (0, _1.exchangeRefreshToken)(db_1.prisma, identityConfig),
|
|
60
|
-
getPublicKey: (0, getPublicKey_1.getPublicKey)(identityConfig.publicKey)
|
|
63
|
+
getPublicKey: (0, getPublicKey_1.getPublicKey)(identityConfig.publicKey),
|
|
64
|
+
// Verification
|
|
65
|
+
sendVerificationCode: (0, verification_1.createSendVerificationCode)(db_1.prisma, identityConfig),
|
|
66
|
+
verifyCode: (0, verification_1.createVerifyCode)(db_1.prisma)
|
|
61
67
|
}
|
|
62
68
|
};
|
|
63
69
|
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TemplatesEnum = void 0;
|
|
4
|
+
/*
|
|
5
|
+
* Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
|
|
6
|
+
* http://github.com/fonoster/fonoster
|
|
7
|
+
*
|
|
8
|
+
* This file is part of Fonoster
|
|
9
|
+
*
|
|
10
|
+
* Licensed under the MIT License (the "License");
|
|
11
|
+
* you may not use this file except in compliance with
|
|
12
|
+
* the License. You may obtain a copy of the License at
|
|
13
|
+
*
|
|
14
|
+
* https://opensource.org/licenses/MIT
|
|
15
|
+
*
|
|
16
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
17
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
18
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
19
|
+
* See the License for the specific language governing permissions and
|
|
20
|
+
* limitations under the License.
|
|
21
|
+
*/
|
|
22
|
+
var TemplatesEnum;
|
|
23
|
+
(function (TemplatesEnum) {
|
|
24
|
+
TemplatesEnum["INVITE_NEW_USER"] = "inviteNewUser";
|
|
25
|
+
TemplatesEnum["INVITE_EXISTING_USER"] = "inviteExistingUser";
|
|
26
|
+
TemplatesEnum["VERIFY_EMAIL"] = "verifyEmail";
|
|
27
|
+
TemplatesEnum["VERIFY_PHONE"] = "verifyPhone";
|
|
28
|
+
})(TemplatesEnum || (exports.TemplatesEnum = TemplatesEnum = {}));
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<title>Verification Code</title>
|
|
5
|
+
<style>
|
|
6
|
+
body {
|
|
7
|
+
font-family: Arial, sans-serif;
|
|
8
|
+
background-color: #f4f4f4;
|
|
9
|
+
color: #333;
|
|
10
|
+
line-height: 1.6;
|
|
11
|
+
padding: 20px;
|
|
12
|
+
}
|
|
13
|
+
.container {
|
|
14
|
+
background: #fff;
|
|
15
|
+
padding: 20px;
|
|
16
|
+
}
|
|
17
|
+
.verification-code {
|
|
18
|
+
font-size: 1.5em;
|
|
19
|
+
font-weight: bold;
|
|
20
|
+
}
|
|
21
|
+
@media (prefers-color-scheme: dark) {
|
|
22
|
+
body {
|
|
23
|
+
background-color: #181818;
|
|
24
|
+
color: #f4f4f4;
|
|
25
|
+
}
|
|
26
|
+
.container {
|
|
27
|
+
background: #181818;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
</style>
|
|
31
|
+
</head>
|
|
32
|
+
<body>
|
|
33
|
+
<div class="container">
|
|
34
|
+
<p>To continue, please verify your account with the code below:</p>
|
|
35
|
+
<p class="verification-code">{{verificationCode}}</p>
|
|
36
|
+
<p>If you didn’t request this code, you can ignore this message.</p>
|
|
37
|
+
</div>
|
|
38
|
+
</body>
|
|
39
|
+
</html>
|
package/dist/users/deleteUser.js
CHANGED
|
@@ -48,5 +48,5 @@ function deleteUser(prisma) {
|
|
|
48
48
|
});
|
|
49
49
|
callback(null, { ref });
|
|
50
50
|
});
|
|
51
|
-
return (0, common_1.withErrorHandlingAndValidation)(fn, common_1.Validators.
|
|
51
|
+
return (0, common_1.withErrorHandlingAndValidation)(fn, common_1.Validators.emptySchema);
|
|
52
52
|
}
|
package/dist/users/getUser.d.ts
CHANGED
package/dist/users/getUser.js
CHANGED
|
@@ -59,5 +59,5 @@ function getUser(prisma) {
|
|
|
59
59
|
}
|
|
60
60
|
callback(null, (0, common_1.datesMapper)(user));
|
|
61
61
|
});
|
|
62
|
-
return (0, common_1.withErrorHandlingAndValidation)(fn, common_1.Validators.
|
|
62
|
+
return (0, common_1.withErrorHandlingAndValidation)(fn, common_1.Validators.emptySchema);
|
|
63
63
|
}
|