|
17 | 17 | package com.google.firebase.snippets;
|
18 | 18 |
|
19 | 19 | import com.google.common.io.BaseEncoding;
|
| 20 | +import com.google.firebase.auth.ActionCodeSettings; |
20 | 21 | import com.google.firebase.auth.ErrorInfo;
|
21 | 22 | import com.google.firebase.auth.ExportedUserRecord;
|
22 | 23 | import com.google.firebase.auth.FirebaseAuth;
|
@@ -596,4 +597,74 @@ public void importWithoutPassword() {
|
596 | 597 | }
|
597 | 598 | // [END import_without_password]
|
598 | 599 | }
|
| 600 | + |
| 601 | + public ActionCodeSettings initActionCodeSettings() { |
| 602 | + // [START init_action_code_settings] |
| 603 | + ActionCodeSettings actionCodeSettings = ActionCodeSettings.builder() |
| 604 | + .setUrl("https://www.example.com/checkout?cartId=1234") |
| 605 | + .setHandleCodeInApp(true) |
| 606 | + .setIosBundleId("com.example.ios") |
| 607 | + .setAndroidPackageName("com.example.android") |
| 608 | + .setAndroidInstallApp(true) |
| 609 | + .setAndroidMinimumVersion("12") |
| 610 | + .setDynamicLinkDomain("coolapp.page.link") |
| 611 | + .build(); |
| 612 | + // [END init_action_code_settings] |
| 613 | + return actionCodeSettings; |
| 614 | + } |
| 615 | + |
| 616 | + public void generatePasswordResetLink() { |
| 617 | + final ActionCodeSettings actionCodeSettings = initActionCodeSettings(); |
| 618 | + final String displayName = "Example User"; |
| 619 | + // [START password_reset_link] |
| 620 | + String email = "[email protected]"; |
| 621 | + try { |
| 622 | + String link = FirebaseAuth.getInstance().generatePasswordResetLink( |
| 623 | + email, actionCodeSettings); |
| 624 | + // Construct email verification template, embed the link and send |
| 625 | + // using custom SMTP server. |
| 626 | + sendCustomPasswordResetEmail(email, displayName, link); |
| 627 | + } catch (FirebaseAuthException e) { |
| 628 | + System.out.println("Error generating email link: " + e.getMessage()); |
| 629 | + } |
| 630 | + // [END password_reset_link] |
| 631 | + } |
| 632 | + |
| 633 | + public void generateEmailVerificationLink() { |
| 634 | + final ActionCodeSettings actionCodeSettings = initActionCodeSettings(); |
| 635 | + final String displayName = "Example User"; |
| 636 | + // [START email_verification_link] |
| 637 | + String email = "[email protected]"; |
| 638 | + try { |
| 639 | + String link = FirebaseAuth.getInstance().generateEmailVerificationLink( |
| 640 | + email, actionCodeSettings); |
| 641 | + // Construct email verification template, embed the link and send |
| 642 | + // using custom SMTP server. |
| 643 | + sendCustomPasswordResetEmail(email, displayName, link); |
| 644 | + } catch (FirebaseAuthException e) { |
| 645 | + System.out.println("Error generating email link: " + e.getMessage()); |
| 646 | + } |
| 647 | + // [END email_verification_link] |
| 648 | + } |
| 649 | + |
| 650 | + public void generateSignInWithEmailLink() { |
| 651 | + final ActionCodeSettings actionCodeSettings = initActionCodeSettings(); |
| 652 | + final String displayName = "Example User"; |
| 653 | + // [START sign_in_with_email_link] |
| 654 | + String email = "[email protected]"; |
| 655 | + try { |
| 656 | + String link = FirebaseAuth.getInstance().generateSignInWithEmailLink( |
| 657 | + email, actionCodeSettings); |
| 658 | + // Construct email verification template, embed the link and send |
| 659 | + // using custom SMTP server. |
| 660 | + sendCustomPasswordResetEmail(email, displayName, link); |
| 661 | + } catch (FirebaseAuthException e) { |
| 662 | + System.out.println("Error generating email link: " + e.getMessage()); |
| 663 | + } |
| 664 | + // [END sign_in_with_email_link] |
| 665 | + } |
| 666 | + |
| 667 | + // Place holder method to make the compiler happy. This is referenced by all email action |
| 668 | + // link snippets. |
| 669 | + private void sendCustomPasswordResetEmail(String email, String displayName, String link) {} |
599 | 670 | }
|
0 commit comments