Overview
BookMe uses 42 Intra OAuth 2.0 for authentication. This provides secure, single sign-on access for Hive Helsinki students and staff.42 OAuth is the only supported authentication method. Users must have a valid 42 Intra account to access the system.
Create OAuth Application
Access 42 Intra
Navigate to the 42 API applications page:https://profile.intra.42.fr/oauth/applications/newLog in with your 42 Intra credentials.
Create New Application
Fill in the application details:Name:
BookMe - Hive Helsinki (or your preferred name)Redirect URI:For production, use your production domain:
Select Scopes
Under Scopes, select:
- ✅ Access the user public data
- User email
- Username
- Profile information
Configure Environment Variables
Add your OAuth credentials to.env:
Variable Descriptions
| Variable | Description |
|---|---|
CLIENT_ID | Your 42 OAuth application client ID (UID) |
SECRET | Your 42 OAuth application client secret |
REDIRECT_URI | Backend endpoint that handles OAuth callback |
REDIRECT_TOKEN_URI | Frontend URL to redirect user after login |
OAUTH_AUTH_URI | 42 authorization endpoint (fixed) |
OAUTH_TOKEN_URI | 42 token endpoint (fixed) |
USER_INFO_URL | 42 user info API endpoint (fixed) |
OAuth Flow
BookMe implements the standard OAuth 2.0 authorization code flow:Frontend Integration
Login Button
In your frontend application, create a login button that redirects to:Handle Callback
Create a callback route at/auth/callback to receive the JWT:
Make Authenticated Requests
Include the JWT in theAuthorization header:
Production Configuration
Update Redirect URIs
For production deployment:Update 42 Application
Go to your 42 OAuth application settings and add your production redirect URI:
CORS Configuration
Ensure your backend allows requests from your frontend domain. See source code atinternal/api/api.go for CORS middleware configuration.
JWT Token Structure
BookMe issues JWT tokens with the following claims:| Claim | Description |
|---|---|
sub | User ID (UUID) |
email | User email from 42 profile |
username | 42 username |
role | User role: student or staff |
exp | Token expiration timestamp |
iat | Token issued at timestamp |
JWT tokens are signed using the
JWT_SECRET from your environment configuration. See internal/auth/auth.go:18 for implementation details.User Roles
BookMe assigns roles based on 42 Intra user type:Student
- Can create reservations
- Can view their own reservations
- Can cancel their own reservations
- Cannot see who booked other time slots
Staff
- Can create reservations with Google Calendar sync
- Can view all reservations and booking details
- Can cancel any reservation
- Can see who booked each time slot
Role determination logic is implemented in
internal/oauth/provider42.go. The application checks the user’s 42 profile to determine if they are staff or a student.Testing OAuth Flow
Verify Redirect
After authorization, you should be redirected to:The JWT token will be in the URL query parameter.
Decode Token (Optional)
Use jwt.io to decode and inspect the token.
Troubleshooting
Redirect URI Mismatch
REDIRECT_URI in .env exactly matches the redirect URI registered in your 42 OAuth application.
Invalid Client
CLIENT_ID and SECRET are correct.
Access Denied
CORS Error
internal/api/api.go. Ensure your frontend origin is allowed.
Invalid Token
- Check
JWT_SECRETis the same value used to sign the token - Verify token hasn’t expired
- Ensure token is included in
Authorization: Bearer <token>header
Security Best Practices
- Rotate Secrets Regularly: Change your
JWT_SECRETperiodically - Use HTTPS in Production: Always use secure connections for OAuth flows
- Validate Redirect URIs: Only allow whitelisted redirect URIs
- Set Token Expiration: JWT tokens should have reasonable expiration times
- Secure Cookie Settings: Use
HttpOnlyandSecureflags for session cookies