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.
Libraries
- auth0/auth0
- auth0/auth0_flutter_web/auth0_flutter_web
- auth0/auth0_flutter_web/src/auth0_js_interop
- auth0/auth0_flutter_web/src/js_stubs
- auth0/auth0_flutter_web/src/options
- auth0/auth0_flutter_web/src/promise_to_future_as_map_stub
- auth0/get_logged_in_user/get_logged_in_user
- auth0/get_logged_in_user/get_logged_in_user_mobile
- auth0/get_logged_in_user/get_logged_in_user_stub
- auth0/get_logged_in_user/get_logged_in_user_web
- auth0/handle_redirect_callback/handle_redirect_callback
- auth0/handle_redirect_callback/handle_redirect_callback_mobile
- auth0/handle_redirect_callback/handle_redirect_callback_stub
- auth0/handle_redirect_callback/handle_redirect_callback_web
- auth0/init_auth0/init_auth0_mobile
- auth0/init_auth0/init_auth0_web
- auth0/login_user/login_user
- auth0/login_user/login_user_mobile
- auth0/login_user/login_user_stub
- auth0/login_user/login_user_web
- auth0/logout_user/logout_user
- auth0/logout_user/logout_user_mobile
- auth0/logout_user/logout_user_stub
- auth0/logout_user/logout_user_web
- auth0_flutter2