Skip to content

Commit 5c5c0e0

Browse files
awolfdenAdam Wolfman
and
Adam Wolfman
authored
Update session management logic and readme (#8)
* Update session management logic and readme * Remove print * Update base session variables Co-authored-by: Adam Wolfman <[email protected]>
1 parent 0f37015 commit 5c5c0e0

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

python-flask-mfa-example/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ An example Flask application demonstrating how to use the [WorkOS MFA API](https
105105

106106
TOTP: This type of authentication requires the use of a 3rd party authentication app (1Password, Authy, Google Authenticator, Microsoft Authenticator, Duo, etc). Scan the QR code from the Factor Details page to create the corresponding factor in the 3rd party app, then enter the time-based password when prompted in this MFA application.
107107

108-
108+
TOTP NOTE - Since all storage is being done via browser cookies, only 1 TOTP type connection can be added at a time to this app due to limitations on the size of the cookies that browsers can store. This is due to the size of the QR code.
109109

110110
## Need help?
111111

python-flask-mfa-example/app.py

+10-6
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,14 @@
1818

1919
@app.route("/")
2020
def home():
21-
if session["factor_list"]:
21+
if session.get("factor_list") == None:
22+
session["factor_list"] = []
23+
session["current_factor_qr"] = ''
24+
session["phone_number"] = ''
25+
26+
if session["factor_list"] != None:
2227
return render_template("list_factors.html", factors=session["factor_list"])
28+
2329
return render_template(
2430
"list_factors.html",
2531
)
@@ -48,8 +54,9 @@ def enroll_factor():
4854
new_factor = workos.client.mfa.enroll_factor(
4955
type=factor_type, totp_issuer=totp_issuer, totp_user=totp_user
5056
)
51-
57+
print(new_factor)
5258
session["factor_list"].append(new_factor)
59+
print(session['factor_list'])
5360
session.modified = True
5461
return redirect("/")
5562

@@ -120,8 +127,5 @@ def verify_factor():
120127

121128
@app.route("/clear_session", methods=["GET"])
122129
def clear_session():
123-
session["factor_list"] = []
124-
session["challenge_id"] = ""
125-
session["current_factor"] = ""
126-
session["current_factor_type"] = ""
130+
session.clear()
127131
return redirect("/")

0 commit comments

Comments
 (0)