loginFor method
Future
loginFor(
- BuildContext context, {
- String hint = '',
- String idpHint = "",
- String emailHint = "",
- String prompt = "login",
Implementation
Future loginFor(BuildContext context, {String hint = '', String idpHint = "", String emailHint = "", String prompt = "login"}) async {
// Make sure you encode these if needed here or before passing
final encodedRedirectUri = Uri.encodeComponent(redirectUri);
encodedScope = Uri.encodeComponent(scope);
// 🔐 PKCE
_codeVerifier = generateCodeVerifier();
final codeChallenge = generateCodeChallenge(_codeVerifier!);
final authUrl =
"https://globalinchexternal.ciamlogin.com/$tenantId/oauth2/v2.0/authorize"
"?client_id=$clientId"
"&response_type=code"
"&redirect_uri=$encodedRedirectUri"
"&scope=$encodedScope"
"&response_mode=query"
"&prompt=$prompt"
"${idpHint.isNotEmpty ? "&idp_hint=$idpHint" : ""}"
"&code_challenge_method=S256"
"${emailHint.isNotEmpty ? "&login_hint=${Uri.encodeComponent(emailHint)}" : ""}"
"&code_challenge=$codeChallenge";
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');
}
}
}