corpusops / bitwardentools

bitwarden python api client and additional tools like for migrating from vaultier to bitwarden (bitwarden_rs)
Other
35 stars 15 forks source link

2fa - allow populating the login data structure via callback for 2fa #18

Closed commonism closed 1 year ago

commonism commented 1 year ago

This allows supplying 2fa tokens to the login.

e.g. using pyotp

def mfa():
    totp = pyotp.TOTP(otpseed)
    return {"twoFactorToken": str(totp.now()), "twoFactorProvider": "0","twoFactorRemember": "0"}

client = Client(server, email, password, mfa_cb=mfa) 
client.sync()
commonism commented 1 year ago

As I see this allows API auth as well - maybe it's better to have this as general auth_cb which gets the login data passed for easy manipulation?

def authenticate(data: Dict[str, str]):
…
     return data

client = Client(server, email, password, auth_cb=authenticate) 
kiorky commented 1 year ago

Thanks for the contribution !

I am not sure to understand well what you mean. If it's a spelling suggestion, yes i would argue that auth_cb (both in argument and attribute) is a better alternative.

Would you mind then updating this PR as i'm more than willing to merge it !

commonism commented 1 year ago

Had some spare characters, made it authentication_cb. No docs to add this to?

kiorky commented 1 year ago

I was going to do it myself after merge, but you can of course do it yourself by adding an exemple to https://github.com/corpusops/bitwardentools/blob/main/USAGE.md (like copy/pasting/adapting what you already posted in commit message)

And also add changelog entry in https://github.com/corpusops/bitwardentools/blob/main/CHANGES.md

So i'm waiting for it, or tell me to do it myself !

commonism commented 1 year ago

just go ahead - you know how it is meant to look like

feel free to https://gist.github.com/wtbarnes/56b942641d314522094d312bbaf33a81