A Flutter package to easily integrate Auth0 into Android, iOS, and Web Flutter apps.
Android | iOS | MacOS | Web | Linux | Windows |
---|---|---|---|---|---|
✔️ | ✔️ | x | ✔️ | x | x |
Auth0Flutter2 is not supported on MacOS, Windows, or Linux.
Integrate Auth0 authentication across mobile and web Flutter apps. Login users, logout users, and identify currently authenticated users across web and mobile.
To use this plugin, add auth0_flutter2
as a dependency in your pubspec.yaml file.
Follow the iOS and Android usage instructions in the official Auth0 mobile package
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...
}
}
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();