Files
MeowSpool/mobile/plugins/withGoogleOAuth.js
T
Felipe 34cbd4a861 feat: implement Google OAuth support for Android and iOS
- Added support for Google OAuth with separate client IDs for Android and iOS.
- Updated `verify_google_id_token` to validate `aud` against both client IDs and check `email_verified`.
- Modified `google_oauth_handler` to accept and process the new client IDs.
- Enhanced security by enforcing explicit JWT algorithm validation.
- Updated mobile app to handle Google OAuth flow using `expo-auth-session`.
- Fixed API request to send `id_token` in snake_case as expected by the backend.
- Added necessary environment variables for Google client IDs in mobile app.
- Implemented intent filter for Google OAuth redirect in AndroidManifest.xml.
2026-03-19 15:24:08 -03:00

51 lines
1.7 KiB
JavaScript

/**
* Plugin local: injeta o intent filter do Google OAuth no AndroidManifest.xml
* durante o `expo prebuild`.
*
* Sem esse intent filter, o Android não sabe que o MeowSpool deve interceptar
* o redirect do Google OAuth (scheme com.googleusercontent.apps.*), fazendo o
* Chrome tratar a URL como pesquisa.
*
* O scheme é o reverse do Android OAuth 2.0 client ID registrado no Google Cloud Console.
*/
const { withAndroidManifest } = require('@expo/config-plugins');
const GOOGLE_REVERSE_CLIENT_ID =
'com.googleusercontent.apps.724520558909-bg5a7e4u24jmis8lgg41ucs0kv0nfp1v';
module.exports = function withGoogleOAuth(config) {
return withAndroidManifest(config, (config) => {
const manifest = config.modResults;
const activities = manifest.manifest.application?.[0]?.activity ?? [];
const mainActivity = activities.find(
(a) => a.$?.['android:name'] === '.MainActivity',
);
if (!mainActivity) return config;
// Evita duplicar o intent filter em rebuilds consecutivos
const alreadyAdded = (mainActivity['intent-filter'] ?? []).some((filter) =>
(filter.data ?? []).some(
(d) => d.$?.['android:scheme'] === GOOGLE_REVERSE_CLIENT_ID,
),
);
if (alreadyAdded) return config;
mainActivity['intent-filter'] = [
...(mainActivity['intent-filter'] ?? []),
{
action: [{ $: { 'android:name': 'android.intent.action.VIEW' } }],
category: [
{ $: { 'android:name': 'android.intent.category.DEFAULT' } },
{ $: { 'android:name': 'android.intent.category.BROWSABLE' } },
],
data: [{ $: { 'android:scheme': GOOGLE_REVERSE_CLIENT_ID } }],
},
];
return config;
});
};