Skip to content

Added snippets for email action links API #264

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
merged 4 commits into from
Feb 20, 2019
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion 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
52 changes: 52 additions & 0 deletions snippets/auth/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,58 @@ 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()
display_name = 'Example User'
# [START password_reset_link]
email = '[email protected]'
link = auth.generate_password_reset_link(email, action_code_settings)
# Construct password reset email template, embed the link and send
# using custom SMTP server.
send_custom_email(email, display_name, link)
# [END password_reset_link]

def email_verification_link():
action_code_settings = init_action_code_settings()
display_name = 'Example User'
# [START email_verification_link]
email = '[email protected]'
link = auth.generate_email_verification_link(email, action_code_settings)
# Construct email verification template, embed the link and send
# using custom SMTP server.
send_custom_email(email, display_name, link)
# [END email_verification_link]

def sign_in_with_email_link():
action_code_settings = init_action_code_settings()
display_name = 'Example User'
# [START sign_in_with_email_link]
email = '[email protected]'
link = auth.generate_sign_in_with_email_link(email, action_code_settings)
# Construct sign-in with email link template, embed the link and send
# using custom SMTP server.
send_custom_email(email, display_name, link)
# [END sign_in_with_email_link]

def send_custom_email(email, display_name, link):
del email
del display_name
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