https://pub.dev/packages/auth0_spa_dart
Dart wrapper for auth0-spa-js
Add the following to your index.html:
<script src="https://cdn.auth0.com/js/auth0-spa-js/1.19/auth0-spa-js.production.js"></script>
final client = await createAuth0Client(
clientId: clientId,
domain: domain,
useRefreshTokens: true, // default = false
cacheLocation: "localstorage" // default = "memory"
);
Use "localstorage" for cacheLocation to persist tokens across refreshes and sessions.
await client.loginWithPopup();
await client.loginWithRedirect();
final token = await client.getTokenSilently(
detailedResponse: true // default = false.
);
If detailedResponse is false, it returns only the accessToken as a string. Otherwise, it returns:
{
"id_token": "...",
"access_token": "...",
"expires_in": "..."
}
await client.isAuthenticated();
Feel free contribute. This project is still in its infancy, so it will be informal unless it takes off.