mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-24 00:06:16 -04:00
Merge pull request #890 from GSA/login_gov_state
make state non-arbitrary
This commit is contained in:
2
.github/workflows/deploy-demo.yml
vendored
2
.github/workflows/deploy-demo.yml
vendored
@@ -57,7 +57,7 @@ jobs:
|
|||||||
NEW_RELIC_LICENSE_KEY: ${{ secrets.NEW_RELIC_LICENSE_KEY }}
|
NEW_RELIC_LICENSE_KEY: ${{ secrets.NEW_RELIC_LICENSE_KEY }}
|
||||||
NOTIFY_E2E_TEST_EMAIL: ${{ secrets.NOTIFY_E2E_TEST_EMAIL }}
|
NOTIFY_E2E_TEST_EMAIL: ${{ secrets.NOTIFY_E2E_TEST_EMAIL }}
|
||||||
NOTIFY_E2E_TEST_PASSWORD: ${{ secrets.NOTIFY_E2E_TEST_PASSWORD }}
|
NOTIFY_E2E_TEST_PASSWORD: ${{ secrets.NOTIFY_E2E_TEST_PASSWORD }}
|
||||||
LOGIN_DOT_GOV_REGISTRATION_URL: "https://secure.login.gov/openid_connect/authorize?acr_values=http%3A%2F%2Fidmanagement.gov%2Fns%2Fassurance%2Fial%2F1&client_id=urn:gov:gsa:openidconnect.profiles:sp:sso:gsa:notify-gov&nonce=01234567890123456789012345&prompt=select_account&redirect_uri=https://notify-demo.app.cloud.gov/set-up-your-profile&response_type=code&scope=openid+email&state=abcdefghijklmnopabcdefghijklmnop"
|
LOGIN_DOT_GOV_REGISTRATION_URL: "https://secure.login.gov/openid_connect/authorize?acr_values=http%3A%2F%2Fidmanagement.gov%2Fns%2Fassurance%2Fial%2F1&client_id=urn:gov:gsa:openidconnect.profiles:sp:sso:gsa:notify-gov&nonce=NONCE&prompt=select_account&redirect_uri=https://notify-demo.app.cloud.gov/set-up-your-profile&response_type=code&scope=openid+email&state=STATE"
|
||||||
|
|
||||||
with:
|
with:
|
||||||
cf_username: ${{ secrets.CLOUDGOV_USERNAME }}
|
cf_username: ${{ secrets.CLOUDGOV_USERNAME }}
|
||||||
|
|||||||
2
.github/workflows/deploy-prod.yml
vendored
2
.github/workflows/deploy-prod.yml
vendored
@@ -61,7 +61,7 @@ jobs:
|
|||||||
NEW_RELIC_LICENSE_KEY: ${{ secrets.NEW_RELIC_LICENSE_KEY }}
|
NEW_RELIC_LICENSE_KEY: ${{ secrets.NEW_RELIC_LICENSE_KEY }}
|
||||||
NOTIFY_E2E_TEST_EMAIL: ${{ secrets.NOTIFY_E2E_TEST_EMAIL }}
|
NOTIFY_E2E_TEST_EMAIL: ${{ secrets.NOTIFY_E2E_TEST_EMAIL }}
|
||||||
NOTIFY_E2E_TEST_PASSWORD: ${{ secrets.NOTIFY_E2E_TEST_PASSWORD }}
|
NOTIFY_E2E_TEST_PASSWORD: ${{ secrets.NOTIFY_E2E_TEST_PASSWORD }}
|
||||||
LOGIN_DOT_GOV_REGISTRATION_URL: "https://secure.login.gov/openid_connect/authorize?acr_values=http%3A%2F%2Fidmanagement.gov%2Fns%2Fassurance%2Fial%2F1&client_id=urn:gov:gsa:openidconnect.profiles:sp:sso:gsa:notify-gov&nonce=01234567890123456789012345&prompt=select_account&redirect_uri=https://beta.notify.gov/set-up-your-profile&response_type=code&scope=openid+email&state=abcdefghijklmnopabcdefghijklmnop"
|
LOGIN_DOT_GOV_REGISTRATION_URL: "https://secure.login.gov/openid_connect/authorize?acr_values=http%3A%2F%2Fidmanagement.gov%2Fns%2Fassurance%2Fial%2F1&client_id=urn:gov:gsa:openidconnect.profiles:sp:sso:gsa:notify-gov&nonce=NONCE&prompt=select_account&redirect_uri=https://beta.notify.gov/set-up-your-profile&response_type=code&scope=openid+email&state=STATE"
|
||||||
|
|
||||||
with:
|
with:
|
||||||
cf_username: ${{ secrets.CLOUDGOV_USERNAME }}
|
cf_username: ${{ secrets.CLOUDGOV_USERNAME }}
|
||||||
|
|||||||
2
.github/workflows/deploy.yml
vendored
2
.github/workflows/deploy.yml
vendored
@@ -62,7 +62,7 @@ jobs:
|
|||||||
NEW_RELIC_LICENSE_KEY: ${{ secrets.NEW_RELIC_LICENSE_KEY }}
|
NEW_RELIC_LICENSE_KEY: ${{ secrets.NEW_RELIC_LICENSE_KEY }}
|
||||||
NOTIFY_E2E_TEST_EMAIL: ${{ secrets.NOTIFY_E2E_TEST_EMAIL }}
|
NOTIFY_E2E_TEST_EMAIL: ${{ secrets.NOTIFY_E2E_TEST_EMAIL }}
|
||||||
NOTIFY_E2E_TEST_PASSWORD: ${{ secrets.NOTIFY_E2E_TEST_PASSWORD }}
|
NOTIFY_E2E_TEST_PASSWORD: ${{ secrets.NOTIFY_E2E_TEST_PASSWORD }}
|
||||||
LOGIN_DOT_GOV_REGISTRATION_URL: "https://secure.login.gov/openid_connect/authorize?acr_values=http%3A%2F%2Fidmanagement.gov%2Fns%2Fassurance%2Fial%2F1&client_id=urn:gov:gsa:openidconnect.profiles:sp:sso:gsa:notify-gov&nonce=01234567890123456789012345&prompt=select_account&redirect_uri=https://notify-staging.app.cloud.gov/set-up-your-profile&response_type=code&scope=openid+email&state=abcdefghijklmnopabcdefghijklmnop"
|
LOGIN_DOT_GOV_REGISTRATION_URL: "https://secure.login.gov/openid_connect/authorize?acr_values=http%3A%2F%2Fidmanagement.gov%2Fns%2Fassurance%2Fial%2F1&client_id=urn:gov:gsa:openidconnect.profiles:sp:sso:gsa:notify-gov&nonce=NONCE&prompt=select_account&redirect_uri=https://notify-staging.app.cloud.gov/set-up-your-profile&response_type=code&scope=openid+email&state=STATE"
|
||||||
|
|
||||||
with:
|
with:
|
||||||
cf_username: ${{ secrets.CLOUDGOV_USERNAME }}
|
cf_username: ${{ secrets.CLOUDGOV_USERNAME }}
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ import uuid
|
|||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from secrets import randbelow
|
from secrets import randbelow
|
||||||
|
|
||||||
|
import sqlalchemy
|
||||||
|
from flask import current_app
|
||||||
from sqlalchemy import func
|
from sqlalchemy import func
|
||||||
from sqlalchemy.orm import joinedload
|
from sqlalchemy.orm import joinedload
|
||||||
|
|
||||||
@@ -39,7 +41,17 @@ def get_login_gov_user(login_uuid, email_address):
|
|||||||
user = User.query.filter_by(login_uuid=login_uuid).first()
|
user = User.query.filter_by(login_uuid=login_uuid).first()
|
||||||
if user:
|
if user:
|
||||||
if user.email_address != email_address:
|
if user.email_address != email_address:
|
||||||
save_user_attribute(user, {"email_address": email_address})
|
try:
|
||||||
|
save_user_attribute(user, {"email_address": email_address})
|
||||||
|
except sqlalchemy.exc.IntegrityError as ie:
|
||||||
|
# We are trying to change the email address as a courtesy,
|
||||||
|
# based on the assumption that the user has somehow changed their
|
||||||
|
# address in login.gov.
|
||||||
|
# But if we cannot change the email address, at least we don't
|
||||||
|
# want to fail here, otherwise the user will be locked out.
|
||||||
|
current_app.logger.error(ie)
|
||||||
|
db.session.rollback()
|
||||||
|
|
||||||
return user
|
return user
|
||||||
# Remove this 1 July 2025, all users should have login.gov uuids by now
|
# Remove this 1 July 2025, all users should have login.gov uuids by now
|
||||||
user = User.query.filter_by(email_address=email_address).first()
|
user = User.query.filter_by(email_address=email_address).first()
|
||||||
|
|||||||
@@ -52,6 +52,15 @@ def invite_user_to_org(organization_id):
|
|||||||
current_app.config["ORGANIZATION_INVITATION_EMAIL_TEMPLATE_ID"]
|
current_app.config["ORGANIZATION_INVITATION_EMAIL_TEMPLATE_ID"]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
token = generate_token(
|
||||||
|
str(invited_org_user.email_address),
|
||||||
|
current_app.config["SECRET_KEY"],
|
||||||
|
current_app.config["DANGEROUS_SALT"],
|
||||||
|
)
|
||||||
|
url = os.environ["LOGIN_DOT_GOV_REGISTRATION_URL"]
|
||||||
|
url = url.replace("NONCE", token)
|
||||||
|
url = url.replace("STATE", token)
|
||||||
|
|
||||||
personalisation = {
|
personalisation = {
|
||||||
"user_name": (
|
"user_name": (
|
||||||
"The Notify.gov team"
|
"The Notify.gov team"
|
||||||
@@ -59,7 +68,7 @@ def invite_user_to_org(organization_id):
|
|||||||
else invited_org_user.invited_by.name
|
else invited_org_user.invited_by.name
|
||||||
),
|
),
|
||||||
"organization_name": invited_org_user.organization.name,
|
"organization_name": invited_org_user.organization.name,
|
||||||
"url": os.environ["LOGIN_DOT_GOV_REGISTRATION_URL"],
|
"url": url,
|
||||||
}
|
}
|
||||||
saved_notification = persist_notification(
|
saved_notification = persist_notification(
|
||||||
template_id=template.id,
|
template_id=template.id,
|
||||||
|
|||||||
@@ -37,10 +37,20 @@ def _create_service_invite(invited_user, invite_link_host):
|
|||||||
template = dao_get_template_by_id(template_id)
|
template = dao_get_template_by_id(template_id)
|
||||||
|
|
||||||
service = Service.query.get(current_app.config["NOTIFY_SERVICE_ID"])
|
service = Service.query.get(current_app.config["NOTIFY_SERVICE_ID"])
|
||||||
|
|
||||||
|
token = generate_token(
|
||||||
|
str(invited_user.email_address),
|
||||||
|
current_app.config["SECRET_KEY"],
|
||||||
|
current_app.config["DANGEROUS_SALT"],
|
||||||
|
)
|
||||||
|
url = os.environ["LOGIN_DOT_GOV_REGISTRATION_URL"]
|
||||||
|
url = url.replace("NONCE", token)
|
||||||
|
url = url.replace("STATE", token)
|
||||||
|
|
||||||
personalisation = {
|
personalisation = {
|
||||||
"user_name": invited_user.from_user.name,
|
"user_name": invited_user.from_user.name,
|
||||||
"service_name": invited_user.service.name,
|
"service_name": invited_user.service.name,
|
||||||
"url": os.environ["LOGIN_DOT_GOV_REGISTRATION_URL"],
|
"url": url,
|
||||||
}
|
}
|
||||||
|
|
||||||
saved_notification = persist_notification(
|
saved_notification = persist_notification(
|
||||||
|
|||||||
Reference in New Issue
Block a user