@fonoster/identity 0.8.24 → 0.8.26
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 → createCreateApiKey.d.ts} +2 -2
- package/dist/apikeys/{createApiKey.js → createCreateApiKey.js} +5 -6
- package/dist/apikeys/createDeleteApiKey.d.ts +6 -0
- package/dist/apikeys/{deleteApiKey.js → createDeleteApiKey.js} +4 -4
- package/dist/apikeys/createListApiKeys.d.ts +6 -0
- package/dist/apikeys/{listApiKeys.js → createListApiKeys.js} +5 -6
- package/dist/apikeys/createRegenerateApiKey.d.ts +6 -0
- package/dist/apikeys/{regenerateApiKey.js → createRegenerateApiKey.js} +4 -4
- package/dist/apikeys/index.d.ts +4 -4
- package/dist/apikeys/index.js +4 -4
- package/dist/exchanges/{exchangeRefreshToken.d.ts → createExchangeApiKey.d.ts} +2 -2
- package/dist/exchanges/{exchangeApiKey.js → createExchangeApiKey.js} +6 -6
- package/dist/exchanges/{exchangeOauth2Code.d.ts → createExchangeCredentials.d.ts} +2 -2
- package/dist/exchanges/{exchangeCredentials.js → createExchangeCredentials.js} +6 -6
- package/dist/exchanges/{exchangeCredentials.d.ts → createExchangeOauth2Code.d.ts} +2 -2
- package/dist/exchanges/{exchangeOauth2Code.js → createExchangeOauth2Code.js} +6 -6
- package/dist/exchanges/{exchangeApiKey.d.ts → createExchangeRefreshToken.d.ts} +2 -2
- package/dist/exchanges/{exchangeRefreshToken.js → createExchangeRefreshToken.js} +4 -4
- package/dist/exchanges/exchangeTokens.js +5 -5
- package/dist/exchanges/index.d.ts +4 -5
- package/dist/exchanges/index.js +4 -5
- package/dist/exchanges/payloads/apikeys/createGetAccessTokenPayload.d.ts +5 -0
- package/dist/exchanges/payloads/apikeys/createGetAccessTokenPayload.js +46 -0
- package/dist/exchanges/payloads/apikeys/createGetRefreshTokenPayload.d.ts +5 -0
- package/dist/exchanges/payloads/apikeys/{getRefreshTokenPayload.js → createGetRefreshTokenPayload.js} +18 -16
- package/dist/exchanges/payloads/apikeys/index.d.ts +2 -2
- package/dist/exchanges/payloads/apikeys/index.js +2 -2
- package/dist/exchanges/payloads/buildRefreshTokenPayload.d.ts +2 -1
- package/dist/exchanges/payloads/buildRefreshTokenPayload.js +2 -2
- package/dist/exchanges/payloads/users/createGetAccessTokenPayload.d.ts +5 -0
- package/dist/exchanges/payloads/users/createGetAccessTokenPayload.js +75 -0
- package/dist/exchanges/payloads/users/createGetIdTokenPayload.d.ts +5 -0
- package/dist/exchanges/payloads/users/createGetIdTokenPayload.js +40 -0
- package/dist/exchanges/payloads/users/createGetRefreshTokenPayload.d.ts +5 -0
- package/dist/exchanges/payloads/users/{getRefreshTokenPayload.js → createGetRefreshTokenPayload.js} +22 -20
- package/dist/exchanges/payloads/users/index.d.ts +3 -3
- package/dist/exchanges/payloads/users/index.js +3 -3
- package/dist/exchanges/types.d.ts +1 -36
- package/dist/getPublicKey.d.ts +2 -2
- package/dist/getPublicKey.js +8 -6
- package/dist/index.d.ts +0 -2
- package/dist/index.js +0 -2
- package/dist/service.js +22 -22
- package/dist/{apikeys/listApiKeys.d.ts → users/createCreateUser.d.ts} +2 -2
- package/dist/users/{createUser.js → createCreateUser.js} +4 -4
- package/dist/users/{createUser.d.ts → createDeleteUser.d.ts} +2 -2
- package/dist/users/{deleteUser.js → createDeleteUser.js} +5 -6
- package/dist/{apikeys/deleteApiKey.d.ts → users/createGetUser.d.ts} +2 -2
- package/dist/users/{getUser.js → createGetUser.js} +5 -6
- package/dist/{apikeys/regenerateApiKey.d.ts → users/createUpdateUser.d.ts} +2 -2
- package/dist/users/{updateUser.js → createUpdateUser.js} +5 -6
- package/dist/users/index.d.ts +4 -4
- package/dist/users/index.js +4 -4
- package/dist/utils/createGenerateCallAccessToken.d.ts +6 -0
- package/dist/utils/{createCallAccessToken.js → createGenerateCallAccessToken.js} +29 -28
- package/dist/utils/{createWorkspaceInviteToken.d.ts → createGenerateWorkspaceInviteToken.d.ts} +2 -2
- package/dist/utils/{createWorkspaceInviteToken.js → createGenerateWorkspaceInviteToken.js} +21 -19
- package/dist/utils/createGetAccessKeyIdFromEmail.d.ts +3 -0
- package/dist/utils/{getAccessKeyIdFromEmail.js → createGetAccessKeyIdFromEmail.js} +8 -6
- package/dist/utils/{getApiKeyByAccessKeyId.d.ts → createGetApiKeyByAccessKeyId.d.ts} +5 -5
- package/dist/utils/{getApiKeyByAccessKeyId.js → createGetApiKeyByAccessKeyId.js} +13 -11
- package/dist/utils/{getUserByEmail.d.ts → createGetUserByEmail.d.ts} +2 -2
- package/dist/utils/{getUserByEmail.js → createGetUserByEmail.js} +10 -8
- package/dist/utils/createUpdateMembershipStatus.d.ts +3 -0
- package/dist/utils/{updateMembershipStatus.js → createUpdateMembershipStatus.js} +18 -16
- package/dist/utils/getAccessKeyIdFromToken.js +3 -4
- package/dist/utils/getUserRefFromToken.js +3 -4
- package/dist/utils/hasAccessToResource.js +3 -4
- package/dist/utils/index.d.ts +2 -8
- package/dist/utils/index.js +2 -8
- package/dist/verification/createVerifyCode.js +2 -2
- package/dist/workspaces/createCreateWorkspace.d.ts +6 -0
- package/dist/workspaces/{createWorkspace.js → createCreateWorkspace.js} +5 -6
- package/dist/workspaces/createDeleteWorkspace.d.ts +6 -0
- package/dist/workspaces/{deleteWorkspace.js → createDeleteWorkspace.js} +5 -6
- package/dist/workspaces/createGetWorkspace.d.ts +6 -0
- package/dist/workspaces/{getWorkspace.js → createGetWorkspace.js} +5 -6
- package/dist/workspaces/{inviteUserToWorkspace.d.ts → createInviteUserToWorkspace.d.ts} +2 -2
- package/dist/workspaces/{inviteUserToWorkspace.js → createInviteUserToWorkspace.js} +26 -25
- package/dist/workspaces/createIsAdminMember.d.ts +3 -0
- package/dist/workspaces/{isAdminMember.js → createIsAdminMember.js} +21 -19
- package/dist/workspaces/createIsWorkspaceMember.d.ts +3 -0
- package/dist/workspaces/createIsWorkspaceMember.js +33 -0
- package/dist/workspaces/createListWorkspaces.d.ts +6 -0
- package/dist/workspaces/{listWorkspaces.js → createListWorkspaces.js} +6 -8
- package/dist/workspaces/createRemoveUserFromWorkspace.d.ts +6 -0
- package/dist/workspaces/{removeUserFromWorkspace.js → createRemoveUserFromWorkspace.js} +8 -10
- package/dist/workspaces/{resendWorkspaceMembershipInvitation.d.ts → createResendWorkspaceMembershipInvitation.d.ts} +2 -2
- package/dist/workspaces/{resendWorkspaceMembershipInvitation.js → createResendWorkspaceMembershipInvitation.js} +10 -11
- package/dist/workspaces/createUpdateWorkspace.d.ts +6 -0
- package/dist/workspaces/{updateWorkspace.js → createUpdateWorkspace.js} +7 -8
- package/dist/workspaces/index.d.ts +8 -8
- package/dist/workspaces/index.js +8 -8
- package/package.json +5 -5
- package/dist/JsonWebErrorEnum.d.ts +0 -5
- package/dist/JsonWebErrorEnum.js +0 -26
- package/dist/createAuthInterceptor.d.ts +0 -15
- package/dist/createAuthInterceptor.js +0 -74
- package/dist/errors.d.ts +0 -4
- package/dist/errors.js +0 -35
- package/dist/exchanges/TokenUseEnum.d.ts +0 -6
- package/dist/exchanges/TokenUseEnum.js +0 -27
- package/dist/exchanges/payloads/apikeys/getAccessTokenPayload.d.ts +0 -4
- package/dist/exchanges/payloads/apikeys/getAccessTokenPayload.js +0 -44
- package/dist/exchanges/payloads/apikeys/getRefreshTokenPayload.d.ts +0 -4
- package/dist/exchanges/payloads/users/getAccessTokenPayload.d.ts +0 -4
- package/dist/exchanges/payloads/users/getAccessTokenPayload.js +0 -73
- package/dist/exchanges/payloads/users/getIdTokenPayload.d.ts +0 -4
- package/dist/exchanges/payloads/users/getIdTokenPayload.js +0 -38
- package/dist/exchanges/payloads/users/getRefreshTokenPayload.d.ts +0 -4
- package/dist/getPublicKeyClient.d.ts +0 -5
- package/dist/getPublicKeyClient.js +0 -71
- package/dist/roles.d.ts +0 -5
- package/dist/roles.js +0 -129
- package/dist/users/deleteUser.d.ts +0 -6
- package/dist/users/getUser.d.ts +0 -6
- package/dist/users/updateUser.d.ts +0 -6
- package/dist/utils/createCallAccessToken.d.ts +0 -6
- package/dist/utils/decodeToken.d.ts +0 -4
- package/dist/utils/decodeToken.js +0 -25
- package/dist/utils/getAccessKeyIdFromCall.d.ts +0 -3
- package/dist/utils/getAccessKeyIdFromCall.js +0 -8
- package/dist/utils/getAccessKeyIdFromEmail.d.ts +0 -3
- package/dist/utils/getTokenFromCall.d.ts +0 -3
- package/dist/utils/getTokenFromCall.js +0 -8
- package/dist/utils/hasAccess.d.ts +0 -3
- package/dist/utils/hasAccess.js +0 -9
- package/dist/utils/isValidToken.d.ts +0 -2
- package/dist/utils/isValidToken.js +0 -51
- package/dist/utils/tokenHasAccessKeyId.d.ts +0 -2
- package/dist/utils/tokenHasAccessKeyId.js +0 -28
- package/dist/utils/updateMembershipStatus.d.ts +0 -3
- package/dist/workspaces/createWorkspace.d.ts +0 -6
- package/dist/workspaces/deleteWorkspace.d.ts +0 -6
- package/dist/workspaces/getWorkspace.d.ts +0 -6
- package/dist/workspaces/isAdminMember.d.ts +0 -3
- package/dist/workspaces/isWorkspaceMember.d.ts +0 -3
- package/dist/workspaces/isWorkspaceMember.js +0 -31
- package/dist/workspaces/listWorkspaces.d.ts +0 -6
- package/dist/workspaces/removeUserFromWorkspace.d.ts +0 -6
- package/dist/workspaces/updateWorkspace.d.ts +0 -6
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { GrpcErrorMessage } from "@fonoster/common";
|
|
2
2
|
import { CreateApiKeyRequest, CreateApiKeyResponse } from "@fonoster/types";
|
|
3
3
|
import { Prisma } from "../db";
|
|
4
|
-
declare function
|
|
4
|
+
declare function createCreateApiKey(prisma: Prisma): (call: {
|
|
5
5
|
request: unknown;
|
|
6
6
|
}, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
|
|
7
|
-
export { CreateApiKeyRequest, CreateApiKeyResponse,
|
|
7
|
+
export { CreateApiKeyRequest, CreateApiKeyResponse, createCreateApiKey };
|
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.
|
|
12
|
+
exports.createCreateApiKey = createCreateApiKey;
|
|
13
13
|
/*
|
|
14
14
|
* Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
|
|
15
15
|
* http://github.com/fonoster/fonoster
|
|
@@ -30,13 +30,12 @@ exports.createApiKey = createApiKey;
|
|
|
30
30
|
*/
|
|
31
31
|
const common_1 = require("@fonoster/common");
|
|
32
32
|
const logger_1 = require("@fonoster/logger");
|
|
33
|
-
const utils_1 = require("../utils");
|
|
34
33
|
const generateAccessKeyId_1 = require("../utils/generateAccessKeyId");
|
|
35
34
|
const generateAccessKeySecret_1 = require("../utils/generateAccessKeySecret");
|
|
36
35
|
const logger = (0, logger_1.getLogger)({ service: "identity", filePath: __filename });
|
|
37
|
-
function
|
|
38
|
-
const
|
|
39
|
-
const accessKeyId = (0,
|
|
36
|
+
function createCreateApiKey(prisma) {
|
|
37
|
+
const createApiKey = (call, callback) => __awaiter(this, void 0, void 0, function* () {
|
|
38
|
+
const accessKeyId = (0, common_1.getAccessKeyIdFromCall)(call);
|
|
40
39
|
const { request } = call;
|
|
41
40
|
const { role, expiresAt } = request;
|
|
42
41
|
logger.info("creating new ApiKey", { accessKeyId, role, expiresAt });
|
|
@@ -59,5 +58,5 @@ function createApiKey(prisma) {
|
|
|
59
58
|
accessKeySecret: response.accessKeySecret
|
|
60
59
|
});
|
|
61
60
|
});
|
|
62
|
-
return (0, common_1.withErrorHandlingAndValidation)(
|
|
61
|
+
return (0, common_1.withErrorHandlingAndValidation)(createApiKey, common_1.Validators.createApiKeyRequestSchema);
|
|
63
62
|
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { GrpcErrorMessage } from "@fonoster/common";
|
|
2
|
+
import { Prisma } from "../db";
|
|
3
|
+
declare function createDeleteApiKey(prisma: Prisma): (call: {
|
|
4
|
+
request: unknown;
|
|
5
|
+
}, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
|
|
6
|
+
export { createDeleteApiKey };
|
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.
|
|
12
|
+
exports.createDeleteApiKey = createDeleteApiKey;
|
|
13
13
|
/*
|
|
14
14
|
* Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
|
|
15
15
|
* http://github.com/fonoster/fonoster
|
|
@@ -31,8 +31,8 @@ exports.deleteApiKey = deleteApiKey;
|
|
|
31
31
|
const common_1 = require("@fonoster/common");
|
|
32
32
|
const logger_1 = require("@fonoster/logger");
|
|
33
33
|
const logger = (0, logger_1.getLogger)({ service: "identity", filePath: __filename });
|
|
34
|
-
function
|
|
35
|
-
const
|
|
34
|
+
function createDeleteApiKey(prisma) {
|
|
35
|
+
const deleteApiKey = (call, callback) => __awaiter(this, void 0, void 0, function* () {
|
|
36
36
|
const { request } = call;
|
|
37
37
|
const { ref } = request;
|
|
38
38
|
logger.info("deleting ApiKey", { ref });
|
|
@@ -43,5 +43,5 @@ function deleteApiKey(prisma) {
|
|
|
43
43
|
});
|
|
44
44
|
callback(null, { ref });
|
|
45
45
|
});
|
|
46
|
-
return (0, common_1.withErrorHandlingAndValidation)(
|
|
46
|
+
return (0, common_1.withErrorHandlingAndValidation)(deleteApiKey, common_1.Validators.emptySchema);
|
|
47
47
|
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { GrpcErrorMessage } from "@fonoster/common";
|
|
2
|
+
import { Prisma } from "../db";
|
|
3
|
+
declare function createListApiKeys(prisma: Prisma): (call: {
|
|
4
|
+
request: unknown;
|
|
5
|
+
}, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
|
|
6
|
+
export { createListApiKeys };
|
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.
|
|
12
|
+
exports.createListApiKeys = createListApiKeys;
|
|
13
13
|
/*
|
|
14
14
|
* Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
|
|
15
15
|
* http://github.com/fonoster/fonoster
|
|
@@ -30,13 +30,12 @@ exports.listApiKeys = listApiKeys;
|
|
|
30
30
|
*/
|
|
31
31
|
const common_1 = require("@fonoster/common");
|
|
32
32
|
const logger_1 = require("@fonoster/logger");
|
|
33
|
-
const utils_1 = require("../utils");
|
|
34
33
|
const logger = (0, logger_1.getLogger)({ service: "identity", filePath: __filename });
|
|
35
|
-
function
|
|
36
|
-
const
|
|
34
|
+
function createListApiKeys(prisma) {
|
|
35
|
+
const listApiKeys = (call, callback) => __awaiter(this, void 0, void 0, function* () {
|
|
37
36
|
var _a;
|
|
38
37
|
const { pageSize, pageToken } = call.request;
|
|
39
|
-
const accessKeyId = (0,
|
|
38
|
+
const accessKeyId = (0, common_1.getAccessKeyIdFromCall)(call);
|
|
40
39
|
logger.verbose("list keys for workspace", { accessKeyId });
|
|
41
40
|
const workspace = yield prisma.workspace.findUnique({
|
|
42
41
|
where: {
|
|
@@ -58,5 +57,5 @@ function listApiKeys(prisma) {
|
|
|
58
57
|
};
|
|
59
58
|
callback(null, response);
|
|
60
59
|
});
|
|
61
|
-
return (0, common_1.withErrorHandlingAndValidation)(
|
|
60
|
+
return (0, common_1.withErrorHandlingAndValidation)(listApiKeys, common_1.Validators.listRequestSchema);
|
|
62
61
|
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { GrpcErrorMessage } from "@fonoster/common";
|
|
2
|
+
import { Prisma } from "../db";
|
|
3
|
+
declare function createRegenerateApiKey(prisma: Prisma): (call: {
|
|
4
|
+
request: unknown;
|
|
5
|
+
}, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
|
|
6
|
+
export { createRegenerateApiKey };
|
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.
|
|
12
|
+
exports.createRegenerateApiKey = createRegenerateApiKey;
|
|
13
13
|
/*
|
|
14
14
|
* Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
|
|
15
15
|
* http://github.com/fonoster/fonoster
|
|
@@ -32,8 +32,8 @@ const common_1 = require("@fonoster/common");
|
|
|
32
32
|
const logger_1 = require("@fonoster/logger");
|
|
33
33
|
const generateAccessKeySecret_1 = require("../utils/generateAccessKeySecret");
|
|
34
34
|
const logger = (0, logger_1.getLogger)({ service: "identity", filePath: __filename });
|
|
35
|
-
function
|
|
36
|
-
const
|
|
35
|
+
function createRegenerateApiKey(prisma) {
|
|
36
|
+
const regenerateApiKey = (call, callback) => __awaiter(this, void 0, void 0, function* () {
|
|
37
37
|
const { request } = call;
|
|
38
38
|
const { ref } = request;
|
|
39
39
|
logger.info("regenerating ApiKey", { ref });
|
|
@@ -51,5 +51,5 @@ function regenerateApiKey(prisma) {
|
|
|
51
51
|
accessKeySecret: response.accessKeySecret
|
|
52
52
|
});
|
|
53
53
|
});
|
|
54
|
-
return (0, common_1.withErrorHandlingAndValidation)(
|
|
54
|
+
return (0, common_1.withErrorHandlingAndValidation)(regenerateApiKey, common_1.Validators.emptySchema);
|
|
55
55
|
}
|
package/dist/apikeys/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from "./
|
|
2
|
-
export * from "./
|
|
3
|
-
export * from "./
|
|
4
|
-
export * from "./
|
|
1
|
+
export * from "./createCreateApiKey";
|
|
2
|
+
export * from "./createDeleteApiKey";
|
|
3
|
+
export * from "./createListApiKeys";
|
|
4
|
+
export * from "./createRegenerateApiKey";
|
package/dist/apikeys/index.js
CHANGED
|
@@ -32,7 +32,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
32
32
|
* See the License for the specific language governing permissions and
|
|
33
33
|
* limitations under the License.
|
|
34
34
|
*/
|
|
35
|
-
__exportStar(require("./
|
|
36
|
-
__exportStar(require("./
|
|
37
|
-
__exportStar(require("./
|
|
38
|
-
__exportStar(require("./
|
|
35
|
+
__exportStar(require("./createCreateApiKey"), exports);
|
|
36
|
+
__exportStar(require("./createDeleteApiKey"), exports);
|
|
37
|
+
__exportStar(require("./createListApiKeys"), exports);
|
|
38
|
+
__exportStar(require("./createRegenerateApiKey"), exports);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { GrpcErrorMessage } from "@fonoster/common";
|
|
2
2
|
import { IdentityConfig } from "./types";
|
|
3
3
|
import { Prisma } from "../db";
|
|
4
|
-
declare function
|
|
4
|
+
declare function createExchangeApiKey(prisma: Prisma, identityConfig: IdentityConfig): (call: {
|
|
5
5
|
request: unknown;
|
|
6
6
|
}, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
|
|
7
|
-
export {
|
|
7
|
+
export { createExchangeApiKey };
|
|
@@ -42,7 +42,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
42
42
|
});
|
|
43
43
|
};
|
|
44
44
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
|
-
exports.
|
|
45
|
+
exports.createExchangeApiKey = createExchangeApiKey;
|
|
46
46
|
/*
|
|
47
47
|
* Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
|
|
48
48
|
* http://github.com/fonoster/fonoster
|
|
@@ -65,14 +65,14 @@ const common_1 = require("@fonoster/common");
|
|
|
65
65
|
const logger_1 = require("@fonoster/logger");
|
|
66
66
|
const grpc = __importStar(require("@grpc/grpc-js"));
|
|
67
67
|
const exchangeTokens_1 = require("./exchangeTokens");
|
|
68
|
-
const
|
|
68
|
+
const createGetApiKeyByAccessKeyId_1 = require("../utils/createGetApiKeyByAccessKeyId");
|
|
69
69
|
const logger = (0, logger_1.getLogger)({ service: "identity", filePath: __filename });
|
|
70
|
-
function
|
|
71
|
-
const
|
|
70
|
+
function createExchangeApiKey(prisma, identityConfig) {
|
|
71
|
+
const exchangeApiKey = (call, callback) => __awaiter(this, void 0, void 0, function* () {
|
|
72
72
|
const { request } = call;
|
|
73
73
|
const { accessKeyId, accessKeySecret } = request;
|
|
74
74
|
logger.verbose("call to exchangeApiKey", { accessKeyId });
|
|
75
|
-
const key = yield (0,
|
|
75
|
+
const key = yield (0, createGetApiKeyByAccessKeyId_1.createGetApiKeyByAccessKeyId)(prisma)(accessKeyId);
|
|
76
76
|
if ((key === null || key === void 0 ? void 0 : key.accessKeySecret) !== (accessKeySecret === null || accessKeySecret === void 0 ? void 0 : accessKeySecret.trim())) {
|
|
77
77
|
return callback({
|
|
78
78
|
code: grpc.status.PERMISSION_DENIED,
|
|
@@ -81,5 +81,5 @@ function exchangeApiKey(prisma, identityConfig) {
|
|
|
81
81
|
}
|
|
82
82
|
callback(null, yield (0, exchangeTokens_1.exchangeTokens)(prisma, identityConfig)(accessKeyId));
|
|
83
83
|
});
|
|
84
|
-
return (0, common_1.withErrorHandlingAndValidation)(
|
|
84
|
+
return (0, common_1.withErrorHandlingAndValidation)(exchangeApiKey, common_1.Validators.exchangeApiKeysRequestSchema);
|
|
85
85
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { GrpcErrorMessage } from "@fonoster/common";
|
|
2
2
|
import { IdentityConfig } from "./types";
|
|
3
3
|
import { Prisma } from "../db";
|
|
4
|
-
declare function
|
|
4
|
+
declare function createExchangeCredentials(prisma: Prisma, identityConfig: IdentityConfig): (call: {
|
|
5
5
|
request: unknown;
|
|
6
6
|
}, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
|
|
7
|
-
export {
|
|
7
|
+
export { createExchangeCredentials };
|
|
@@ -42,7 +42,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
42
42
|
});
|
|
43
43
|
};
|
|
44
44
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
|
-
exports.
|
|
45
|
+
exports.createExchangeCredentials = createExchangeCredentials;
|
|
46
46
|
/*
|
|
47
47
|
* Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
|
|
48
48
|
* http://github.com/fonoster/fonoster
|
|
@@ -67,18 +67,18 @@ const grpc = __importStar(require("@grpc/grpc-js"));
|
|
|
67
67
|
const exchangeTokens_1 = require("./exchangeTokens");
|
|
68
68
|
const envs_1 = require("../envs");
|
|
69
69
|
const createIsValidVerificationCode_1 = require("../utils/createIsValidVerificationCode");
|
|
70
|
-
const
|
|
70
|
+
const createGetUserByEmail_1 = require("../utils/createGetUserByEmail");
|
|
71
71
|
const verification_1 = require("../verification");
|
|
72
72
|
const logger = (0, logger_1.getLogger)({ service: "identity", filePath: __filename });
|
|
73
73
|
const verificationRequiredButNotProvided = (user) => envs_1.IDENTITY_USER_VERIFICATION_REQUIRED &&
|
|
74
74
|
(!user.emailVerified || !user.phoneNumberVerified);
|
|
75
|
-
function
|
|
75
|
+
function createExchangeCredentials(prisma, identityConfig) {
|
|
76
76
|
const isValidVerificationCode = (0, createIsValidVerificationCode_1.createIsValidVerificationCode)(prisma);
|
|
77
|
-
const
|
|
77
|
+
const exchangeCredentials = (call, callback) => __awaiter(this, void 0, void 0, function* () {
|
|
78
78
|
const { request } = call;
|
|
79
79
|
const { username: email, password, verificationCode } = request;
|
|
80
80
|
logger.verbose("call to exchangeCredentials", { username: email });
|
|
81
|
-
const user = yield (0,
|
|
81
|
+
const user = yield (0, createGetUserByEmail_1.createGetUserByEmail)(prisma)(email);
|
|
82
82
|
if (!user || user.password !== (password === null || password === void 0 ? void 0 : password.trim())) {
|
|
83
83
|
return callback({
|
|
84
84
|
code: grpc.status.PERMISSION_DENIED,
|
|
@@ -106,5 +106,5 @@ function exchangeCredentials(prisma, identityConfig) {
|
|
|
106
106
|
}
|
|
107
107
|
callback(null, yield (0, exchangeTokens_1.exchangeTokens)(prisma, identityConfig)(user.accessKeyId));
|
|
108
108
|
});
|
|
109
|
-
return (0, common_1.withErrorHandlingAndValidation)(
|
|
109
|
+
return (0, common_1.withErrorHandlingAndValidation)(exchangeCredentials, common_1.exchangeCredentialsRequestSchema);
|
|
110
110
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { GrpcErrorMessage } from "@fonoster/common";
|
|
2
2
|
import { IdentityConfig } from "./types";
|
|
3
3
|
import { Prisma } from "../db";
|
|
4
|
-
declare function
|
|
4
|
+
declare function createExchangeOauth2Code(prisma: Prisma, identityConfig: IdentityConfig): (call: {
|
|
5
5
|
request: unknown;
|
|
6
6
|
}, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
|
|
7
|
-
export {
|
|
7
|
+
export { createExchangeOauth2Code };
|
|
@@ -42,7 +42,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
42
42
|
});
|
|
43
43
|
};
|
|
44
44
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
|
-
exports.
|
|
45
|
+
exports.createExchangeOauth2Code = createExchangeOauth2Code;
|
|
46
46
|
/*
|
|
47
47
|
* Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
|
|
48
48
|
* http://github.com/fonoster/fonoster
|
|
@@ -65,10 +65,10 @@ const common_1 = require("@fonoster/common");
|
|
|
65
65
|
const logger_1 = require("@fonoster/logger");
|
|
66
66
|
const grpc = __importStar(require("@grpc/grpc-js"));
|
|
67
67
|
const exchangeTokens_1 = require("./exchangeTokens");
|
|
68
|
-
const
|
|
68
|
+
const createGetUserByEmail_1 = require("../utils/createGetUserByEmail");
|
|
69
69
|
const logger = (0, logger_1.getLogger)({ service: "identity", filePath: __filename });
|
|
70
|
-
function
|
|
71
|
-
const
|
|
70
|
+
function createExchangeOauth2Code(prisma, identityConfig) {
|
|
71
|
+
const exchangeOauth2Code = (call, callback) => __awaiter(this, void 0, void 0, function* () {
|
|
72
72
|
const { request } = call;
|
|
73
73
|
const { provider, username: email, code } = request;
|
|
74
74
|
logger.verbose("call to exchangeOauth2Code", { provider });
|
|
@@ -92,7 +92,7 @@ function exchangeOauth2Code(prisma, identityConfig) {
|
|
|
92
92
|
}
|
|
93
93
|
});
|
|
94
94
|
const userData = yield userResponse.json();
|
|
95
|
-
const user = yield (0,
|
|
95
|
+
const user = yield (0, createGetUserByEmail_1.createGetUserByEmail)(prisma)(email);
|
|
96
96
|
if (userData.email !== email || !user) {
|
|
97
97
|
return callback({
|
|
98
98
|
code: grpc.status.PERMISSION_DENIED,
|
|
@@ -101,5 +101,5 @@ function exchangeOauth2Code(prisma, identityConfig) {
|
|
|
101
101
|
}
|
|
102
102
|
callback(null, yield (0, exchangeTokens_1.exchangeTokens)(prisma, identityConfig)(user.accessKeyId));
|
|
103
103
|
});
|
|
104
|
-
return (0, common_1.withErrorHandlingAndValidation)(
|
|
104
|
+
return (0, common_1.withErrorHandlingAndValidation)(exchangeOauth2Code, common_1.exchangeOauth2RequestSchema);
|
|
105
105
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { GrpcErrorMessage } from "@fonoster/common";
|
|
2
2
|
import { IdentityConfig } from "./types";
|
|
3
3
|
import { Prisma } from "../db";
|
|
4
|
-
declare function
|
|
4
|
+
declare function createExchangeRefreshToken(prisma: Prisma, identityConfig: IdentityConfig): (call: {
|
|
5
5
|
request: unknown;
|
|
6
6
|
}, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
|
|
7
|
-
export {
|
|
7
|
+
export { createExchangeRefreshToken };
|
|
@@ -12,7 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.
|
|
15
|
+
exports.createExchangeRefreshToken = createExchangeRefreshToken;
|
|
16
16
|
/*
|
|
17
17
|
* Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
|
|
18
18
|
* http://github.com/fonoster/fonoster
|
|
@@ -37,8 +37,8 @@ const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
|
|
|
37
37
|
const exchangeTokens_1 = require("./exchangeTokens");
|
|
38
38
|
const constants_1 = require("../constants");
|
|
39
39
|
const logger = (0, logger_1.getLogger)({ service: "identity", filePath: __filename });
|
|
40
|
-
function
|
|
41
|
-
const
|
|
40
|
+
function createExchangeRefreshToken(prisma, identityConfig) {
|
|
41
|
+
const exchangeRefreshToken = (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;
|
|
@@ -49,5 +49,5 @@ function exchangeRefreshToken(prisma, identityConfig) {
|
|
|
49
49
|
logger.verbose("call to exchangeRefreshToken", { accessKeyId });
|
|
50
50
|
callback(null, yield (0, exchangeTokens_1.exchangeTokens)(prisma, identityConfig)(accessKeyId));
|
|
51
51
|
});
|
|
52
|
-
return (0, common_1.withErrorHandlingAndValidation)(
|
|
52
|
+
return (0, common_1.withErrorHandlingAndValidation)(exchangeRefreshToken, common_1.exchangeRefreshTokenRequestSchema);
|
|
53
53
|
}
|
|
@@ -79,16 +79,16 @@ function exchangeTokens(prisma, identityConfig) {
|
|
|
79
79
|
let accessToken = null;
|
|
80
80
|
let refreshToken = null;
|
|
81
81
|
if (accessKeyId.startsWith("US")) {
|
|
82
|
-
const idTokenPayload = yield US.
|
|
83
|
-
const accessTokenPayload = yield US.
|
|
84
|
-
const refreshTokenPayload = yield US.
|
|
82
|
+
const idTokenPayload = yield US.createGetIdTokenPayload(prisma, identityConfig)(accessKeyId);
|
|
83
|
+
const accessTokenPayload = yield US.createGetAccessTokenPayload(prisma, identityConfig)(accessKeyId);
|
|
84
|
+
const refreshTokenPayload = yield US.createGetRefreshTokenPayload(prisma, identityConfig)(accessKeyId);
|
|
85
85
|
idToken = jsonwebtoken_1.default.sign(idTokenPayload, privateKey, idTokenSignOptions);
|
|
86
86
|
accessToken = jsonwebtoken_1.default.sign(accessTokenPayload, privateKey, accessTokenSignOptions);
|
|
87
87
|
refreshToken = jsonwebtoken_1.default.sign(refreshTokenPayload, privateKey, refreshTokenSignOptions);
|
|
88
88
|
}
|
|
89
89
|
else {
|
|
90
|
-
const accessTokenPayload = yield AK.
|
|
91
|
-
const refreshTokenPayload = yield AK.
|
|
90
|
+
const accessTokenPayload = yield AK.createGetAccessTokenPayload(prisma, identityConfig)(accessKeyId);
|
|
91
|
+
const refreshTokenPayload = yield AK.createGetRefreshTokenPayload(prisma, identityConfig)(accessKeyId);
|
|
92
92
|
accessToken = jsonwebtoken_1.default.sign(accessTokenPayload, privateKey, accessTokenSignOptions);
|
|
93
93
|
refreshToken = jsonwebtoken_1.default.sign(refreshTokenPayload, privateKey, refreshTokenSignOptions);
|
|
94
94
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
export * from "./
|
|
2
|
-
export * from "./
|
|
3
|
-
export * from "./
|
|
4
|
-
export * from "./
|
|
5
|
-
export * from "./exchangeRefreshToken";
|
|
1
|
+
export * from "./createExchangeApiKey";
|
|
2
|
+
export * from "./createExchangeCredentials";
|
|
3
|
+
export * from "./createExchangeOauth2Code";
|
|
4
|
+
export * from "./createExchangeRefreshToken";
|
|
6
5
|
export * from "./types";
|
package/dist/exchanges/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("./TokenUseEnum"), exports);
|
|
18
17
|
/*
|
|
19
18
|
* Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
|
|
20
19
|
* http://github.com/fonoster/fonoster
|
|
@@ -33,8 +32,8 @@ __exportStar(require("./TokenUseEnum"), exports);
|
|
|
33
32
|
* See the License for the specific language governing permissions and
|
|
34
33
|
* limitations under the License.
|
|
35
34
|
*/
|
|
36
|
-
__exportStar(require("./
|
|
37
|
-
__exportStar(require("./
|
|
38
|
-
__exportStar(require("./
|
|
39
|
-
__exportStar(require("./
|
|
35
|
+
__exportStar(require("./createExchangeApiKey"), exports);
|
|
36
|
+
__exportStar(require("./createExchangeCredentials"), exports);
|
|
37
|
+
__exportStar(require("./createExchangeOauth2Code"), exports);
|
|
38
|
+
__exportStar(require("./createExchangeRefreshToken"), exports);
|
|
40
39
|
__exportStar(require("./types"), exports);
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Prisma } from "../../../db";
|
|
2
|
+
import { AccessToken } from "@fonoster/common/";
|
|
3
|
+
import { IdentityConfig } from "../../types";
|
|
4
|
+
declare function createGetAccessTokenPayload(prisma: Prisma, identityConfig: IdentityConfig): (accessKeyId: string) => Promise<AccessToken>;
|
|
5
|
+
export { createGetAccessTokenPayload };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.createGetAccessTokenPayload = createGetAccessTokenPayload;
|
|
13
|
+
const common_1 = require("@fonoster/common/");
|
|
14
|
+
function createGetAccessTokenPayload(prisma, identityConfig) {
|
|
15
|
+
return function getAccessTokenPayload(accessKeyId) {
|
|
16
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
17
|
+
const apiKey = yield prisma.apiKey.findFirst({
|
|
18
|
+
where: {
|
|
19
|
+
accessKeyId
|
|
20
|
+
},
|
|
21
|
+
include: {
|
|
22
|
+
workspace: true
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
if (!apiKey) {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
const { issuer, audience } = identityConfig;
|
|
29
|
+
const { ref, workspace } = apiKey;
|
|
30
|
+
const access = [
|
|
31
|
+
{
|
|
32
|
+
accessKeyId: workspace.accessKeyId,
|
|
33
|
+
role: apiKey.role
|
|
34
|
+
}
|
|
35
|
+
];
|
|
36
|
+
return {
|
|
37
|
+
iss: issuer,
|
|
38
|
+
sub: ref,
|
|
39
|
+
aud: audience,
|
|
40
|
+
tokenUse: common_1.TokenUseEnum.ACCESS,
|
|
41
|
+
accessKeyId,
|
|
42
|
+
access
|
|
43
|
+
};
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Prisma } from "../../../db";
|
|
2
|
+
import { IdentityConfig } from "../../types";
|
|
3
|
+
import { RefreshToken } from "@fonoster/common";
|
|
4
|
+
declare function createGetRefreshTokenPayload(prisma: Prisma, identityConfig: IdentityConfig): (accessKeyId: string) => Promise<RefreshToken>;
|
|
5
|
+
export { createGetRefreshTokenPayload };
|
|
@@ -9,23 +9,25 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.
|
|
12
|
+
exports.createGetRefreshTokenPayload = createGetRefreshTokenPayload;
|
|
13
13
|
const buildRefreshTokenPayload_1 = require("../buildRefreshTokenPayload");
|
|
14
|
-
function
|
|
15
|
-
return
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
function createGetRefreshTokenPayload(prisma, identityConfig) {
|
|
15
|
+
return function createGetRefreshTokenPayload(accessKeyId) {
|
|
16
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
17
|
+
const apiKey = yield prisma.apiKey.findFirst({
|
|
18
|
+
where: {
|
|
19
|
+
accessKeyId
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
if (!apiKey) {
|
|
23
|
+
return null;
|
|
19
24
|
}
|
|
25
|
+
const { ref: identityRef } = apiKey;
|
|
26
|
+
return (0, buildRefreshTokenPayload_1.buildRefreshTokenPayload)({
|
|
27
|
+
identityConfig,
|
|
28
|
+
accessKeyId,
|
|
29
|
+
identityRef
|
|
30
|
+
});
|
|
20
31
|
});
|
|
21
|
-
|
|
22
|
-
return null;
|
|
23
|
-
}
|
|
24
|
-
const { ref: identityRef } = apiKey;
|
|
25
|
-
return (0, buildRefreshTokenPayload_1.buildRefreshTokenPayload)({
|
|
26
|
-
identityConfig,
|
|
27
|
-
accessKeyId,
|
|
28
|
-
identityRef
|
|
29
|
-
});
|
|
30
|
-
});
|
|
32
|
+
};
|
|
31
33
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from "./
|
|
2
|
-
export * from "./
|
|
1
|
+
export * from "./createGetAccessTokenPayload";
|
|
2
|
+
export * from "./createGetRefreshTokenPayload";
|
|
@@ -32,5 +32,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
32
32
|
* See the License for the specific language governing permissions and
|
|
33
33
|
* limitations under the License.
|
|
34
34
|
*/
|
|
35
|
-
__exportStar(require("./
|
|
36
|
-
__exportStar(require("./
|
|
35
|
+
__exportStar(require("./createGetAccessTokenPayload"), exports);
|
|
36
|
+
__exportStar(require("./createGetRefreshTokenPayload"), exports);
|
|
@@ -19,7 +19,7 @@ exports.buildRefreshTokenPayload = buildRefreshTokenPayload;
|
|
|
19
19
|
* See the License for the specific language governing permissions and
|
|
20
20
|
* limitations under the License.
|
|
21
21
|
*/
|
|
22
|
-
const
|
|
22
|
+
const common_1 = require("@fonoster/common");
|
|
23
23
|
function buildRefreshTokenPayload(params) {
|
|
24
24
|
const { identityConfig, accessKeyId, identityRef } = params;
|
|
25
25
|
const { issuer, audience } = identityConfig;
|
|
@@ -27,7 +27,7 @@ function buildRefreshTokenPayload(params) {
|
|
|
27
27
|
iss: issuer,
|
|
28
28
|
sub: identityRef,
|
|
29
29
|
aud: audience,
|
|
30
|
-
tokenUse:
|
|
30
|
+
tokenUse: common_1.TokenUseEnum.REFRESH,
|
|
31
31
|
accessKeyId
|
|
32
32
|
};
|
|
33
33
|
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Prisma } from "../../../db";
|
|
2
|
+
import { AccessToken } from "@fonoster/common";
|
|
3
|
+
import { IdentityConfig } from "../../types";
|
|
4
|
+
declare function createGetAccessTokenPayload(prisma: Prisma, identityConfig: IdentityConfig): (accessKeyId: string) => Promise<AccessToken>;
|
|
5
|
+
export { createGetAccessTokenPayload };
|