Skip to content
This repository has been archived by the owner on Jul 5, 2024. It is now read-only.

Commit

Permalink
Add fallbacks for token name if OriginalName unset
Browse files Browse the repository at this point in the history
Will use Name if it is available, and otherwise will use UniqueID, which
is not descriptive but should always be available.

Should fix one of the complaints reported in #1.
  • Loading branch information
alexzorin committed Jul 29, 2019
1 parent b6a562b commit 66bacad
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions cmd/authy-export/authy-export.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func main() {
for _, tok := range tokensResponse.AuthenticatorTokens {
decrypted, err := tok.Decrypt(string(pp))
if err != nil {
log.Printf("Failed to decrypt token %s: %v", tok.OriginalName, err)
log.Printf("Failed to decrypt token %s: %v", tok.Description(), err)
continue
}

Expand All @@ -80,7 +80,7 @@ func main() {
u := url.URL{
Scheme: "otpauth",
Host: "totp",
Path: tok.OriginalName,
Path: tok.Description(),
RawQuery: params.Encode(),
}
fmt.Println(u.String())
Expand Down
12 changes: 12 additions & 0 deletions objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,3 +182,15 @@ func (t AuthenticatorToken) Decrypt(passphrase string) (string, error) {
}
return strings.ToUpper(string(buf)), nil
}

// Description returns OriginalName if not empty, otherwise Name,
// otherwise `Token-{UniqueID}`.
func (t AuthenticatorToken) Description() string {
if t.OriginalName != "" {
return t.OriginalName
}
if t.Name != "" {
return t.Name
}
return "Token-" + t.UniqueID
}

0 comments on commit 66bacad

Please sign in to comment.