Skip to content

Commit

Permalink
Update the examples with the latest functionality.
Browse files Browse the repository at this point in the history
  • Loading branch information
jltorresm committed Sep 2, 2020
1 parent 4b32572 commit a7c31ce
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
14 changes: 12 additions & 2 deletions examples/hotp/main.go
Expand Up @@ -43,7 +43,17 @@ func main() {
fmt.Printf(msg, otp36, isValid1, invalidToken, isValid2)

// If trying to validate without a key it will error out.
h = otpgo.HOTP{}
isValid, err := h.Validate("a-token")
h2 := otpgo.HOTP{}
isValid, err := h2.Validate("a-token")
fmt.Printf("Trying to validate without key, is valid: %v, error: %s\n", isValid, err)

// To export the secrets you will need to the KeyUri based on your HOTP variable.
// For this purpose an account name and an issuer are needed.
aUsername := "username@example.com"
anIssuer := "A Company"
ku := h.KeyUri(aUsername, anIssuer)

// From here you can get the plain text uri.
msg = "Exporting config for \"%s\" at \"%s\":\n\t- Plain URI --> %s\n"
fmt.Printf(msg, aUsername, anIssuer, ku.String())
}
14 changes: 12 additions & 2 deletions examples/totp/main.go
Expand Up @@ -35,7 +35,17 @@ func main() {
fmt.Printf("Validated codes:\n\t- %s -> %v\n\t- %s -> %v\n", otp1, ok, otherCode, ok2)

// If trying to validate without a key it will error out.
t = otpgo.TOTP{}
isValid, err := t.Validate("a-token")
t2 := otpgo.TOTP{}
isValid, err := t2.Validate("a-token")
fmt.Printf("Trying to validate without key, is valid: %v, error: %s\n", isValid, err)

// To export the secrets you will need to the KeyUri based on your TOTP variable.
// For this purpose an account name and an issuer are needed.
aUsername := "username@example.com"
anIssuer := "A Company"
ku := t.KeyUri(aUsername, anIssuer)

// From here you can get the plain text uri.
msg = "Exporting config for \"%s\" at \"%s\":\n\t- Plain URI --> %s\n"
fmt.Printf(msg, aUsername, anIssuer, ku.String())
}

0 comments on commit a7c31ce

Please sign in to comment.