I'm trying to make it easy for users to create their own Virtual MFA device and I get the results from CreateVirtualMFADevice function but I'm lost on how to print the QRCodePNG it self. When I print the results I just get the binary JSON results. Here is my code:
reader := bufio.NewReader(os.Stdin)
fmt.Println("Enter name of new virtual device: ")
user, err := reader.ReadString('
')
if err != nil {
fmt.Printf("Error: %v
", err)
}
input := &iam.CreateVirtualMFADeviceInput{
VirtualMFADeviceName: aws.String(strings.TrimSpace(user)),
//Path: aws.String("./QR_Code.png"),
}
result, err := svc.CreateVirtualMFADevice(input)
if err != nil {
if aerr, ok := err.(awserr.Error); ok {
switch aerr.Code() {
case iam.ErrCodeLimitExceededException:
fmt.Println(iam.ErrCodeLimitExceededException, aerr.Error())
case iam.ErrCodeEntityAlreadyExistsException:
fmt.Println(iam.ErrCodeEntityAlreadyExistsException, aerr.Error())
case iam.ErrCodeServiceFailureException:
fmt.Println(iam.ErrCodeServiceFailureException, aerr.Error())
default:
fmt.Println(aerr.Error())
}
} else {
// Print the error, cast err to awserr.Error to get the Code and
// Message from an error.
fmt.Println(err.Error())
}
return
}
fmt.Println(result)
Here are the references to the SDK calls: https://docs.aws.amazon.com/sdk-for-go/api/service/iam/#IAM.CreateVirtualMFADevice
This is the output I get from fmt.Println(result)
Enter name of new virtual device:
blah
Enter QR code to google authenticator
{
VirtualMFADevice: {
Base32StringSeed: <binary> len 64,
QRCodePNG: <binary> len 1619,
SerialNumber: "arn:aws:iam::xxxxxxxxxxxxx:mfa/blah"
}
}