Add user authentication to the Flutter app using OAuth 2.0

Flutter is Google’s cross-platform UI toolkit created to build expressive and beautiful mobile applications.

OAuth 2.0 is an industry-standard protocol for authorization. It allow users to give third-party applications access to their resources. We can see a typical example of OAuth 2.0 in action when a user tries to sign up for a third-party app using Google. OAuth 2.0 allows users to give the third-party applications access to resources, such as using their profile data on a social network platform, without needing to input their credentials on said application.

Prerequisites

You need the following installations in your machine:

Scaffold a Flutter project

Once you are done with the installation, we need to create a flutter project.

Install Dependencies

Your Flutter project requires three main dependencies:

  • http: A composable, Future-based library for making HTTP API call.
  • flutter_appauth : A wrapper package around AppAuth for Flutter. AppAuth authenticates and authorizes users.
  • fluttersecurestorage: A library used to securely persist data locally.

Configure Dependencies and Callback URL

A callback URL is a mechanism by which an authorization server communicates back to your applications.

com.auth0.flutterdemo://login-callback

Configure Android Dependencies and Callback URL

Update the android/app/build.gradle file as follows:

defaultConfig {
applicationId "com.auth0.flutterdemo"
minSdkVersion 18
targetSdkVersion 29
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
manifestPlaceholders = [
'appAuthRedirectScheme': 'com.auth0.flutterdemo'
]
}

Read more: https://tudip.com/blog-post/add-user-authentication-to-the-flutter-app-using-oauth-2-0/

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store