Skip to content

feat(auth): Update ActionCodeSettings to support link_domain and deprecate dynamic_link_domain #884

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Prev Previous commit
Next Next commit
Add handling for InvalidHostingLinkDomainError
  • Loading branch information
huwmartin committed Jun 2, 2025
commit bb1a986ed904c72e0166a852ce60133e6f16bc09
10 changes: 10 additions & 0 deletions firebase_admin/_auth_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,15 @@ def __init__(self, message, cause, http_response):
exceptions.InvalidArgumentError.__init__(self, message, cause, http_response)


class InvalidHostingLinkDomainError(exceptions.InvalidArgumentError):
"""Hosting link domain in ActionCodeSettings is not authorized."""

default_message = 'Hosting link domain specified in ActionCodeSettings is not authorized'

def __init__(self, message, cause, http_response):
exceptions.InvalidArgumentError.__init__(self, message, cause, http_response)


class InvalidIdTokenError(exceptions.InvalidArgumentError):
"""The provided ID token is not a valid Firebase ID token."""

Expand Down Expand Up @@ -427,6 +436,7 @@ def __init__(self, message, cause=None, http_response=None):
'EMAIL_NOT_FOUND': EmailNotFoundError,
'INSUFFICIENT_PERMISSION': InsufficientPermissionError,
'INVALID_DYNAMIC_LINK_DOMAIN': InvalidDynamicLinkDomainError,
'INVALID_HOSTING_LINK_DOMAIN': InvalidHostingLinkDomainError,
'INVALID_ID_TOKEN': InvalidIdTokenError,
'PHONE_NUMBER_EXISTS': PhoneNumberAlreadyExistsError,
'TENANT_NOT_FOUND': TenantNotFoundError,
Expand Down
2 changes: 2 additions & 0 deletions firebase_admin/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
'ImportUserRecord',
'InsufficientPermissionError',
'InvalidDynamicLinkDomainError',
'InvalidHostingLinkDomainError',
'InvalidIdTokenError',
'InvalidSessionCookieError',
'ListProviderConfigsPage',
Expand Down Expand Up @@ -125,6 +126,7 @@
ImportUserRecord = _user_import.ImportUserRecord
InsufficientPermissionError = _auth_utils.InsufficientPermissionError
InvalidDynamicLinkDomainError = _auth_utils.InvalidDynamicLinkDomainError
InvalidHostingLinkDomainError = _auth_utils.InvalidHostingLinkDomainError
InvalidIdTokenError = _auth_utils.InvalidIdTokenError
InvalidSessionCookieError = _token_gen.InvalidSessionCookieError
ListProviderConfigsPage = _auth_providers.ListProviderConfigsPage
Expand Down
17 changes: 17 additions & 0 deletions tests/test_user_mgt.py
Original file line number Diff line number Diff line change
Expand Up @@ -1500,6 +1500,23 @@ def test_invalid_dynamic_link(self, user_mgt_app, func):
assert excinfo.value.http_response is not None
assert excinfo.value.cause is not None

@pytest.mark.parametrize('func', [
auth.generate_sign_in_with_email_link,
auth.generate_email_verification_link,
auth.generate_password_reset_link,
])
def test_invalid_hosting_link(self, user_mgt_app, func):
resp = '{"error":{"message": "INVALID_HOSTING_LINK_DOMAIN: Because of this reason."}}'
_instrument_user_manager(user_mgt_app, 500, resp)
with pytest.raises(auth.InvalidHostingLinkDomainError) as excinfo:
func('test@test.com', MOCK_ACTION_CODE_SETTINGS, app=user_mgt_app)
assert isinstance(excinfo.value, exceptions.InvalidArgumentError)
assert str(excinfo.value) == ('Hosting link domain specified in ActionCodeSettings is '
'not authorized (INVALID_HOSTING_LINK_DOMAIN). Because '
'of this reason.')
assert excinfo.value.http_response is not None
assert excinfo.value.cause is not None

@pytest.mark.parametrize('func', [
auth.generate_sign_in_with_email_link,
auth.generate_email_verification_link,
Expand Down