GHauth
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.
Viewing readonly version of main branch: v3View latest version
A Val Town service for handling GitHub OAuth authentication with redirect support for external applications.
- GitHub OAuth sign-in flow
- JWT token generation for authenticated users
- Redirect support for external applications
- Secure token validation
- User profile retrieval
-
Create a GitHub OAuth App:
- Go to GitHub Settings > Developer settings > OAuth Apps
- Create a new OAuth App
- Set Authorization callback URL to:
https://[your-val-url]/auth/callback
-
Set environment variables in Val Town:
GITHUB_CLIENT_ID
: Your GitHub OAuth app client IDGITHUB_CLIENT_SECRET
: Your GitHub OAuth app client secretJWT_SECRET
: A secure random string for signing JWT tokens
- Redirect users to:
https://[your-val-url]/auth/signin?redirect_uri=[your-app-url]
- Users will be redirected to GitHub for authentication
- After successful auth, users are redirected back to your app with a token:
[your-app-url]?token=[jwt-token]
Make a GET request to: https://[your-val-url]/auth/validate?token=[jwt-token]
Returns user profile if token is valid.
GET /auth/signin
- Initiate GitHub OAuth flowGET /auth/callback
- Handle GitHub OAuth callbackGET /auth/validate
- Validate JWT token and return user infoGET /
- Auth page UI
/backend/index.ts
- Main Hono server with OAuth routes/frontend/index.html
- Auth page UI/shared/types.ts
- Shared TypeScript types