feat: Implement Apple Sign-In for Android by adding a callback function, updating redirect URI, and configuring the Android manifest.

This commit is contained in:
Van Leemput Dayron
2025-12-03 15:41:22 +01:00
parent f3ae91ccf9
commit fd19b88eef
4 changed files with 50 additions and 14 deletions

View File

@@ -40,6 +40,20 @@
<category android:name="android.intent.category.LAUNCHER"/> <category android:name="android.intent.category.LAUNCHER"/>
</intent-filter> </intent-filter>
</activity> </activity>
<!-- Apple Sign In Callback Activity -->
<activity
android:name="com.aboutyou.dart_packages.sign_in_with_apple.SignInWithAppleCallback"
android:exported="true"
android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="signinwithapple" />
<data android:path="/" />
</intent-filter>
</activity>
<!-- Don't delete the meta-data below. <!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java --> This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
<meta-data <meta-data

View File

@@ -144,3 +144,22 @@ exports.onExpenseCreated = functions.firestore
{ groupId: groupId } { groupId: groupId }
); );
}); });
exports.callbacks_signInWithApple = functions.https.onRequest((req, res) => {
const code = req.body.code;
const state = req.body.state;
const id_token = req.body.id_token;
const user = req.body.user;
const params = new URLSearchParams();
if (code) params.append('code', code);
if (state) params.append('state', state);
if (id_token) params.append('id_token', id_token);
if (user) params.append('user', user);
const qs = params.toString();
const packageName = 'be.devdayronvl.travel_mate';
const redirectUrl = `intent://callback?${qs}#Intent;package=${packageName};scheme=signinwithapple;end`;
res.redirect(302, redirectUrl);
});

View File

@@ -58,6 +58,9 @@ class _LoadingContentState extends State<LoadingContent>
} }
} catch (e) { } catch (e) {
debugPrint('Erreur lors de la tâche en arrière-plan: $e'); debugPrint('Erreur lors de la tâche en arrière-plan: $e');
if (mounted) {
Navigator.pop(context);
}
} }
} }
} }

View File

@@ -225,17 +225,17 @@ class AuthService {
} }
// Request Apple ID credential with platform-specific configuration // Request Apple ID credential with platform-specific configuration
final AuthorizationCredentialAppleID credential = final AuthorizationCredentialAppleID
await SignInWithApple.getAppleIDCredential( credential = await SignInWithApple.getAppleIDCredential(
scopes: [ scopes: [
AppleIDAuthorizationScopes.email, AppleIDAuthorizationScopes.email,
AppleIDAuthorizationScopes.fullName, AppleIDAuthorizationScopes.fullName,
], ],
// Configuration for Android/Web // Configuration for Android/Web
webAuthenticationOptions: WebAuthenticationOptions( webAuthenticationOptions: WebAuthenticationOptions(
clientId: 'be.devdayronvl.travel_mate.service', clientId: 'be.devdayronvl.TravelMate.service',
redirectUri: Uri.parse( redirectUri: Uri.parse(
'https://travelmate-a47f5.firebaseapp.com/__/auth/handler', 'https://us-central1-travelmate-a47f5.cloudfunctions.net/callbacks_signInWithApple',
), ),
), ),
); );