in auth_flow/login.go [26:55]
func main() {
conf := &aws.Config{Region: aws.String("us-east-1")}
sess := session.Must(session.NewSession(conf))
// This is the part where we generate the hash.
mac := hmac.New(sha256.New, []byte(clientSecret))
mac.Write([]byte(username + clientId))
secretHash := base64.StdEncoding.EncodeToString(mac.Sum(nil))
cognitoClient := cognitoidentityprovider.New(sess)
authTry := &cognitoidentityprovider.InitiateAuthInput{
AuthFlow: aws.String("USER_PASSWORD_AUTH"),
AuthParameters: map[string]*string{
"USERNAME": aws.String(username),
"PASSWORD": aws.String(password),
"SECRET_HASH": aws.String(secretHash),
},
ClientId: aws.String(clientId),
}
res, err := cognitoClient.InitiateAuth(authTry)
if err != nil {
fmt.Println(err)
} else {
fmt.Println("authenticated")
fmt.Println(res.AuthenticationResult)
}
}