Made some serious headway getting TOTP up and running with PAS but am stuck on the very last portion. I've got a python script using the scriptable plugin in PAS that auth's the user, and while the user/pass work just fine, calling the entered google authenticator token from the script after it has been entered into the web page is not working.
Here's the workflow:
-
Go to login page and type in the username, password, and current auth token via the google authenticator app
-
Submit the form and PAS goes to work auth'ing the user
The crazy part is that if I hard code the token variable in the pyton script to the current google auth token, and try to login fast enough so it doesn't change before I complete the login, it works just fine. However, calling it from the request namespace does not.
I have tried manually converting it to UTF-8, converting it to ascii, wrapping single quotes around it (just in case that wasn't happening), and virtually everything else I can think of. Nothing is working and I'm hoping you can help.
Here's the current script:
from ZcPassword import verify_password
from ZcPassword import totp_verify
login = credentials.get('login', None)
password = credentials.get('password', None)
#This is how I am trying to get the form variable intranet_token and though
#the auth fails, if I raise the exception, the error log shows me the 6 numbers I entered
mytoken = context.REQUEST.get('intranet_token', None)
# When I hard code the mytoken variable as described in the post it works
#mytoken = '272216'
#This exception returns the correct value of mytoken
#raise(Exception(mytoken))
if not login or not password or not mytoken or mytoken == "":
raise(Exception(f"something is none, login: {login}, token: {mytoken}"))
return (None, None)
for user in context.fetch_user_by_name(login=login):
if not user.username == login:
continue
# Check password
if not verify_password(password, user.password):
return (None, None)
# Check the totp
if not totp_verify(mytoken, user.totp_key):
return (None, None)
return (user.id, user.username)
return (None, None)
I would of course look to the ZcPassword module or the login page itself, but as I said, if I hard code the token it properly logs in, which tells me everything is working as it should. The only thing I can think of is that I am getting the form variable in a format that is not just the 6 digits I entered, and instead the error_log is simply showing me a rendered output instead of what mytoken actually is.