2023-10-20 08:48:04 -07:00
|
|
|
import os
|
|
|
|
|
import uuid
|
|
|
|
|
|
|
|
|
|
import requests
|
|
|
|
|
from flask import redirect, url_for, current_app
|
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-10-20 08:48:04 -07:00
|
|
|
def _sign_out_at_login_dot_gov():
|
|
|
|
|
|
|
|
|
|
base_url = "https://idp.int.identitysandbox.gov/openid_connect/logout?"
|
|
|
|
|
client_id = (
|
|
|
|
|
f"client_id={os.getenv('LOGIN_DOT_GOV_CLIENT_ID')}"
|
|
|
|
|
)
|
2023-10-20 09:34:39 -07:00
|
|
|
post_logout_redirect_uri = "post_logout_redirect_uri=http://localhost:6012/sign-in"
|
2023-10-20 08:48:04 -07:00
|
|
|
|
|
|
|
|
# TODO If I take this url and put it in the browser, login.gov sign out works properly
|
|
|
|
|
# TODO But with this code it results in a 404 error message and we don't sign out from login.gov
|
2023-10-20 09:34:39 -07:00
|
|
|
url = f"{base_url}&{client_id}&{post_logout_redirect_uri}"
|
|
|
|
|
current_app.logger.info(f"url={url}")
|
|
|
|
|
response = requests.post(url, headers={'User-Agent': 'Custom'})
|
|
|
|
|
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
|
|
|
|
|
if current_user.is_authenticated:
|
|
|
|
|
current_user.sign_out()
|
2023-10-20 08:48:04 -07:00
|
|
|
_sign_out_at_login_dot_gov()
|
2023-08-25 09:12:23 -07:00
|
|
|
return redirect(url_for("main.index"))
|