Backend portfolio project for traveler application with authentication and API documentation.
We have implemented the first recommended approach for handling authentication with Swagger UI using redirect/popup flow with PKCE support.
-
OAuth2 Redirect/Popup Flow
- Configured Swagger UI with
oauth2RedirectUrlpointing to/swagger-oauth2-redirect - PKCE (Proof Key for Code Exchange) support enabled
- Google OAuth2 authorization with proper scopes (
profile,email)
- Configured Swagger UI with
-
Security Schemes
- Bearer Token Authentication: JWT tokens for API access
- Google OAuth2: OAuth2 flow with authorization code grant
- Both authentication methods supported on protected endpoints
-
OAuth2 Redirect Handler
- Custom redirect page at
/swagger-oauth2-redirect - Handles authorization code exchange with parent window
- Automatic popup closure after successful authentication
- Custom redirect page at
- Navigate to
http://localhost:5000/api-docs - Click the "Authorize" button in Swagger UI
- Select "googleOAuth" and click "Authorize"
- Complete Google authentication in the popup
- The popup will close automatically and token will be stored
- Use "Try it out" features with authenticated endpoints
- Client ID: Set via
GOOGLE_CLIENT_IDenvironment variable - Client Secret: Set via
GOOGLE_CLIENT_SECRETenvironment variable - Redirect URL:
http://localhost:5000/swagger-oauth2-redirect - Scopes:
profile,email - PKCE: Enabled for enhanced security
Let Swagger call an endpoint on your backend (a single origin). Your controlled backend will exchange the code for a token with Google, avoiding CORS issues from the browser.
If direct XHR is necessary, ensure the target server (not Google) sends Access-Control-Allow-Origin that allows the Swagger origin. This is usually not possible for Google's own endpoints.
be-travello/- Backend applicationfe-travello/- Frontend applicationsrc/- Source filesdist/- Build output
Refer to the following documentation files for detailed setup instructions:
GOOGLE_OAUTH_SETUP.md- Google OAuth configurationDATABASE_SETUP.md- Database setup guideFRONTEND_GUIDE.md- Frontend setupCHAT_API_DOCS.md- Chat API documentation
Use the provided test files:
test-auth-100-percent.sh- Complete authentication testingtest-oauth-flow.sh- OAuth flow testingtest-auth-api.html- Authentication API testing- Various HTML test files for different components