Commit 2833f343 authored by Titan's avatar Titan Committed by 老广

otp issuer配置项 (#2133)

多机房环境中otp issuer配置
parent 3d13f3a1
...@@ -354,6 +354,9 @@ AUTH_USER_MODEL = 'users.User' ...@@ -354,6 +354,9 @@ AUTH_USER_MODEL = 'users.User'
FILE_UPLOAD_PERMISSIONS = 0o644 FILE_UPLOAD_PERMISSIONS = 0o644
FILE_UPLOAD_DIRECTORY_PERMISSIONS = 0o755 FILE_UPLOAD_DIRECTORY_PERMISSIONS = 0o755
# OTP settings
OTP_ISSUER_NAME = CONFIG.OTP_ISSUER_NAME
# Auth LDAP settings # Auth LDAP settings
AUTH_LDAP = False AUTH_LDAP = False
AUTH_LDAP_SERVER_URI = 'ldap://localhost:389' AUTH_LDAP_SERVER_URI = 'ldap://localhost:389'
......
...@@ -284,7 +284,8 @@ def generate_otp_uri(request, issuer="Jumpserver"): ...@@ -284,7 +284,8 @@ def generate_otp_uri(request, issuer="Jumpserver"):
otp_secret_key = base64.b32encode(os.urandom(10)).decode('utf-8') otp_secret_key = base64.b32encode(os.urandom(10)).decode('utf-8')
cache.set(request.session.session_key+'otp_key', otp_secret_key, 600) cache.set(request.session.session_key+'otp_key', otp_secret_key, 600)
totp = pyotp.TOTP(otp_secret_key) totp = pyotp.TOTP(otp_secret_key)
return totp.provisioning_uri(name=user.username, issuer_name=issuer), otp_secret_key otp_issuer_name = settings.OTP_ISSUER_NAME or issuer
return totp.provisioning_uri(name=user.username, issuer_name=otp_issuer_name), otp_secret_key
def check_otp_code(otp_secret_key, otp_code): def check_otp_code(otp_secret_key, otp_code):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment