Authentication of Instagram with Firebase and Flutter

0
424

Authentication of Instagram with Firebase and Flutter – Four federated Identity Providers are supported out-of-the-box by Firebase Authentication, making authentication with Google, Facebook, Twitter, and GitHub super simple. In a web app, for example, all you need to sign in with Google for your Firebase users is:

var google = new firebase.auth.GoogleAuthProvider();

firebase.auth().signInWithPopup(google);

However, to allow your users to sign in to your Firebase app, you can be interested in using other Identity Providers. Instagram, for example, can be a nice alternative, especially if you intend to use the Instagram API to let users share their Instagram images as well.

It is possible to use Identity Providers for which Firebase does not have built-in support, but a bit more code and a server are needed. Let’s go through the steps needed to incorporate Instagram Sign-In into a web application for Firebase. Instagram uses OAuth 2.0 to sign in, so this post can also help you connect with other providers of OAuth 2.0 identity, such as LinkedIn.

Design Overview

Instagram supports OAuth 2.0 as its primary way of approving apps and accessing user data that includes the identity of the Instagram user. You need to make the user go through the flow of the OAuth 2.0 auth code and give your app access. This is how the flow of OAuth 2.0 goes:

First, the user must be routed to Instagram’s authorization endpoint, which will provide the user with a consent screen when they are first asked to allow access to your app. In a pop-up window, we’ll do that.

Upon approving your software, users will be routed with an authentication code back to your domain. You can swap the authentication code on the server-side for an access token using the credentials of your Instagram app. Instagram will also return the user ID in the process of exchanging the authentic code (this sometimes requires an additional request with other OAuth 2.0 providers like LinkedIn).

On the server, we will generate a Firebase custom auth token once we have retrieved the Instagram user data. This token will allow the user to use the signInWithCustomToken method to sign in to Firebase in our web app.

We will also pass on the user profile details we received from Instagram, such as the show name and the picture URL so that we can update the client’s Firebase profile – Note: Instagram does not include the user’s email, so we will have a Firebase account without an email, which is all right. We close the popup until done and Voila! Your user logs in to Firebase with their Instagram account’s profile information.

Register your app with Instagram

On your web app, you will need to add a button that starts the Instagram authentication flow. You will first need to register your application on the Instagram Developers console before we do this so that we can get your app credentials that are needed for OAuth 2.0.0.

Setup:

  1. Build a Developer Account for Facebook.
  2. Instagram App setup.
  3. Add the Flutter App to Firebase.

Idea:

  1. Open the Web Display Authorization Pane.
  2. Invoke the Cloud Function and log in.

Code:

Part 1: Flutter App

  1. Dependencies to install review flutter, HTTP, firebase auth.
  2. Build a Tab for login.
  3. Build a screen for Splash.
  4. Build a home page Demo.
  5. Edit a file named main. dart.

Part 2: Cloud Function

  1. Start off with Cloud Functions.
  2. Firebase-admin, firebase-functions, and qs are installed.
  3. To get a short-lived access token, exchange code.
  4. Short-lived access-token swap for long-lived access-token. (Optional)
  5. Get Instagram User Info.
  6. Add a Cloud Firestore Customer.
  7. Build Instagram User Id Custom Token with ( Custom Token is used to sign in the user in App ).

See also:

 

Disclosure: This post can contain affiliate links, which means that if you click a link and buy anything we suggested, we may earn a fee. Read more about Affiliate disclosure here.


We believe and sincerely hope that this post was helpful to you, please show your support by sharing it with your families, acquaintances, friends, and relatives who might be in a dire need of this help-guide via Facebook, Twitter, as well as on Instagram platform using the social buttons on this page.


Copyright And Warning: Published contents (including posts and media) on this blog may not be reproduced, redistributed, republished either in whole or in part without due permission or acknowledgment from the Quick News Ng administrator.

The blog posts and other content on this blog is written and published with good intentions. If you own any of the content and believe that your copyright was violated or infringed, please ensure you contact us via [coolieecoldex(at)gmail.com] to file a complaint, and actions will be taken with an immediate effect.

LEAVE A REPLY

Please enter your comment!
Please enter your name here