2023-10-20 08:48:04 -07:00
|
|
|
import os
|
|
|
|
|
|
|
|
|
|
import requests
|
2023-10-31 12:22:06 -07:00
|
|
|
from flask import current_app, redirect, url_for
|
2020-02-03 15:08:55 +00:00
|
|
|
from flask_login import current_user
|
2016-01-06 16:40:38 +00:00
|
|
|
|
|
|
|
|
from app.main import main
|
|
|
|
|
|
2023-11-14 07:11:40 -08:00
|
|
|
# ask login.gov if we really need manual logout and what's up with one hour sessions
|
|
|
|
|
# ask login.gov how they recommend approaching dev environment
|
|
|
|
|
# ask Tim Donaworth the same for #2
|
|
|
|
|
|
|
|
|
|
|
2023-10-20 08:48:04 -07:00
|
|
|
def _sign_out_at_login_dot_gov():
|
|
|
|
|
base_url = "https://idp.int.identitysandbox.gov/openid_connect/logout?"
|
2023-10-31 12:22:06 -07:00
|
|
|
client_id = f"client_id={os.getenv('LOGIN_DOT_GOV_CLIENT_ID')}"
|
2023-11-14 07:11:40 -08:00
|
|
|
post_logout_redirect_uri = "post_logout_redirect_uri=http://localhost:6012/sign-out"
|
2023-10-20 08:48:04 -07:00
|
|
|
|
2023-10-31 12:22:06 -07:00
|
|
|
url = f"{base_url}{client_id}&{post_logout_redirect_uri}"
|
2023-10-20 09:34:39 -07:00
|
|
|
current_app.logger.info(f"url={url}")
|
2023-11-14 07:11:40 -08:00
|
|
|
|
|
|
|
|
response = requests.post(url)
|
|
|
|
|
|
|
|
|
|
# response = requests.post(url)
|
2023-10-20 09:34:39 -07:00
|
|
|
current_app.logger.info(f"login.gov response: {response.text}")
|
2023-10-20 08:48:04 -07:00
|
|
|
|
|
|
|
|
|
2023-10-20 09:34:39 -07:00
|
|
|
@main.route("/sign-out", methods=(["GET", "POST"]))
|
2016-01-06 16:40:38 +00:00
|
|
|
def sign_out():
|
2020-02-04 12:16:58 +00:00
|
|
|
# An AnonymousUser does not have an id
|
2023-11-14 07:11:40 -08:00
|
|
|
current_app.logger.info("HIT THE REGULAR SIGN OUT")
|
2020-02-04 12:16:58 +00:00
|
|
|
if current_user.is_authenticated:
|
2023-11-02 14:10:22 -07:00
|
|
|
# TODO This doesn't work yet, due to problems above.
|
|
|
|
|
current_user.sign_out()
|
2023-11-14 07:14:27 -08:00
|
|
|
|
|
|
|
|
return redirect(
|
|
|
|
|
"https://idp.int.identitysandbox.gov/openid_connect/logout?client_id=urn:gov:gsa:openidconnect.profiles:sp:sso:gsa:test_notify_gov&post_logout_redirect_uri=http://localhost:6012/sign-out" # noqa
|
|
|
|
|
)
|
2023-08-25 09:12:23 -07:00
|
|
|
return redirect(url_for("main.index"))
|
2023-11-14 07:11:40 -08:00
|
|
|
|
|
|
|
|
|
2023-11-14 07:14:27 -08:00
|
|
|
# @main.route("/sign-out-at-login-gov", methods=(["POST"]))
|
|
|
|
|
# def sign_out_at_login_gov():
|
|
|
|
|
# current_app.logger.info("SHOULD BE REDIRECTING TO LOGIN GOV")
|
|
|
|
|
# return redirect(
|
|
|
|
|
# "https://idp.int.identitysandbox.gov/openid_connect/logout?client_id=urn:gov:gsa:openidconnect.profiles:sp:sso:gsa:test_notify_gov&post_logout_redirect_uri=http://localhost:6012/sign-out"
|
|
|
|
|
# )
|