LastPass Authenticator to KeePassXC OTP URIs | Patryk Adamczyk's Log

Recently I wanted to try KeePassXC stuff for my passwords because why not. And I noticed that You can do One Time Password stuff in there. So I wanted to give it a shot.

What I learned from it is that KeePass is pretty nice. And Microslop Authenticator is garbage (good that I don't use it much).

Anyway so I mostly used LastPass Authenticator for my OTP needs and few things that I couldn't I used Microslop Authenticator. From Microslop Authenticator you cant export it at all. So this is dead end. But from LastPass Authenticator you can.

I made simple nushell script that helped me to convert entries from exported JSON into otp:// uri that is used in KeePassXC when you try to setup any OTP.

OTP uri is practically something like this: otpauth://(auth_type)/(issuer):(username)?secret=($secret)&period=($timeStep)&digits=($digits)&issuer=($issuer)&algorithm=(algorithm). I think it can have some more fields if needed but thats all needed for LastPass Authenticator convert.

Anyway so my script look like this:

#!/usr/bin/env nu

# Load file
let file = open "export.json"

# Folders
let folders = [
    "Other accounts"
    "Favorites"
]

# Process
$file
| get accounts
| each {|acc|
    # Acc has these fields
    # - accountID
    # - lmiUserId
    # - issuerName
    # - originalIssuerName
    # - userName
    # - originalUserName
    # - pushNotification
    # - secret
    # - timeStep
    # - digits
    # - creationTimestamp
    # - isFavorite
    # - algorithm
    # - folderData/folderId
    # - folderData/position
    "totp" | let auth_type
    $acc.originalIssuerName | url encode | let issuer
    $acc.originalUserName | url encode | let username
    $"otpauth://($auth_type)/($issuer):($username)?secret=($acc.secret)&period=($acc.timeStep)&digits=($acc.digits)&issuer=($issuer)&algorithm=($acc.algorithm)" | let uri
    $folders | get ($acc.folderData.folderId | into int) | let folder
    {"issuerName": $acc.issuerName, "userName": $acc.userName, "favorite": $acc.isFavorite, "folder": $folder, "uri": $uri} | let result
    $result | to json | print
    $result
}

I used this script to mostly just manually add these to my KeePassXC DB. So I just printed stuff to stdout to just read it manually and copy paste. If you want you could probably use keepassxc cli to automate it fully.

If you want to use this script, it should work in any new enough nushell version (in few versions older this pipelined let syntax didn't exist).