Document 2fa functions

This commit is contained in:
syeopite 2021-07-16 14:25:50 -07:00
parent 2928e3e80e
commit 194d248342
No known key found for this signature in database
GPG Key ID: A73C186DA3955A1A
2 changed files with 12 additions and 4 deletions

View File

@ -447,6 +447,10 @@ def parse_link_endpoint(endpoint : JSON::Any, text : String, video_id : String)
end end
# Templates the 2fa validator page.
#
# Requires the env, user, sid and locale variables for
# generating a csrf_token and the required variables for the view.
def call_totp_validator(env, user, sid, locale) def call_totp_validator(env, user, sid, locale)
referer = URI.decode_www_form(env.get?("current_page").to_s) referer = URI.decode_www_form(env.get?("current_page").to_s)
csrf_token = generate_response(sid, {":2fa/validate"}, HMAC_KEY) csrf_token = generate_response(sid, {":2fa/validate"}, HMAC_KEY)

View File

@ -374,7 +374,7 @@ module Invidious::Routes::Account
# 2fa through OTP handling # 2fa through OTP handling
# ------------------- # -------------------
# Setup 2fa page # Templates the page to setup 2fa on an user account
def setup_2fa_page(env) def setup_2fa_page(env)
locale = env.get("preferences").as(Preferences).locale locale = env.get("preferences").as(Preferences).locale
@ -382,6 +382,10 @@ module Invidious::Routes::Account
sid = env.get? "sid" sid = env.get? "sid"
referer = get_referer(env, unroll: false) referer = get_referer(env, unroll: false)
if !user
return env.redirect referer
end
user = user.as(User) user = user.as(User)
sid = sid.as(String) sid = sid.as(String)
csrf_token = generate_response(sid, {":2fa/setup"}, HMAC_KEY) csrf_token = generate_response(sid, {":2fa/setup"}, HMAC_KEY)
@ -393,7 +397,7 @@ module Invidious::Routes::Account
return templated "user/setup_2fa" return templated "user/setup_2fa"
end end
# Setup 2fa post request. # Handles requests to setup 2fa on an user account
def setup_2fa(env) def setup_2fa(env)
locale = env.get("preferences").as(Preferences).locale locale = env.get("preferences").as(Preferences).locale
@ -430,7 +434,7 @@ module Invidious::Routes::Account
env.redirect referer env.redirect referer
end end
# Validate 2fa code endpoint # Handles requests to validate a TOTP code on an user account
def validate_2fa(env) def validate_2fa(env)
locale = env.get("preferences").as(Preferences).locale locale = env.get("preferences").as(Preferences).locale
referer = get_referer(env, unroll: false) referer = get_referer(env, unroll: false)
@ -508,7 +512,7 @@ module Invidious::Routes::Account
env.redirect referer env.redirect referer
end end
# Remove 2fa page # Templates the page to remove 2fa on an user account
def remove_2fa_page(env) def remove_2fa_page(env)
locale = env.get("preferences").as(Preferences).locale locale = env.get("preferences").as(Preferences).locale
referer = get_referer(env) referer = get_referer(env)