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:
- Build a Developer Account for Facebook.
- Instagram App setup.
- Add the Flutter App to Firebase.
Idea:
- Open the Web Display Authorization Pane.
- Invoke the Cloud Function and log in.
Code:
Part 1: Flutter App
- Dependencies to install review flutter, HTTP, firebase auth.
- Build a Tab for login.
- Build a screen for Splash.
- Build a home page Demo.
- Edit a file named main. dart.
Part 2: Cloud Function
- Start off with Cloud Functions.
- Firebase-admin, firebase-functions, and qs are installed.
- To get a short-lived access token, exchange code.
- Short-lived access-token swap for long-lived access-token. (Optional)
- Get Instagram User Info.
- Add a Cloud Firestore Customer.
- Build Instagram User Id Custom Token with ( Custom Token is used to sign in the user in App ).
See also:
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 Quicknewsng 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.