Skip to content

Instantly share code, notes, and snippets.

@yutakahashi114
Created May 16, 2021 06:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yutakahashi114/f4552724774f546a688e0935f80154c7 to your computer and use it in GitHub Desktop.
Save yutakahashi114/f4552724774f546a688e0935f80154c7 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"log"
"os"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/cognitoidentityprovider"
)
func main() {
if len(os.Args) != 3 {
log.Fatal("invalid args")
}
id := os.Args[1]
password := os.Args[2]
params := &cognitoidentityprovider.AdminInitiateAuthInput{
AuthFlow: aws.String(cognitoidentityprovider.AuthFlowTypeAdminNoSrpAuth),
AuthParameters: map[string]*string{
"USERNAME": aws.String(id),
"PASSWORD": aws.String(password),
},
ClientId: aws.String(os.Getenv("CLIENT_ID")),
UserPoolId: aws.String(os.Getenv("USER_POOL_ID")),
}
client := cognitoidentityprovider.New(
session.Must(session.NewSessionWithOptions(session.Options{
SharedConfigState: session.SharedConfigEnable,
})),
)
res, err := client.AdminInitiateAuth(params)
if err != nil {
log.Fatal(err)
}
if res == nil || res.AuthenticationResult == nil || res.AuthenticationResult.IdToken == nil {
log.Fatal("failed to login")
}
fmt.Println(*res.AuthenticationResult.IdToken)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment