This repository has been archived on 2024-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
authentik/passbook/otp/utils.py
2019-02-25 12:29:40 +01:00

23 lines
684 B
Python

"""passbook OTP Utils"""
from django.conf import settings
from django.utils.http import urlencode
def otpauth_url(accountname, secret, issuer=None, digits=6):
"""Create otpauth according to
https://github.com/google/google-authenticator/wiki/Key-Uri-Format"""
accountname = accountname
issuer = issuer if issuer else getattr(settings, 'OTP_TOTP_ISSUER')
# Ensure that the secret parameter is the FIRST parameter of the URI, this
# allows Microsoft Authenticator to work.
query = [
('secret', secret),
('digits', digits),
('issuer', issuer),
]
return 'otpauth://totp/%s:%s?%s' % (issuer, accountname, urlencode(query))