loginFor method
Implementation
Future loginFor(String userFlow, BuildContext context, {String hint = ''}) async {
// Make sure you encode these if needed here or before passing
user_flow = userFlow;
final encodedRedirectUri = Uri.encodeComponent(redirectUri);
encodedScope = Uri.encodeComponent(scope);
final authURL =
'https://astroconnect.b2clogin.com/astroconnect.onmicrosoft.com/oauth2/v2.0/authorize?p=$userFlow'
'&client_id=$clientId'
'&nonce=defaultNonce'
'&redirect_uri=$encodedRedirectUri'
'&scope=$encodedScope'
'&response_type=code'
'&prompt=login'
'&login_hint=$hint';
print("Auth URL: $authURL");
try {
await FlutterWebAuth2.authenticate(
url: authURL,
callbackUrlScheme: Uri.parse(redirectUri).scheme,
options: const FlutterWebAuth2Options(useWebview: false),
);
} catch (e) {
if (e is PlatformException && e.code == 'CANCELED') {
print('Login canceled by user');
} else {
print('Login error: $e');
}
}
}