diff --git a/backend/typescript/rest/authRoutes.ts b/backend/typescript/rest/authRoutes.ts index 76f7d587..9421c77c 100644 --- a/backend/typescript/rest/authRoutes.ts +++ b/backend/typescript/rest/authRoutes.ts @@ -34,10 +34,8 @@ const cookieOptions: CookieOptions = { /* Returns access token and user info in response body and sets refreshToken as an httpOnly cookie */ authRouter.post("/login", loginRequestValidator, async (req, res) => { try { - const authDTO = req.body.idToken - ? // OAuth - await authService.generateTokenOAuth(req.body.idToken) - : await authService.generateToken(req.body.email, req.body.password); + const authDTO = req.body.idToken; + await authService.generateToken(req.body.email, req.body.password); const { refreshToken, ...rest } = authDTO; @@ -58,7 +56,6 @@ authRouter.post( try { if (isAuthorizedByEmail(req.body.email)) { const user = await userService.getUserByEmail(req.body.email); - const activatedUser = user; activatedUser.status = UserStatus.ACTIVE; await userService.updateUserById(user.id, activatedUser); @@ -146,7 +143,7 @@ authRouter.post( } else { res.status(400).json(responseSuccess); } - } catch (error) { + } catch (error: unknown) { res.status(500).json({ error: getErrorMessage(error) }); } }, diff --git a/backend/typescript/services/implementations/authService.ts b/backend/typescript/services/implementations/authService.ts index 0b691211..fcbaf4d3 100644 --- a/backend/typescript/services/implementations/authService.ts +++ b/backend/typescript/services/implementations/authService.ts @@ -38,40 +38,6 @@ class AuthService implements IAuthService { } } - /* eslint-disable class-methods-use-this */ - async generateTokenOAuth(idToken: string): Promise { - try { - const googleUser = await FirebaseRestClient.signInWithGoogleOAuth( - idToken, - ); - // googleUser.idToken refers to the Firebase Auth access token for the user - const token = { - accessToken: googleUser.idToken, - refreshToken: googleUser.refreshToken, - }; - // If user already has a login with this email, just return the token - try { - // Note: an error message will be logged from UserService if this lookup fails. - // You may want to silence the logger for this special OAuth user lookup case - const user = await this.userService.getUserByEmail(googleUser.email); - return { ...token, ...user }; - /* eslint-disable-next-line no-empty */ - } catch (error) {} - - const user = await this.userService.createUser({ - firstName: googleUser.firstName, - lastName: googleUser.lastName, - email: googleUser.email, - role: Role.STAFF, - }); - - return { ...token, ...user }; - } catch (error) { - Logger.error(`Failed to generate token for user with OAuth ID token`); - throw error; - } - } - async revokeTokens(userId: string): Promise { try { const authId = await this.userService.getAuthIdById(userId); diff --git a/backend/typescript/services/interfaces/authService.ts b/backend/typescript/services/interfaces/authService.ts index 50e4d4ef..926a20be 100644 --- a/backend/typescript/services/interfaces/authService.ts +++ b/backend/typescript/services/interfaces/authService.ts @@ -11,15 +11,6 @@ interface IAuthService { */ generateToken(email: string, password: string): Promise; - /** - * Generate a short-lived JWT access token and a long-lived refresh token - * when supplied OAuth ID token - * @param idToken user's ID token - * @returns AuthDTO object containing the access token, refresh token, and user info - * @throws Error if token generation fails - */ - generateTokenOAuth(idToken: string): Promise; - /** * Revoke all refresh tokens of a user * @param userId userId of user whose refresh tokens are to be revoked diff --git a/backend/typescript/utilities/firebaseRestClient.ts b/backend/typescript/utilities/firebaseRestClient.ts index 8afa69fc..8b4cc619 100644 --- a/backend/typescript/utilities/firebaseRestClient.ts +++ b/backend/typescript/utilities/firebaseRestClient.ts @@ -9,8 +9,6 @@ const FIREBASE_SIGN_IN_URL = "https://identitytoolkit.googleapis.com/v1/accounts:signInWithPassword"; const FIREBASE_REFRESH_TOKEN_URL = "https://securetoken.googleapis.com/v1/token"; -const FIREBASE_OAUTH_SIGN_IN_URL = - "https://identitytoolkit.googleapis.com/v1/accounts:signInWithIdp"; type PasswordSignInResponse = { idToken: string; @@ -21,27 +19,6 @@ type PasswordSignInResponse = { registered: boolean; }; -type OAuthSignInResponse = { - federatedId: string; - providerId: string; - localId: string; - emailVerified: boolean; - email: string; - oauthIdToken: string; - oauthAccessToken: string; - oauthTokenSecret: string; - rawUserInfo: string; - firstName: string; - lastName: string; - fullName: string; - displayName: string; - photoUrl: string; - idToken: string; - refreshToken: string; - expiresIn: string; - needConfirmation: boolean; -}; - type RefreshTokenResponse = { expires_in: string; token_type: string; @@ -103,45 +80,6 @@ const FirebaseRestClient = { }; }, - // Docs: https://firebase.google.com/docs/reference/rest/auth/#section-sign-in-with-oauth-credential - signInWithGoogleOAuth: async ( - idToken: string, - ): Promise => { - const response: Response = await fetch( - `${FIREBASE_OAUTH_SIGN_IN_URL}?key=${process.env.FIREBASE_WEB_API_KEY}`, - { - method: "POST", - headers: { - "Content-Type": "application/json", - }, - body: JSON.stringify({ - postBody: `id_token=${idToken}&providerId=google.com`, - requestUri: process.env.FIREBASE_REQUEST_URI, - returnIdpCredential: true, - returnSecureToken: true, - }), - }, - ); - - const responseJson: - | OAuthSignInResponse - | RequestError = await response.json(); - - if (!response.ok) { - const errorMessage = [ - "Failed to sign-in via Firebase REST API with OAuth, status code =", - `${response.status},`, - "error message =", - (responseJson as RequestError).error.message, - ]; - Logger.error(errorMessage.join(" ")); - - throw new Error("Failed to sign-in via Firebase REST API"); - } - - return responseJson as OAuthSignInResponse; - }, - // Docs: https://firebase.google.com/docs/reference/rest/auth/#section-refresh-token refreshToken: async (refreshToken: string): Promise => { const response: Response = await fetch( diff --git a/frontend/package.json b/frontend/package.json index 9e99ff5f..3c1c0bb0 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -36,7 +36,6 @@ "react": "^18.2.0", "react-bootstrap": "^1.5.2", "react-dom": "^18.2.0", - "react-google-login": "^5.2.2", "react-icons": "^3.10.0", "react-json-schema": "^1.2.2", "react-jsonschema-form": "^1.8.1", diff --git a/frontend/src/APIClients/AuthAPIClient.ts b/frontend/src/APIClients/AuthAPIClient.ts index 528abe52..3aa81e58 100644 --- a/frontend/src/APIClients/AuthAPIClient.ts +++ b/frontend/src/APIClients/AuthAPIClient.ts @@ -57,20 +57,6 @@ const loginWithSignInLink = async ( } }; -const loginWithGoogle = async (idToken: string): Promise => { - try { - const { data } = await baseAPIClient.post( - "/auth/login", - { idToken }, - { withCredentials: true }, - ); - localStorage.setItem(AUTHENTICATED_USER_KEY, JSON.stringify(data)); - return data; - } catch (error) { - return null; - } -}; - const logout = async (userId: number | undefined): Promise => { const bearerToken = `Bearer ${getLocalStorageObjProperty( AUTHENTICATED_USER_KEY, @@ -177,7 +163,6 @@ export default { login, loginWithSignInLink, logout, - loginWithGoogle, register, resetPassword, refresh,