Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Aug 8, 2023

Conversation

commonism
Copy link
Contributor

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
Copy link
Contributor Author

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
Copy link
Contributor

kiorky commented Aug 8, 2023

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 !

allows other login mechanisms such as totp or api key.

example:

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

client = Client(server, email, password, authentication_cb=mfa2fa)


def api_key(loginpayload):
    loginpayload.update(
        {
            "client_id": CLIENT_ID,
            "client_secret": CLIENT_SECRET,
            "scope": "api",
            "grant_type": "client_credentials"
        }
    )
    return loginpayload

client = Client(server, email, password, authentication_cb=api_key)
@commonism
Copy link
Contributor Author

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

@kiorky
Copy link
Contributor

kiorky commented Aug 8, 2023

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
Copy link
Contributor Author

commonism commented Aug 8, 2023

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

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

@kiorky kiorky merged commit d832534 into corpusops:main Aug 8, 2023
@commonism commonism deleted the 2fa branch August 8, 2023 16:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants