docs
evals
scenario-1
scenario-10
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
Build a simple Express.js application that authenticates users with Google OAuth 2.0 and displays their profile information on a dashboard page.
Implement Google OAuth 2.0 authentication that allows users to sign in with their Google account.
/auth/google redirects the user to Google's OAuth consent screen @test/auth/google/callback, the user is redirected to the dashboard @test/login @testDisplay the authenticated user's profile information on a dashboard page.
/dashboard displays the user's Google ID, display name, and email address when authenticated @test/dashboard without authentication redirects to /login @testMaintain user authentication state across requests using sessions.
/dashboard do not require re-authentication @test/logout clears the session and redirects to /login @test/**
* Express.js application with Google OAuth authentication
*
* Routes:
* - GET /auth/google - Initiates Google OAuth flow
* - GET /auth/google/callback - Handles OAuth callback
* - GET /dashboard - Displays user profile (requires authentication)
* - GET /login - Login page
* - GET /logout - Logs out user and clears session
*
* The application should:
* - Configure Google OAuth 2.0 strategy with appropriate scopes
* - Retrieve user profile data including id, displayName, and email
* - Store authenticated user in session
* - Protect dashboard route to require authentication
*/
const express = require('express');
const app = express();
// Configure and start the Express server
function startServer(port = 3000) {
return app.listen(port);
}
module.exports = { app, startServer };The application should read OAuth credentials from environment variables:
GOOGLE_CLIENT_ID - Google OAuth 2.0 client IDGOOGLE_CLIENT_SECRET - Google OAuth 2.0 client secretCALLBACK_URL - OAuth callback URL (e.g., http://localhost:3000/auth/google/callback)SESSION_SECRET - Secret for session encryptionWeb framework for Node.js
Authentication middleware for Node.js
Google OAuth authentication strategy for Passport
Session middleware for Express