authenticate static method
Implementation
static Future<Map<String, dynamic>> authenticate({
String? accessToken,
String? code,
String? callbackPath,
required String? clientId,
required String? clientSecret,
required String redirectBase,
}) async {
if (clientId == null || clientSecret == null) {
throw AuthException('Facebook OAuth is not configured');
}
String finalAccessToken = accessToken ?? '';
// If code is provided, exchange it for access token
if (code != null) {
finalAccessToken = await _exchangeCodeForToken(
code,
clientId,
clientSecret,
callbackPath != null
? '$redirectBase$callbackPath'
: '$redirectBase/api/auth/facebook/callback',
);
}
if (finalAccessToken.isEmpty) {
throw AuthException('Either accessToken or code must be provided');
}
// Verify token and get user profile
final profile = await _verifyTokenAndGetProfile(finalAccessToken, clientId);
return AuthProvider.formatUserData(
provider: 'facebook',
providerId: profile['id'],
email: profile['email'],
name: profile['name'],
picture: profile['picture']?['data']?['url'],
rawProfile: profile,
);
}