【发布时间】:2019-07-24 17:11:09
【问题描述】:
我正在用 Go 编写一个 Lambda 函数来对用户进行身份验证,即我想用于后续 API 调用的 AccessToken/IdToken。
当我从独立程序执行 Go 代码时,它可以工作,InitiateAuth 成功。
当我尝试使用 lambda 函数中的相同代码时,我收到错误 NotAuthorizedException: Unable to verify secret hash for client ....
这是我正在使用的代码 sn-p
func AuthenticateUser(userName string, passWord string) (*cognitoidentityprovider.InitiateAuthOutput, error) {
username := aws.String(userName)
password := aws.String(passWord)
clientID := aws.String(constants.COGNITO_APP_CLIENT_ID)
params := &cognitoidentityprovider.InitiateAuthInput{
AuthFlow: aws.String("USER_PASSWORD_AUTH"),
AuthParameters: map[string]*string{
"USERNAME": username,
"PASSWORD": password,
},
ClientId: clientID,
}
authResponse, authError := cognitoClient.InitiateAuth(params)
if authError != nil {
fmt.Println("Error = ", authError)
return nil, authError
}
fmt.Println(authResponse)
fmt.Println(*authResponse.Session)
return authResponse, nil
}
我已经给 lambda 用户足够的权限 - 认知 idp:AdminCreateUser - cognito-idp:AdminDeleteUser - 认知 idp:InitiateAuth - cognito-idp:ChangePassword - cognito-idp:AdminRespondToAuthChallenge - 认知 idp:AdminInitiateAuth - cognito-idp:ConfirmForgotPassword
我错过了什么吗?
【问题讨论】:
-
要验证这确实是 IAM 权限问题,请暂时授予您的 Lambda 函数的完全管理员访问权限,然后重试。如果有效,这确实是缺少 IAM 策略。阅读错误消息主要会为您提供权限中缺少的 API 调用的名称。
标签: amazon-web-services go aws-lambda amazon-cognito