Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions firebase_admin/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@
'create_session_cookie',
'create_user',
'delete_user',
'generate_password_reset_link',
'generate_email_verification_link',
'generate_password_reset_link',
'generate_sign_in_with_email_link',
'get_user',
'get_user_by_email',
Expand Down Expand Up @@ -464,7 +464,7 @@ def generate_password_reset_link(email, action_code_settings=None, app=None):
passed in the deep link.
app: An App instance (optional).
Returns:
link: The password reset link created by API
link: The password reset link created by the API

Raises:
ValueError: If the provided arguments are invalid
Expand All @@ -488,7 +488,7 @@ def generate_email_verification_link(email, action_code_settings=None, app=None)
passed in the deep link.
app: An App instance (optional).
Returns:
link: The email verification link created by API
link: The email verification link created by the API

Raises:
ValueError: If the provided arguments are invalid
Expand All @@ -512,7 +512,7 @@ def generate_sign_in_with_email_link(email, action_code_settings, app=None):
passed in the deep link.
app: An App instance (optional).
Returns:
link: The email sign in link created by API
link: The email sign-in link created by the API

Raises:
ValueError: If the provided arguments are invalid
Expand Down
48 changes: 48 additions & 0 deletions snippets/auth/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,54 @@ def import_without_password():
print('Error importing users:', error)
# [END import_without_password]

def init_action_code_settings():
# [START init_action_code_settings]
action_code_settings = auth.ActionCodeSettings(
url='https://www.example.com/checkout?cartId=1234',
handle_code_in_app=True,
ios_bundle_id='com.example.ios',
android_package_name='com.example.android',
android_install_app=True,
android_minimum_version='12',
dynamic_link_domain='coolapp.page.link',
)
# [END init_action_code_settings]
return action_code_settings

def password_reset_link():
action_code_settings = init_action_code_settings()
# [START password_reset_link]
email = 'user@example.com'
link = auth.generate_password_reset_link(email, action_code_settings)
# Construct password reset email from a template embedding the link, and send
# using a custom SMTP server.
send_custom_email(email, link)
# [END password_reset_link]

def email_verification_link():
action_code_settings = init_action_code_settings()
# [START email_verification_link]
email = 'user@example.com'
link = auth.generate_email_verification_link(email, action_code_settings)
# Construct email from a template embedding the link, and send
# using a custom SMTP server.
send_custom_email(email, link)
# [END email_verification_link]

def sign_in_with_email_link():
action_code_settings = init_action_code_settings()
# [START sign_in_with_email_link]
email = 'user@example.com'
link = auth.generate_sign_in_with_email_link(email, action_code_settings)
# Construct email from a template embedding the link, and send
# using a custom SMTP server.
send_custom_email(email, link)
# [END sign_in_with_email_link]

def send_custom_email(email, link):
del email
del link

initialize_sdk_with_service_account()
initialize_sdk_with_application_default()
#initialize_sdk_with_refresh_token()
Expand Down
4 changes: 2 additions & 2 deletions tests/test_token_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ def test_sign_with_iam(self):
iam_resp = '{{"signature": "{0}"}}'.format(signature)
_overwrite_iam_request(app, testutils.MockRequest(200, iam_resp))
custom_token = auth.create_custom_token(MOCK_UID, app=app).decode()
assert custom_token.endswith('.' + signature)
assert custom_token.endswith('.' + signature.rstrip('='))
self._verify_signer(custom_token, 'test-service-account')
finally:
firebase_admin.delete_app(app)
Expand Down Expand Up @@ -241,7 +241,7 @@ def test_sign_with_discovered_service_account(self):
request.response = testutils.MockResponse(
200, '{{"signature": "{0}"}}'.format(signature))
custom_token = auth.create_custom_token(MOCK_UID, app=app).decode()
assert custom_token.endswith('.' + signature)
assert custom_token.endswith('.' + signature.rstrip('='))
self._verify_signer(custom_token, 'discovered-service-account')
assert len(request.log) == 2
assert request.log[0][1]['headers'] == {'Metadata-Flavor': 'Google'}
Expand Down