-
Notifications
You must be signed in to change notification settings - Fork 32
docs: add GitHub OAuth flow sequence diagram #609
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
Open
aivong-openhands
wants to merge
1
commit into
main
Choose a base branch
from
docs/add-github-oauth-flow-diagram
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| sequenceDiagram | ||
| autonumber | ||
| participant Browser | ||
| participant OpenHands as OpenHands<br/>(Enterprise Server) | ||
| participant DB as AuthTokenStore<br/>(Local DB) | ||
| participant Keycloak as Keycloak<br/>(Identity Provider) | ||
| participant GitHub as GitHub<br/>(OAuth Provider) | ||
|
|
||
| Note over Browser,GitHub: User Login Flow (Client-Side Initiated) | ||
|
|
||
| Note over Browser: User visits /login (SPA route)<br/>Clicks "Sign in with GitHub"<br/>Frontend builds Keycloak URL<br/>window.location.href = url | ||
|
|
||
| Browser->>Keycloak: GET /realms/allhands/protocol/openid-connect/auth<br/>?client_id=allhands<br/>&response_type=code<br/>&kc_idp_hint=github<br/>&redirect_uri=.../oauth/keycloak/callback<br/>&scope=openid+email+profile | ||
|
|
||
| Note over Keycloak: kc_idp_hint=github<br/>skips login page | ||
|
|
||
| Keycloak->>Browser: 302 Redirect to GitHub | ||
|
|
||
| Browser->>GitHub: GET /login/oauth/authorize<br/>?client_id=<GITHUB_APP_CLIENT_ID><br/>&redirect_uri=.../broker/github/endpoint<br/>&scope=openid+email+profile | ||
|
|
||
| Note over GitHub: User authorizes<br/>GitHub App | ||
|
|
||
| GitHub->>Browser: 302 Redirect to Keycloak broker | ||
| Browser->>Keycloak: GET /realms/allhands/broker/github/endpoint<br/>?code=<github-auth-code> | ||
|
|
||
| Note over Keycloak,GitHub: Server-to-Server Token Exchange | ||
|
|
||
| Keycloak->>GitHub: POST /login/oauth/access_token<br/>client_id, client_secret, code | ||
| GitHub-->>Keycloak: access_token (ghu_...) | ||
|
|
||
| Keycloak->>GitHub: GET /user<br/>Authorization: Bearer ghu_... | ||
| GitHub-->>Keycloak: User profile (id, email, name) | ||
|
|
||
| Note over Keycloak: Creates/updates user<br/>Stores GitHub token<br/>(storeToken: true)<br/>Maps github_id attribute | ||
|
|
||
| Keycloak->>Browser: 302 Redirect to OpenHands | ||
| Browser->>OpenHands: GET /oauth/keycloak/callback<br/>?code=<keycloak-auth-code><br/>&session_state=<uuid><br/>&iss=.../realms/allhands | ||
|
|
||
| Note over OpenHands,Keycloak: Server-to-Server Token Exchange | ||
|
|
||
| OpenHands->>Keycloak: POST /realms/allhands/protocol/openid-connect/token<br/>client_id, client_secret, code, grant_type=authorization_code | ||
| Keycloak-->>OpenHands: access_token, refresh_token, id_token | ||
|
|
||
| OpenHands->>Keycloak: GET /realms/allhands/protocol/openid-connect/userinfo<br/>Authorization: Bearer <access_token> | ||
| Keycloak-->>OpenHands: User claims (sub, email, github_id, identity_provider) | ||
|
|
||
| Note over OpenHands,Keycloak: Fetch & Store GitHub Token from Keycloak Broker | ||
|
|
||
| OpenHands->>Keycloak: GET /realms/allhands/broker/github/token<br/>Authorization: Bearer <keycloak_access_token> | ||
| Keycloak-->>OpenHands: GitHub access_token (ghu_...) | ||
|
|
||
| OpenHands->>DB: Store GitHub token in AuthTokenStore | ||
|
|
||
| Note over OpenHands: User logged in<br/>Session created | ||
|
|
||
| alt First Login - TOS Required | ||
| OpenHands->>Browser: 302 Redirect to /accept-tos (SPA page) | ||
| Note over Browser: User accepts TOS on SPA page | ||
| Browser->>OpenHands: POST /api/accept_tos | ||
| OpenHands-->>Browser: 200 OK, JSON {redirect_url: ...} | ||
| Note over Browser: Frontend reads redirect_url<br/>window.location.href = redirect_url | ||
| Browser->>Keycloak: GET /realms/allhands/protocol/openid-connect/auth<br/>&redirect_uri=.../oauth/keycloak/offline/callback<br/>&scope=openid+email+profile+offline_access | ||
| Keycloak->>Browser: 302 Redirect with new code | ||
| Browser->>OpenHands: GET /oauth/keycloak/offline/callback<br/>?code=<new-keycloak-code> | ||
| OpenHands->>Keycloak: POST /realms/allhands/protocol/openid-connect/token | ||
| Keycloak-->>OpenHands: refresh_token (for offline access) | ||
| end | ||
|
|
||
| OpenHands->>Browser: Set session cookies<br/>Redirect to app | ||
|
|
||
| Note over Browser,GitHub: Subsequent API Calls (GitHub Token from Local DB) | ||
|
|
||
| Browser->>OpenHands: API request (e.g., list repos) | ||
|
|
||
| OpenHands->>DB: Load GitHub token from AuthTokenStore | ||
|
|
||
| alt Token Expired | ||
| OpenHands->>GitHub: POST /login/oauth/access_token<br/>grant_type=refresh_token<br/>(direct refresh with GitHub) | ||
| GitHub-->>OpenHands: New access_token | ||
| OpenHands->>DB: Update token in AuthTokenStore | ||
| end | ||
|
|
||
| OpenHands->>GitHub: API call with GitHub token<br/>Authorization: Bearer ghu_... | ||
| GitHub-->>OpenHands: API response | ||
|
|
||
| OpenHands->>Browser: Response with data | ||
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 Suggestion: Technical Accuracy - GitHub's standard OAuth 2.0 flow doesn't typically support refresh tokens (
grant_type=refresh_token). GitHub issues long-lived access tokens that don't expire in the traditional OAuth sense.If OpenHands Enterprise is using GitHub Apps with expiring installation tokens, the refresh mechanism would be different (re-authenticating the app installation, not using refresh tokens). Consider verifying this flow matches the actual implementation or adding a note clarifying this is a simplified representation.