From 3621162ab95502f1c43d7bd67623edbee2654c21 Mon Sep 17 00:00:00 2001 From: hiranya911 Date: Tue, 19 Feb 2019 14:14:13 -0800 Subject: [PATCH 1/4] Added snippets for email action links API --- snippets/auth/index.py | 50 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/snippets/auth/index.py b/snippets/auth/index.py index 36ea949d2..16216f5c4 100644 --- a/snippets/auth/index.py +++ b/snippets/auth/index.py @@ -587,6 +587,56 @@ 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 = 'user@example.com' + 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 = 'user@example.com' + 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 = 'user@example.com' + 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): + pass + initialize_sdk_with_service_account() initialize_sdk_with_application_default() #initialize_sdk_with_refresh_token() From 35e2701cd7d47447953c17f12015fcb804e54b79 Mon Sep 17 00:00:00 2001 From: hiranya911 Date: Tue, 19 Feb 2019 14:35:41 -0800 Subject: [PATCH 2/4] Fixing a lint error; Fixing a regression caused by https://github.com/googleapis/google-auth-library-python/pull/324 --- snippets/auth/index.py | 4 +++- tests/test_token_gen.py | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/snippets/auth/index.py b/snippets/auth/index.py index 16216f5c4..8600dabc7 100644 --- a/snippets/auth/index.py +++ b/snippets/auth/index.py @@ -635,7 +635,9 @@ def sign_in_with_email_link(): # [END sign_in_with_email_link] def send_custom_email(email, display_name, link): - pass + del email + del display_name + del link initialize_sdk_with_service_account() initialize_sdk_with_application_default() diff --git a/tests/test_token_gen.py b/tests/test_token_gen.py index 52ccd172b..412ba3d0e 100644 --- a/tests/test_token_gen.py +++ b/tests/test_token_gen.py @@ -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) @@ -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'} From 335133bb34d824b39f26fe0541fdd1283ce4fd65 Mon Sep 17 00:00:00 2001 From: hiranya911 Date: Tue, 19 Feb 2019 14:49:34 -0800 Subject: [PATCH 3/4] Fixing order of exported methods --- firebase_admin/auth.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firebase_admin/auth.py b/firebase_admin/auth.py index 6a65c646f..aff761636 100644 --- a/firebase_admin/auth.py +++ b/firebase_admin/auth.py @@ -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', From 606a3fefc7f19f82d07c20f6667868a9aa7ece87 Mon Sep 17 00:00:00 2001 From: hiranya911 Date: Wed, 20 Feb 2019 12:08:17 -0800 Subject: [PATCH 4/4] Applying feedback from docs team; Updating snippets based on code review comments --- firebase_admin/auth.py | 6 +++--- snippets/auth/index.py | 24 ++++++++++-------------- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/firebase_admin/auth.py b/firebase_admin/auth.py index aff761636..984c2babd 100644 --- a/firebase_admin/auth.py +++ b/firebase_admin/auth.py @@ -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 @@ -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 @@ -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 diff --git a/snippets/auth/index.py b/snippets/auth/index.py index 8600dabc7..5bfe21f8e 100644 --- a/snippets/auth/index.py +++ b/snippets/auth/index.py @@ -603,40 +603,36 @@ def init_action_code_settings(): def password_reset_link(): action_code_settings = init_action_code_settings() - display_name = 'Example User' # [START password_reset_link] email = 'user@example.com' 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) + # 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() - display_name = 'Example User' # [START email_verification_link] email = 'user@example.com' 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) + # 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() - display_name = 'Example User' # [START sign_in_with_email_link] email = 'user@example.com' 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) + # 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, display_name, link): +def send_custom_email(email, link): del email - del display_name del link initialize_sdk_with_service_account()