diff --git a/android/README.md b/android/README.md index b03860ca..0f7576ef 100644 --- a/android/README.md +++ b/android/README.md @@ -183,9 +183,9 @@ Backend logs can be accessed from the output of `yarn prod / dev` like in the we Java/Kotlin logs can be accessed via Android Studio's Logcat. ``` +adb logcat | grep CompassApp adb logcat | grep com.compass.app adb logcat | grep Capacitor -adb logcat | grep console ``` You can also add this inside `MainActivity.java`: diff --git a/backend/api/src/auth-google.ts b/backend/api/src/auth-google.ts index 36063fa2..53f16d76 100644 --- a/backend/api/src/auth-google.ts +++ b/backend/api/src/auth-google.ts @@ -1,5 +1,5 @@ import {APIError, APIHandler} from './helpers/endpoint' -import {GOOGLE_CLIENT_ID} from "common/constants"; +import {GOOGLE_CLIENT_ID, REDIRECT_URI} from "common/constants"; export const authGoogle: APIHandler<'auth-google'> = async ( {code, codeVerifier}, @@ -14,7 +14,7 @@ export const authGoogle: APIHandler<'auth-google'> = async ( code: code as string, code_verifier: codeVerifier as string, grant_type: 'authorization_code', - redirect_uri: `https://compassmeet.com/auth/callback`, + redirect_uri: REDIRECT_URI, }; console.log('Body:', body) const tokenRes = await fetch('https://oauth2.googleapis.com/token', { diff --git a/common/src/constants.ts b/common/src/constants.ts index 6fa254a7..2e696a70 100644 --- a/common/src/constants.ts +++ b/common/src/constants.ts @@ -23,5 +23,7 @@ export const IS_MAINTENANCE = false // set to true to enable the maintenance mod export const MIN_BIO_LENGTH = 250 export const WEB_GOOGLE_CLIENT_ID = '253367029065-khkj31qt22l0vc3v754h09vhpg6t33ad.apps.googleusercontent.com' -export const ANDROID_GOOGLE_CLIENT_ID = '253367029065-s9sr5vqgkhc8f7p5s6ti6a4chqsrqgc4.apps.googleusercontent.com' +// export const ANDROID_GOOGLE_CLIENT_ID = '253367029065-s9sr5vqgkhc8f7p5s6ti6a4chqsrqgc4.apps.googleusercontent.com' export const GOOGLE_CLIENT_ID = WEB_GOOGLE_CLIENT_ID + +export const REDIRECT_URI = `https://compassmeet.com/auth/callback` diff --git a/web/lib/firebase/users.ts b/web/lib/firebase/users.ts index fe9b5194..019d64e8 100644 --- a/web/lib/firebase/users.ts +++ b/web/lib/firebase/users.ts @@ -5,8 +5,7 @@ import {getAuth, GoogleAuthProvider, signInWithPopup} from 'firebase/auth' import {safeLocalStorage} from '../util/local' import {app} from './init' -import {IS_LOCAL} from "common/envs/constants"; -import {GOOGLE_CLIENT_ID} from "common/constants"; +import {GOOGLE_CLIENT_ID, REDIRECT_URI} from "common/constants"; dayjs.extend(utc) @@ -73,10 +72,10 @@ async function generatePKCE() { /** * Authenticates a Firebase client running a webview APK on Android with Google OAuth. * - * `https://accounts.google.com/o/oauth2/v2/auth?${params}` to get the code (in external browser, as google blocks it in webview) - * Redirects to `com.compassmeet://auth` (in webview java main activity) - * 'https://oauth2.googleapis.com/token' to get the ID token (in javascript app) - * signInWithCredential(auth, credential) to set up firebase user in client (auth.currentUser) + * Calls `https://accounts.google.com/o/oauth2/v2/auth?${params}` to get the code (in external browser, as Google blocks it in webview) + * Redirects to `com.compassmeet://auth` (in webview java main activity), which triggers oauthRedirect in the app (see _app.tsx) + * Calls backend endpoint `https://api.compassmeet.com/auth-google` to get the tokens from the code ('https://oauth2.googleapis.com/token') + * Uses signInWithCredential(auth, credential) to set up firebase user in the client (auth.currentUser) * * @public */ @@ -86,7 +85,7 @@ export async function webviewGoogleSignin() { const params = new URLSearchParams({ client_id: GOOGLE_CLIENT_ID, - redirect_uri: `https://compassmeet.com/auth/callback`, + redirect_uri: REDIRECT_URI, response_type: 'code', scope: 'openid email profile', code_challenge: codeChallenge, @@ -97,48 +96,8 @@ export async function webviewGoogleSignin() { window.open(`https://accounts.google.com/o/oauth2/v2/auth?${params}`, '_system'); } -// export async function googleNativeLogin() { -// console.log('Platform:', Capacitor.getPlatform()) -// console.log('URL origin:', window.location.origin) -// -// await SocialLogin.initialize({ -// google: { -// webClientId: '253367029065-khkj31qt22l0vc3v754h09vhpg6t33ad.apps.googleusercontent.com', // Required for Android and Web -// // iOSClientId: 'YOUR_IOS_CLIENT_ID', // Required for iOS -// // iOSServerClientId: 'YOUR_WEB_CLIENT_ID', // Required for iOS offline mode and server authorization (same as webClientId) -// mode: 'online', // 'online' or 'offline' -// } -// }); -// console.log('Done initializing SocialLogin') -// -// // Run the native Google OAuth -// const result: any = await SocialLogin.login({provider: 'google', options: {}}) -// -// console.log('result', result) -// -// // Extract the tokens from the native result -// const idToken = result?.result?.idToken -// const accessToken = result?.result?.accessToken?.token -// -// if (!idToken) { -// throw new Error('No idToken returned from Google login') -// } -// -// // Create a Firebase credential from the Google tokens -// const credential = GoogleAuthProvider.credential(idToken, accessToken) -// -// // Sign in with Firebase using the credential -// const userCredential = await signInWithCredential(auth, credential) -// -// console.log('Firebase user:', userCredential.user) -// -// return userCredential -// } - -// export const isRunningInAPK = () => typeof window !== 'undefined' && (window as any).IS_APK === true - export async function firebaseLogin() { - if (isAndroidWebView() || IS_LOCAL) { + if (isAndroidWebView()) { console.log('Running in APK') return await webviewGoogleSignin() } diff --git a/web/pages/auth/callback.tsx b/web/pages/auth/callback.tsx index 50f16d81..8d2eae7c 100644 --- a/web/pages/auth/callback.tsx +++ b/web/pages/auth/callback.tsx @@ -6,34 +6,10 @@ export default function GoogleAuthCallback() { const params = new URLSearchParams(window.location.search); console.log('/auth/callback', params); const code = params.get('code'); - // const state = params.get('state'); if (code) { - console.log('/auth/callback code', code); // Send code back to the native app window.location.href = `com.compassmeet://auth?code=${encodeURIComponent(code)}}`; - - // const codeVerifier = localStorage.getItem('pkce_verifier'); - // const body = new URLSearchParams({ - // client_id: GOOGLE_CLIENT_ID, - // code, - // code_verifier: codeVerifier!, - // redirect_uri: 'com.compassmeet://auth', - // grant_type: 'authorization_code', - // }); - // console.log('Body:', body); - // const tokenResponse = await fetch('https://oauth2.googleapis.com/token', { - // method: 'POST', - // headers: {'Content-Type': 'application/x-www-form-urlencoded'}, - // body: body, - // }); - // const tokens = await tokenResponse.json(); - // console.log('Tokens:', tokens); - - // Send code back to the native app - // const deepLink = `com.compassmeet://auth?tokens=${encodeURIComponent(tokens)}}`; - // window.location.href = deepLink; - } else { document.body.textContent = 'Missing code in redirect.'; }