gpt4 book ai didi

amazon-web-services - 用户登录时登录抛出 'Incorrect username or password' 错误

转载 作者:行者123 更新时间:2023-12-01 04:31:00 26 4
gpt4 key购买 nike

我创建了一个 Cognito 用户池,用户可以在其中注册,但无法再登录。我尝试了许多不同的配置,例如禁用 MFA、关闭设备内存(据我所知可能会导致此问题),但均无济于事。

最奇怪的是,它在本地运行良好(localhost:5000)。我可以创建帐户并登录,没有任何戏剧性,但是当我尝试在我的网站 https://example.com(托管在 S3 上)上登录时,它会抛出上述错误。如果我注册的话,用户实际上似乎也是在 Cognito 中创建的 - 这样就可以了,但登录除了在本地以外的任何地方都不起作用。

我对每个设置、环境变量、重新创建用户池等进行了两次、三次检查。

错误

这是我尝试登录时抛出的不明确错误:

{
__type: "NotAuthorizedException",
message: "Incorrect username or password."
}

预注册触发 lambda

我在用户通过 lambda 注册之前对其进行确认:

import {INTERNAL_SERVER_ERROR} from 'http-status-codes';

export async function validateHumanViaSns(
event: CognitoUserPoolTriggerEvent,
context: Context,
callback: Callback
): Promise<CognitoUserPoolTriggerHandler> {
try {
event.response.autoConfirmUser = true;

callback(null, event);

return;
} catch (error) {
console.error(error);
callback(null, new Response(INTERNAL_SERVER_ERROR, {message: 'Something went wrong'}));

return;
}
}

package.json

我的客户正在使用最新的 amplify-js图书馆。

dependencies: {
"amplify": "1.1.19" // broken since 1.1.18
}

CloudFormation Cognito 模板

UserPool:
Type: 'AWS::Cognito::UserPool'
Properties:
UserPoolName: myapp-${self:provider.stage}-user-pool
SmsVerificationMessage: 'Your verification code is {####}.'
AutoVerifiedAttributes:
- email
MfaConfiguration: 'OFF'
EmailVerificationSubject: 'Your MyApp verification code'
EmailVerificationMessage: 'Your MyApp verification code is {####}.'
SmsAuthenticationMessage: 'Your MyApp authentication code is {####}.'
Schema:
- Name: name
AttributeDataType: String
Mutable: true
Required: false
- Name: email
AttributeDataType: String
Mutable: false
Required: false
- Name: phone_number
AttributeDataType: String
Mutable: true
Required: false
Policies:
PasswordPolicy:
RequireLowercase: true
RequireSymbols: false
RequireNumbers: true
MinimumLength: 8
RequireUppercase: true
AdminCreateUserConfig:
InviteMessageTemplate:
EmailMessage: 'Your MyApp username is {username} and temporary password is {####}.'
EmailSubject: 'Your temporary MyApp password'
SMSMessage: 'Your MyApp username is {username} and temporary password is {####}.'
UnusedAccountValidityDays: 7
AllowAdminCreateUserOnly: false

# Creates a User Pool Client to be used by the identity pool
UserPoolClient:
Type: 'AWS::Cognito::UserPoolClient'
Properties:
ClientName: myapp-${self:provider.stage}-web-client
GenerateSecret: false
UserPoolId:
Ref: UserPool

# Creates a federeated Identity pool
IdentityPool:
Type: 'AWS::Cognito::IdentityPool'
Properties:
IdentityPoolName: MyApp{self:provider.stage}Identity
AllowUnauthenticatedIdentities: true
CognitoIdentityProviders:
- ClientId:
Ref: UserPoolClient
ProviderName:
'Fn::GetAtt': [ UserPool, ProviderName ]

# Create a role for unauthorized access to AWS resources. Very limited access. Only allows users in the previously created Identity Pool
CognitoUnAuthorizedRole:
Type: 'AWS::IAM::Role'
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: 'Allow'
Principal:
Federated: 'cognito-identity.amazonaws.com '
Action:
- 'sts:AssumeRoleWithWebIdentity'
Condition:
StringEquals:
'cognito-identity.amazonaws.com :aud':
Ref: IdentityPool
'ForAnyValue:StringLike':
'cognito-identity.amazonaws.com :amr': unauthenticated
Policies:
- PolicyName: 'CognitoUnauthorizedPolicy'
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: 'Allow'
Action:
- 'mobileanalytics:PutEvents'
- 'cognito-sync:*'
Resource: '*'

# Create a role for authorized access to AWS resources. Control what your user can access. This example only allows Lambda invokation
# Only allows users in the previously created Identity Pool
CognitoAuthorizedRole:
Type: 'AWS::IAM::Role'
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: 'Allow'
Principal:
Federated: 'cognito-identity.amazonaws.com '
Action:
- 'sts:AssumeRoleWithWebIdentity'
Condition:
StringEquals:
'cognito-identity.amazonaws.com :aud':
Ref: IdentityPool
'ForAnyValue:StringLike':
'cognito-identity.amazonaws.com :amr': authenticated
Policies:
- PolicyName: 'CognitoAuthorizedPolicy'
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: 'Allow'
Action:
- 'mobileanalytics:PutEvents'
- 'cognito-sync:*'
- 'cognito-identity:*'
Resource: '*'
- Effect: 'Allow'
Action:
- 'lambda:InvokeFunction'
Resource: '*'

# Assigns the roles to the Identity Pool
IdentityPoolRoleMapping:
Type: 'AWS::Cognito::IdentityPoolRoleAttachment'
Properties:
IdentityPoolId:
Ref: IdentityPool
Roles:
authenticated:
'Fn::GetAtt': [ CognitoAuthorizedRole, Arn ]
unauthenticated:
'Fn::GetAtt': [ CognitoUnAuthorizedRole, Arn ]

有谁知道为什么会抛出这个特定的错误(我认为这是误导性的),或者更好的是,如何解决这个问题?

最佳答案

此问题已在 AWS Amplify Github 问题积压中修复,more context here .

无论在哪里导入 amplify,都需要事先直接导入 crypto-js 依赖项,因为 amplify-js 库中存在 Typescript 编译问题:

import 'crypto-js/lib-typedarrays'; // add this line
import Amplify, {Auth} from 'aws-amplify';

看起来这将是 future 拉取请求中的永久修复,因此根据您登陆此处的时间,尝试将aws-amplify包更新为某些内容>首先1.1.19,看看是否已经在主包中修复了。

关于amazon-web-services - 用户登录时登录抛出 'Incorrect username or password' 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54188428/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com