implement authentication redirect
This commit is contained in:
parent
9937b77c74
commit
ea5c9732ba
18
atst/domain/auth.py
Normal file
18
atst/domain/auth.py
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
from functools import wraps
|
||||||
|
from flask import g, request, redirect, url_for, session
|
||||||
|
|
||||||
|
from atst.domain.users import Users
|
||||||
|
|
||||||
|
|
||||||
|
def login_required(f):
|
||||||
|
|
||||||
|
@wraps(f)
|
||||||
|
def decorated_function(*args, **kwargs):
|
||||||
|
if session.get("user_id"):
|
||||||
|
g.user = Users.get(session.get("user_id"))
|
||||||
|
return f(*args, **kwargs)
|
||||||
|
|
||||||
|
else:
|
||||||
|
return redirect(url_for("atst.root"))
|
||||||
|
|
||||||
|
return decorated_function
|
@ -1,9 +1,11 @@
|
|||||||
from flask import Blueprint, render_template, g, redirect, session, url_for, request
|
from flask import Blueprint, render_template, g, redirect, session, url_for, request
|
||||||
|
from flask import current_app as app
|
||||||
import pendulum
|
import pendulum
|
||||||
|
|
||||||
from atst.domain.requests import Requests
|
from atst.domain.requests import Requests
|
||||||
from atst.domain.users import Users
|
from atst.domain.users import Users
|
||||||
from atst.domain.authnid.utils import parse_sdn
|
from atst.domain.authnid.utils import parse_sdn
|
||||||
|
from atst.domain.auth import login_required
|
||||||
|
|
||||||
bp = Blueprint("atst", __name__)
|
bp = Blueprint("atst", __name__)
|
||||||
|
|
||||||
@ -14,16 +16,19 @@ def root():
|
|||||||
|
|
||||||
|
|
||||||
@bp.route("/home")
|
@bp.route("/home")
|
||||||
|
@login_required
|
||||||
def home():
|
def home():
|
||||||
return render_template("home.html")
|
return render_template("home.html")
|
||||||
|
|
||||||
|
|
||||||
@bp.route("/styleguide")
|
@bp.route("/styleguide")
|
||||||
|
@login_required
|
||||||
def styleguide():
|
def styleguide():
|
||||||
return render_template("styleguide.html")
|
return render_template("styleguide.html")
|
||||||
|
|
||||||
|
|
||||||
@bp.route('/<path:path>')
|
@bp.route('/<path:path>')
|
||||||
|
@login_required
|
||||||
def catch_all(path):
|
def catch_all(path):
|
||||||
return render_template("{}.html".format(path))
|
return render_template("{}.html".format(path))
|
||||||
|
|
||||||
@ -58,8 +63,3 @@ def is_valid_certificate(request):
|
|||||||
return result
|
return result
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def construct_redirect(uuid):
|
|
||||||
access_token = app.token_manager.token(uuid)
|
|
||||||
url = f'{app.config["ATST_REDIRECT"]}?bearer-token={access_token}'
|
|
||||||
return app.make_response(redirect(url))
|
|
||||||
|
@ -46,7 +46,7 @@ _DEV_USERS = {
|
|||||||
|
|
||||||
|
|
||||||
@bp.route("/login-dev")
|
@bp.route("/login-dev")
|
||||||
def get():
|
def login_dev():
|
||||||
role = request.args.get("username", "amanda")
|
role = request.args.get("username", "amanda")
|
||||||
user_data = _DEV_USERS[role]
|
user_data = _DEV_USERS[role]
|
||||||
user = _set_user_permissions(user_data["dod_id"], user_data["atat_role"])
|
user = _set_user_permissions(user_data["dod_id"], user_data["atat_role"])
|
||||||
|
@ -6,7 +6,7 @@ AUTHNID_BASE_URL= https://localhost:8001
|
|||||||
COOKIE_SECRET = some-secret-please-replace
|
COOKIE_SECRET = some-secret-please-replace
|
||||||
SECRET = change_me_into_something_secret
|
SECRET = change_me_into_something_secret
|
||||||
SECRET_KEY = change_me_into_something_secret
|
SECRET_KEY = change_me_into_something_secret
|
||||||
CAC_URL = https://localhost:8001
|
CAC_URL = http://localhost:8000/login-redirect
|
||||||
PE_NUMBER_CSV_URL = http://c95e1ebb198426ee57b8-174bb05a294821bedbf46b6384fe9b1f.r31.cf5.rackcdn.com/penumbers.csv
|
PE_NUMBER_CSV_URL = http://c95e1ebb198426ee57b8-174bb05a294821bedbf46b6384fe9b1f.r31.cf5.rackcdn.com/penumbers.csv
|
||||||
REDIS_URI = redis://localhost:6379
|
REDIS_URI = redis://localhost:6379
|
||||||
SESSION_TTL_SECONDS = 600
|
SESSION_TTL_SECONDS = 600
|
||||||
@ -17,6 +17,5 @@ PGUSER = postgres
|
|||||||
PGPASSWORD = postgres
|
PGPASSWORD = postgres
|
||||||
PGDATABASE = atat
|
PGDATABASE = atat
|
||||||
SESSION_TYPE = redis
|
SESSION_TYPE = redis
|
||||||
SESSION_COOKIE_DOMAIN= atat.codes
|
SESSION_COOKIE_NAME=atat
|
||||||
SESSION_COOKIE_SECURE = True
|
|
||||||
SESSION_USE_SIGNER = True
|
SESSION_USE_SIGNER = True
|
||||||
|
2
config/prod.ini
Normal file
2
config/prod.ini
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
[default]
|
||||||
|
SESSION_COOKIE_SECURE=True
|
@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
<h1 class="usa-display">JEDI</h1>
|
<h1 class="usa-display">JEDI</h1>
|
||||||
|
|
||||||
<a class="usa-button" href='{{ config.get('cac_url','https://cac.atat.codes') }}'><span>Sign In with CAC</span></a>
|
<a class="usa-button" href='{{ config.get('CAC_URL','https://cac.atat.codes') }}'><span>Sign In with CAC</span></a>
|
||||||
<button class="usa-button" disabled>Sign In via MFA</button>
|
<button class="usa-button" disabled>Sign In via MFA</button>
|
||||||
{% if g.dev %}
|
{% if g.dev %}
|
||||||
<a class="usa-button usa-button-secondary" href='/login-dev'><span>DEV Login</span></a>
|
<a class="usa-button usa-button-secondary" href='/login-dev'><span>DEV Login</span></a>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user