认知用户迁移触发器未触发



在 eu-west-1 中的 cognito user pool 中。我正在尝试为用户添加触发器 迁移。当我尝试以不存在的用户身份登录时,它不会触发。 我已经通过编写一个简单的python lambda来测试这一点:

def handler(event, context):
print(event)
return event

在日志中,如果用户不存在,我永远不会看到此运行。然后我尝试了 设置所有触发器以使用此 lambda 我看到(使用现有用户登录时(:

  • PreAuthentication_Authentication
  • PostAuthentication_Authentication
  • TokenGeneration_Authentication

使用不存在的用户登录时,即迁移候选 - 我没有看到触发的触发器。

这是一个特定于区域的问题吗? 我们需要启用某些功能才能触发触发器吗? 我们是否需要为非身份验证用户或失败登录触发的触发器启用特定权限?

要调用用户迁移触发器,您必须使用 USER_PASSWORD_AUTH

authenticationFlowType: 'USER_PASSWORD_AUTH'

执行此操作的一个例子是下面底部的 Amplify 中的此配置

import Amplify from 'aws-amplify';
Amplify.configure({
Auth: {
// REQUIRED only for Federated Authentication - Amazon Cognito Identity Pool ID
identityPoolId: 'XX-XXXX-X:XXXXXXXX-XXXX-1234-abcd-1234567890ab',
// REQUIRED - Amazon Cognito Region
region: 'XX-XXXX-X',
// OPTIONAL - Amazon Cognito Federated Identity Pool Region 
// Required only if it's different from Amazon Cognito Region
identityPoolRegion: 'XX-XXXX-X',
// OPTIONAL - Configuration for cookie storage
// Note: if the secure flag is set to true, then the cookie transmission requires a secure protocol
cookieStorage: {
// REQUIRED - Cookie domain (only required if cookieStorage is provided)
domain: '.yourdomain.com',
// OPTIONAL - Cookie path
path: '/',
// OPTIONAL - Cookie expiration in days
expires: 365,
// OPTIONAL - Cookie secure flag
// Either true or false, indicating if the cookie transmission requires a secure protocol (https).
secure: true
},
// OPTIONAL - customized storage object
storage: new MyStorage(),
// OPTIONAL - Manually set the authentication flow type. Default is 'USER_SRP_AUTH'
authenticationFlowType: 'USER_PASSWORD_AUTH'
// OPTIONAL - Amazon Cognito User Pool ID
userPoolId: 'XX-XXXX-X_abcd1234',
// OPTIONAL - Amazon Cognito Web Client ID (26-char alphanumeric string)
userPoolWebClientId: 'a1b2c3d4e5f6g7h8i9j0k1l2m3',
// OPTIONAL - Enforce user authentication prior to accessing AWS resources or not
mandatorySignIn: false,
}
});

如果您的用户池同时启用了ALLOW_USER_PASSWORD_AUTHALLOW_USER_SRP_AUTH,cognito 将尝试使用更安全的 SRP(安全远程协议(进行身份验证,以避免通过网络以纯文本形式发送密码。

我发现在调用之前添加呼叫setAuthenticationFlowType('USER_PASSWORD_AUTH');authenticateUser(authDetails,...)克服了对 SRP 的这种偏好,并且迁移用户 Lambda 在身份验证失败时触发。

import { CognitoUser } from 'amazon-cognito-identity-js';
...
...
const cognitoUser = new CognitoUser({
Username: email,
Pool: migrationDestUserPool,
});
...
...
cognitoUser.setAuthenticationFlowType('USER_PASSWORD_AUTH');
cognitoUser.authenticateUser(authDetails, {...

最新更新