Hello,
I’m using this code for my Login page. It works fine if I remove the “audience” parameter, however, as soon as I add it to make sure I can call my API the retrieval of the access token gives a BadRequest.
class LoginPage extends StatefulWidget {
const LoginPage({super.key});
@override
State<LoginPage> createState() => _LoginPageState();
}
class _LoginPageState extends State<LoginPage> {
final Auth0Web _auth0web = Auth0Web("{domain}", "{ClientId}");
Future<void> authenticate() async {
try {
return _auth0web.loginWithRedirect(audience: "http://localhost:7145/", redirectUrl: "http://localhost:3000");
} catch (e) {
print(e);
}
}
@override
Widget build(BuildContext context) {
var localizations = getLocalizations(context);
return PlatformScaffold(
appBar: PlatformAppBar(
title: Text(localizations.lbl_login),
material: (context, platform) => MaterialAppBarData(centerTitle: true),
backgroundColor: ColorConfig.appBarColor.withOpacity(1),
),
body: Stack(
alignment: Alignment.center,
children: [
ResponsiveRowColumn(
layout: ResponsiveRowColumnType.COLUMN,
children: [
ResponsiveRowColumnItem(
child: Expanded(
child: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [
ColorConfig.authScreensGradientFrom.withOpacity(1),
ColorConfig.authScreensGradientTo.withOpacity(1),
],
),
),
),
),
),
],
),
ResponsiveRowColumn(
layout: ResponsiveRowColumnType.COLUMN,
columnMainAxisAlignment: MainAxisAlignment.center,
children: [
ResponsiveRowColumnItem(
child: SingleChildScrollView(
child: PlatformElevatedButton(
cupertino: (context, platform) => CupertinoElevatedButtonData(
color: ColorConfig.black,
),
material: (context, platform) => MaterialElevatedButtonData(
style: ElevatedButton.styleFrom(
backgroundColor: ColorConfig.black,
fixedSize: const Size(250, 50),
),
),
onPressed: authenticate,
child: Text(localizations.lbl_login),
),
),
)
],
),
],
),
);
}
@override
void initState() {
super.initState();
var authService = ServiceContainer.instance.getSingleton<AuthService>(AuthService.instanceName);
_auth0web.onLoad().then(
(credentials) => setState(
() {
print("credentials not empty ${credentials != null}");
if (credentials != null) {
authService.writeUserCredentialsToCache(credentials);
context.go("/");
}
},
),
);
}
}
I know what a BadRequest means. My real question is, what data am I missing? I can’t seem to find anything in the docs.
Thanks for the help in advance,
Michael