doulu4976 2019-03-03 04:02
浏览 134
已采纳

通过Lambda函数的AWS Cognito InitiateAuth导致错误

I am writing a Lambda function in Go to authenticate a user, the AccessToken/IdToken I want to use for subsequent API calls.

When I execute the Go code from a standalone program, it works, the InitiateAuth was successful.

When I tried to use the same code from the lambda function, I get an error NotAuthorizedException: Unable to verify secret hash for client .......

Here is the code snippet I am using

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
}

I have given sufficient permissions to the lambda user - cognito-idp:AdminCreateUser - cognito-idp:AdminDeleteUser - cognito-idp:InitiateAuth - cognito-idp:ChangePassword - cognito-idp:AdminRespondToAuthChallenge - cognito-idp:AdminInitiateAuth - cognito-idp:ConfirmForgotPassword

Am I missing something here?

  • 写回答

1条回答 默认 最新

  • duanchao1002 2019-03-04 08:03
    关注

    When we create a new App client, by default it has an associated App client secret.

    I created one more app client, without "Client Secret". I used this new App client.

    I modified the code to use the API AdminInitiateAuth, instead of the InitiateAuth

    I was able to successfully login.

    Here is the reference link, which was useful - Amplify "Unable to verify secret hash for client"

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作