簡體   English   中英

使用 NestJS/Node.js 根據租戶創建不同的 AWS Cognito 用戶池和角色

[英]Create Different AWS Cognito user pools, roles according to tenant with NestJS/Node.js

我正在使用 NestJS (Node.js) 開發一個多租戶應用程序並做出反應。 我希望將我的用戶存儲在 AWS Cognito 用戶池中。 我需要根據他們的租戶將我的用戶保留在不同的用戶池中。並且需要根據他們的租戶創建角色。 我無法通過 Node.js (NestJS) 找到創建用戶池、角色和用戶的方法或做出反應。 我沒有找到任何有用的方法來做到這一點。 有人可以建議我如何通過該程序創建不同的用戶池。(這可能嗎??)

我遵循了一些教程,但找不到合適的解決方案。 授權和身份驗證看起來不錯。 但是我需要根據他們的租戶將我的用戶保留在不同的用戶組中。

是的,我們可以通過編程方式做到這一點。 AWS Cognito 用戶池 API促進了這一點。 例如,我們可以使用CreateUserPool端點來創建新的用戶池。

對於Node.js ,您可以依賴 AWS JavaScript SDK ,這進一步簡化了上述 API 的使用。

您必須使用CognitoIdentityProviderClientsend帶有相關參數的CreateUserPoolCommand

以下代碼塊說明了高級方法。

//Initiates the client with configs.
const client = new CognitoIdentityProviderClient({
    region: "REGION"
});

//setup input params for CreateUserPoolCommandInput
const params = {
    PoolName: "the-name-of-the-pool",
    EmailVerificationMessage: "message goes here."
    //add rest of the details as required.
};

//Initiate the command with input parameters.
const command = new CreateUserPoolCommand(params);

//Call send operation on client with command object as input.
const data = await client.send(command);

希望這會幫助您實現您的要求。 請參閱給定的鏈接以獲取更多詳細信息。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM