What is the purpose of this code in Firebase auth?











up vote
0
down vote

favorite












I looked at the FirebaseUI sign-in methods. on the first page of the explanation there is a "Sign in with a pre-built UI" as shown here: Easily add sign-in to your Android app with FirebaseUI. This page contains the following code:



// Choose authentication providers
List<AuthUI.IdpConfig> providers = Arrays.asList(
new AuthUI.IdpConfig.EmailBuilder().build(),
new AuthUI.IdpConfig.PhoneBuilder().build(),
new AuthUI.IdpConfig.GoogleBuilder().build(),
new AuthUI.IdpConfig.FacebookBuilder().build(),
new AuthUI.IdpConfig.TwitterBuilder().build());

// Create and launch sign-in intent
startActivityForResult(
AuthUI.getInstance()
.createSignInIntentBuilder()
.setAvailableProviders(providers)
.build(),
RC_SIGN_IN);


And then



@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);

if (requestCode == RC_SIGN_IN) {
IdpResponse response = IdpResponse.fromResultIntent(data);

if (resultCode == RESULT_OK) {
// Successfully signed in
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
// ...
} else {
// Sign in failed. If response is null the user canceled the
// sign-in flow using the back button. Otherwise check
// response.getError().getErrorCode() and handle the error.
// ...
}
}
}


But, when I look at their example of the how to authenticate with phone via SMS, this code is no where to be seen, yet the verification works.
The phone authentication code can be seen in their snippet:
PhoneAuthActivity.java



So when do I need to use this code and when not? What is the purpose of this part?










