Skip to content

A Flutter package to easily integrate Auth0 into Android, iOS, and Web Flutter apps.

License

Notifications You must be signed in to change notification settings

apogee23/auth0_flutter2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A Flutter package to easily integrate Auth0 into Android, iOS, and Web Flutter apps.

Platform Support

Android iOS MacOS Web Linux Windows
✔️ ✔️ x ✔️ x x

Auth0Flutter2 is not supported on MacOS, Windows, or Linux.

Features

Integrate Auth0 authentication across mobile and web Flutter apps. Login users, logout users, and identify currently authenticated users across web and mobile.

Usage

To use this plugin, add auth0_flutter2 as a dependency in your pubspec.yaml file.

iOS and Android

Follow the iOS and Android usage instructions in the official Auth0 mobile package

Web

Add the Auth0 Javascript SPA (Single Page Application) library.

<script src="https://cdn.auth0.com/js/auth0-spa-js/1.13/auth0-spa-js.production.js"></script>

In main.dart, add a method to handle Web login callbacks.

  @override
  void initState() {
    checkForRedirectCallback();
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    .....
  }

  Future<void> checkForRedirectCallback() async {
    // Check for login callback state.
    var redirectCallbackHandled =
        await Auth0Flutter2.instance.handleWebLoginCallback(
      Uri.base.toString(),
    );

    // If callback was able to be processed, do something.
    if (redirectCallbackHandled) {
      // DO SOMETHING...
    }
  }

Example

Import the library.

import 'package:auth0_flutter2/auth0_flutter2.dart';

Then initialize the Auth0Flutter2 class in your main() method.

void main() {
  Auth0Flutter2.auth0Domain = "AUTH0_DOMAIN";
  Auth0Flutter2.auth0ClientId = "AUTH0_CLIENT_ID";
  Auth0Flutter2.redirectUri = "YOUR_APP_REDIRECT_URI";

  // Set the URL strategy for our web app. Removes 
  // trailing hash(#) to ensure login callbacks
  // will be captured and processed correctly.
  Auth0Flutter2.setPathUrlStrategy();

  runApp(const MyApp());
}

Then invoke the class methods anywhere in your Dart code.

Auth0Flutter2.instance.loginUser();
Auth0Flutter2.instance.logoutUser();
Auth0Flutter2.instance.getLoggedInUserId();

For The Love Of Open Source.

Buy Me A Coffee

About

A Flutter package to easily integrate Auth0 into Android, iOS, and Web Flutter apps.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages