docs
evals
scenario-1
scenario-10
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
Build a web application that implements Google OAuth 2.0 authentication with comprehensive error handling and proper failure management.
Your application should provide the following functionality:
Implement Google OAuth 2.0 authentication that:
Implement robust error handling that:
Create the following routes:
GET / - Landing page with a "Login with Google" linkGET /auth/google - Initiates Google OAuth authenticationGET /auth/google/callback - Handles OAuth callback from GoogleGET /dashboard - Protected route that displays user information (requires authentication)GET /error - Error page that displays authentication error messagesGET /logout - Logs out the user and redirects to the landing page/**
* Express application with Google OAuth authentication
* and comprehensive error handling
*/
// Main application routes
app.get('/', handleLandingPage);
app.get('/auth/google', initiateGoogleAuth);
app.get('/auth/google/callback', handleGoogleCallback);
app.get('/dashboard', requireAuth, handleDashboard);
app.get('/error', handleError);
app.get('/logout', handleLogout);
/**
* Middleware to check if user is authenticated
*/
function requireAuth(req, res, next) {
// Implementation here
}
/**
* Handler for landing page
*/
function handleLandingPage(req, res) {
// Implementation here
}
/**
* Handler for initiating Google OAuth
*/
function initiateGoogleAuth(req, res, next) {
// Implementation here
}
/**
* Handler for Google OAuth callback
*/
function handleGoogleCallback(req, res, next) {
// Implementation here
}
/**
* Handler for protected dashboard
*/
function handleDashboard(req, res) {
// Implementation here
}
/**
* Handler for error page
*/
function handleError(req, res) {
// Implementation here
}
/**
* Handler for logout
*/
function handleLogout(req, res) {
// Implementation here
}
module.exports = app;Your 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 (default: http://localhost:3000/auth/google/callback)Provides Google OAuth 2.0 authentication strategy for Passport.js, including error handling capabilities for authentication failures.
Authentication middleware for Node.js that provides the framework for implementing OAuth strategies.
Web application framework for handling HTTP requests and routing.
Session middleware for Express to maintain user authentication state across requests.