Skip to content

feat(auth): add optional OIDC-based JWT validation for API routes #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

jescalada
Copy link
Collaborator

@jescalada jescalada commented Mar 1, 2025

This PR adds optional JWT validation middleware for /repo, /user, and /push endpoints.

  • If jwt auth method is present and enabled in the proxy.config.json

    • When logging in through the UI, you can access data as usual
    • Direct API requests require a JWT bearer token to go through
      • The JWT token is validated through the configuration in the jwtConfig in proxy.config.json.
      • The user issues their own JWT using the clientID, authorityURL (and potentially, the expectedAudience) provided in the config
  • If jwt is not enabled, it works as it used to.

    • All API resources are accessible even to unlogged users
    • No JWT is required

To activate the JWT check, you must fill in the JWT details (proxy.config.json). The following will let you verify against my Google testing app:

{
  "type": "jwt",
  "enabled": true,
  "jwtConfig": {
    "clientID": "1009968223893-u92qq6itk7ej5008o4174gjubs5lhorg.apps.googleusercontent.com",
    "authorityURL": "https://accounts.google.com"
  }
}

You can manually generate a sample JWT by accessing the following link in your browser:

https://accounts.google.com/o/oauth2/auth?client_id=1009968223893-u92qq6itk7ej5008o4174gjubs5lhorg.apps.googleusercontent.com&redirect_uri=http://localhost:8080/api/auth/oidc/callback&response_type=code&scope=openid%20email%20profile

Upon successful login, it will redirect to the callback URL containing an auth code (code query param). Replace AUTHORIZATION_CODE below with the code, to issue a JWT:

curl -X POST "https://oauth2.googleapis.com/token" \
     -H "Content-Type: application/x-www-form-urlencoded" \
     -d "client_id=1009968223893-u92qq6itk7ej5008o4174gjubs5lhorg.apps.googleusercontent.com" \
     -d "client_secret=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" \
     -d "code=AUTHORIZATION_CODE" \
     -d "grant_type=authorization_code" \
     -d "redirect_uri=http://localhost:8080/api/auth/oidc/callback"

Note: Although my Google app secrets are exposed, only registered emails can use it. Let me know if you'd like to test it out, and I can add your email to the app!

Changelog

  • Add a jwtAuthHandler middleware for /repo, /user, and /push endpoints
    • JWT check is optional based on config
    • Descriptive 401 errors are returned if failed to verify
      • Missing token
      • Missing configuration
      • Invalid token format/algorithm
      • Expired token

@jescalada jescalada self-assigned this Mar 1, 2025
@jescalada jescalada force-pushed the add-oidc-auth-to-api-through-jwt branch from f2c5e5e to c5b45b2 Compare March 8, 2025 05:07
JamieSlome and others added 28 commits May 20, 2025 15:49
feat: implements config loader to enable remote or external configs
fix: decouple UI layout from admin routes
@jescalada
Copy link
Collaborator Author

Merged in finos#967.

@jescalada jescalada closed this Jun 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement OIDC for accessing API routes
8 participants