share|improve this question


























    up vote
    0
    down vote

    favorite












    I looked at the FirebaseUI sign-in methods. on the first page of the explanation there is a "Sign in with a pre-built UI" as shown here: Easily add sign-in to your Android app with FirebaseUI. This page contains the following code:



    // Choose authentication providers
    List<AuthUI.IdpConfig> providers = Arrays.asList(
    new AuthUI.IdpConfig.EmailBuilder().build(),
    new AuthUI.IdpConfig.PhoneBuilder().build(),
    new AuthUI.IdpConfig.GoogleBuilder().build(),
    new AuthUI.IdpConfig.FacebookBuilder().build(),
    new AuthUI.IdpConfig.TwitterBuilder().build());

    // Create and launch sign-in intent
    startActivityForResult(
    AuthUI.getInstance()
    .createSignInIntentBuilder()
    .setAvailableProviders(providers)
    .build(),
    RC_SIGN_IN);


    And then



    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == RC_SIGN_IN) {
    IdpResponse response = IdpResponse.fromResultIntent(data);

    if (resultCode == RESULT_OK) {
    // Successfully signed in
    FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
    // ...
    } else {
    // Sign in failed. If response is null the user canceled the
    // sign-in flow using the back button. Otherwise check
    // response.getError().getErrorCode() and handle the error.
    // ...
    }
    }
    }


    But, when I look at their example of the how to authenticate with phone via SMS, this code is no where to be seen, yet the verification works.
    The phone authentication code can be seen in their snippet:
    PhoneAuthActivity.java



    So when do I need to use this code and when not? What is the purpose of this part?










    share|improve this question
























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I looked at the FirebaseUI sign-in methods. on the first page of the explanation there is a "Sign in with a pre-built UI" as shown here: Easily add sign-in to your Android app with FirebaseUI. This page contains the following code:



      // Choose authentication providers
      List<AuthUI.IdpConfig> providers = Arrays.asList(
      new AuthUI.IdpConfig.EmailBuilder().build(),
      new AuthUI.IdpConfig.PhoneBuilder().build(),
      new AuthUI.IdpConfig.GoogleBuilder().build(),
      new AuthUI.IdpConfig.FacebookBuilder().build(),
      new AuthUI.IdpConfig.TwitterBuilder().build());

      // Create and launch sign-in intent
      startActivityForResult(
      AuthUI.getInstance()
      .createSignInIntentBuilder()
      .setAvailableProviders(providers)
      .build(),
      RC_SIGN_IN);


      And then



      @Override
      protected void onActivityResult(int requestCode, int resultCode, Intent data) {
      super.onActivityResult(requestCode, resultCode, data);

      if (requestCode == RC_SIGN_IN) {
      IdpResponse response = IdpResponse.fromResultIntent(data);

      if (resultCode == RESULT_OK) {
      // Successfully signed in
      FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
      // ...
      } else {
      // Sign in failed. If response is null the user canceled the
      // sign-in flow using the back button. Otherwise check
      // response.getError().getErrorCode() and handle the error.
      // ...
      }
      }
      }


      But, when I look at their example of the how to authenticate with phone via SMS, this code is no where to be seen, yet the verification works.
      The phone authentication code can be seen in their snippet:
      PhoneAuthActivity.java



      So when do I need to use this code and when not? What is the purpose of this part?










      share|improve this question













      I looked at the FirebaseUI sign-in methods. on the first page of the explanation there is a "Sign in with a pre-built UI" as shown here: Easily add sign-in to your Android app with FirebaseUI. This page contains the following code:



      // Choose authentication providers
      List<AuthUI.IdpConfig> providers = Arrays.asList(
      new AuthUI.IdpConfig.EmailBuilder().build(),
      new AuthUI.IdpConfig.PhoneBuilder().build(),
      new AuthUI.IdpConfig.GoogleBuilder().build(),
      new AuthUI.IdpConfig.FacebookBuilder().build(),
      new AuthUI.IdpConfig.TwitterBuilder().build());

      // Create and launch sign-in intent
      startActivityForResult(
      AuthUI.getInstance()
      .createSignInIntentBuilder()
      .setAvailableProviders(providers)
      .build(),
      RC_SIGN_IN);


      And then



      @Override
      protected void onActivityResult(int requestCode, int resultCode, Intent data) {
      super.onActivityResult(requestCode, resultCode, data);

      if (requestCode == RC_SIGN_IN) {
      IdpResponse response = IdpResponse.fromResultIntent(data);

      if (resultCode == RESULT_OK) {
      // Successfully signed in
      FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
      // ...
      } else {
      // Sign in failed. If response is null the user canceled the
      // sign-in flow using the back button. Otherwise check
      // response.getError().getErrorCode() and handle the error.
      // ...
      }
      }
      }


      But, when I look at their example of the how to authenticate with phone via SMS, this code is no where to be seen, yet the verification works.
      The phone authentication code can be seen in their snippet:
      PhoneAuthActivity.java



      So when do I need to use this code and when not? What is the purpose of this part?







      android firebase firebase-authentication






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 21 at 22:28









      TTnote

      1799




      1799
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          2
          down vote



          accepted










          There are two main ways to implement Firebase Authentication:




          1. Use the so-called headless API and build your own API and flows on top of that.

          2. Use FirebaseUI, which is a UI library that (in this case) encapsulates the Firebase Authentication sign-in flow. It calls the Firebase Authentication API under the hood, as you can see in its open source implementation.


          The first snippet you showed configures FirebaseUI, specifically saying what providers (Google, Facebook, Email+Password, Phone, Twitter) are enabled and then starting an activity to kick off the flow.



          The second snippet uses the Firebase Authentication API directly to implement a part of the authentication flow.



          If you're using FirebaseUI, follow the documentation for configuring phone number auth in its repo. As far as I can see there, this doesn't require the onActivityResult you shared. Most likely that flow is already encapsulated in FirebaseUI itself.






          share|improve this answer





















            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














             

            draft saved


            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53421321%2fwhat-is-the-purpose-of-this-code-in-firebase-auth%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            2
            down vote



            accepted










            There are two main ways to implement Firebase Authentication:




            1. Use the so-called headless API and build your own API and flows on top of that.

            2. Use FirebaseUI, which is a UI library that (in this case) encapsulates the Firebase Authentication sign-in flow. It calls the Firebase Authentication API under the hood, as you can see in its open source implementation.


            The first snippet you showed configures FirebaseUI, specifically saying what providers (Google, Facebook, Email+Password, Phone, Twitter) are enabled and then starting an activity to kick off the flow.



            The second snippet uses the Firebase Authentication API directly to implement a part of the authentication flow.



            If you're using FirebaseUI, follow the documentation for configuring phone number auth in its repo. As far as I can see there, this doesn't require the onActivityResult you shared. Most likely that flow is already encapsulated in FirebaseUI itself.






            share|improve this answer

























              up vote
              2
              down vote



              accepted










              There are two main ways to implement Firebase Authentication:




              1. Use the so-called headless API and build your own API and flows on top of that.

              2. Use FirebaseUI, which is a UI library that (in this case) encapsulates the Firebase Authentication sign-in flow. It calls the Firebase Authentication API under the hood, as you can see in its open source implementation.


              The first snippet you showed configures FirebaseUI, specifically saying what providers (Google, Facebook, Email+Password, Phone, Twitter) are enabled and then starting an activity to kick off the flow.



              The second snippet uses the Firebase Authentication API directly to implement a part of the authentication flow.



              If you're using FirebaseUI, follow the documentation for configuring phone number auth in its repo. As far as I can see there, this doesn't require the onActivityResult you shared. Most likely that flow is already encapsulated in FirebaseUI itself.






              share|improve this answer























                up vote
                2
                down vote



                accepted







                up vote
                2
                down vote



                accepted






                There are two main ways to implement Firebase Authentication:




                1. Use the so-called headless API and build your own API and flows on top of that.

                2. Use FirebaseUI, which is a UI library that (in this case) encapsulates the Firebase Authentication sign-in flow. It calls the Firebase Authentication API under the hood, as you can see in its open source implementation.


                The first snippet you showed configures FirebaseUI, specifically saying what providers (Google, Facebook, Email+Password, Phone, Twitter) are enabled and then starting an activity to kick off the flow.



                The second snippet uses the Firebase Authentication API directly to implement a part of the authentication flow.



                If you're using FirebaseUI, follow the documentation for configuring phone number auth in its repo. As far as I can see there, this doesn't require the onActivityResult you shared. Most likely that flow is already encapsulated in FirebaseUI itself.






                share|improve this answer












                There are two main ways to implement Firebase Authentication:




                1. Use the so-called headless API and build your own API and flows on top of that.

                2. Use FirebaseUI, which is a UI library that (in this case) encapsulates the Firebase Authentication sign-in flow. It calls the Firebase Authentication API under the hood, as you can see in its open source implementation.


                The first snippet you showed configures FirebaseUI, specifically saying what providers (Google, Facebook, Email+Password, Phone, Twitter) are enabled and then starting an activity to kick off the flow.



                The second snippet uses the Firebase Authentication API directly to implement a part of the authentication flow.



                If you're using FirebaseUI, follow the documentation for configuring phone number auth in its repo. As far as I can see there, this doesn't require the onActivityResult you shared. Most likely that flow is already encapsulated in FirebaseUI itself.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 22 at 0:59









                Frank van Puffelen

                221k25362387




                221k25362387






























                     

                    draft saved


                    draft discarded



















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53421321%2fwhat-is-the-purpose-of-this-code-in-firebase-auth%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    What visual should I use to simply compare current year value vs last year in Power BI desktop

                    Alexandru Averescu

                    Trompette piccolo