我正在 Go 中編寫一個 Lambda 函數來對用戶進行身份驗證,這是我想用于后續 API 調用的 AccessToken/IdToken。當我從一個獨立程序執行 Go 代碼時,它起作用了,InitiateAuth 成功了。當我嘗試使用來自 lambda 函數的相同代碼時,出現錯誤 NotAuthorizedException: Unable to verify secret hash for client ......這是我正在使用的代碼片段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 用戶提供了足夠的權限 - cognito-idp:AdminCreateUser - cognito-idp:AdminDeleteUser - cognito-idp:InitiateAuth - cognito-idp:ChangePassword - cognito-idp:AdminRespondToAuthChallenge - cognito-idp:AdminInitiateAuth - cognito-idp:確認忘記密碼我在這里錯過了什么嗎?
1 回答

達令說
TA貢獻1821條經驗 獲得超6個贊
當我們創建一個新的 App 客戶端時,默認情況下它有一個關聯的 App 客戶端密碼。
我又創建了一個沒有“Client Secret”的應用程序客戶端。我使用了這個新的 App 客戶端。
我修改了代碼以使用 API AdminInitiateAuth,而不是 InitiateAuth
我能夠成功登錄。
- 1 回答
- 0 關注
- 161 瀏覽
添加回答
舉報
0/150
提交
取消