2025-07-10 12:48:59 -07:00
---
2025-07-21 14:12:55 -07:00
title: "Authentication"
description: "How authentication works in Open SWE"
2025-07-10 12:48:59 -07:00
---
2025-07-10 22:28:36 +00:00
Open SWE implements a comprehensive authentication system that secures both client-side interactions and server-side operations. The authentication flow involves GitHub OAuth for user authentication, encrypted token handling, and multi-layered security for LangGraph server requests.
## GitHub OAuth Authentication
Open SWE uses GitHub OAuth for client-side authentication, providing secure access to user accounts and repository permissions.
### Authentication Flow
- **Unauthenticated users** are automatically redirected to GitHub OAuth login
- **Authenticated users** are redirected directly to the chat interface
- **Settings management** is available at `/settings` for updating GitHub authentication
<Note>
2025-07-21 14:12:55 -07:00
GitHub OAuth provides the foundation for all user interactions, enabling Open
SWE to access repositories and perform actions on behalf of authenticated
users.
2025-07-10 22:28:36 +00:00
</Note>
## LangGraph Server Authentication
All requests to the LangGraph server are authenticated through a sophisticated proxy system that ensures secure communication between the web interface and the agent backend.
### Proxy Route Architecture
The Next.js application includes a proxy route (`apps/web/src/app/api/[..._path]/route.ts`) that acts as an intermediary for all LangGraph server requests. This proxy uses the [`langgraph-nextjs-api-passthrough`](https://www.npmjs.com/package/langgraph-nextjs-api-passthrough) package to handle request forwarding with enhanced security.
<Tip>
2025-07-21 14:12:55 -07:00
The proxy route ensures that sensitive authentication tokens never reach the
client directly, maintaining security while enabling seamless communication
with the LangGraph server.
2025-07-10 22:28:36 +00:00
</Tip>
### Header Injection System
The proxy route automatically injects the following encrypted headers into each request:
#### Authentication Headers
- **`x-github-access-token`** - User's GitHub access token for user-specific actions (creating issues, comments)
- **`x-github-installation-token`** - GitHub App installation token for app-level actions (commits, pull requests)
- **`x-github-installation-name`** - Installation name (username or organization name)
<Note>
2025-07-21 14:12:55 -07:00
All headers are prefixed with `x-` to ensure they're included in LangGraph run
configurations, making them accessible during execution while maintaining
security through encryption.
2025-07-10 22:28:36 +00:00
</Note>
### Token Encryption
2025-07-11 10:48:14 -07:00
Open SWE implements AES-256-GCM encryption for all secrets passed to the LangGraph server to prevent exposure in:
2025-07-21 14:12:55 -07:00
2025-07-10 22:28:36 +00:00
- LangSmith trace metadata
- Run configurations
- Potential unauthorized access scenarios
2025-07-11 10:48:14 -07:00
The encryption process uses the `SECRETS_ENCRYPTION_KEY` environment variable and includes:
2025-07-21 14:12:55 -07:00
2025-07-10 22:28:36 +00:00
- **Initialization Vector (IV)** for unique encryption per token
- **Authentication Tag** for data integrity verification
- **Base64 encoding** for safe transport
<Tip>
2025-07-21 14:12:55 -07:00
The same encryption key must be configured in both the web application and
LangGraph agent for proper token decryption.
2025-07-10 22:28:36 +00:00
</Tip>
## Authentication Middleware
The LangGraph server implements comprehensive authentication middleware (`apps/open-swe/src/security/auth.ts`) that validates all incoming requests.
### Webhook Authentication
The middleware first checks for GitHub webhook requests by detecting the `X-Hub-Signature-256` header:
1. **Signature verification** using the configured webhook secret
2. **Automatic authorization** for valid webhook signatures
3. **Separate user verification** in subsequent run creation requests
<Note>
2025-07-21 14:12:55 -07:00
Webhook authentication is handled separately from user authentication to
enable automated GitHub issue processing while maintaining security.
2025-07-10 22:28:36 +00:00
</Note>
### Standard Request Authentication
For non-webhook requests, the middleware validates:
#### Required Headers
2025-07-21 14:12:55 -07:00
2025-07-10 22:28:36 +00:00
- **Installation name** (`x-github-installation-name`)
- **Installation token** (`x-github-installation-token`)
Missing either header results in a 401 Unauthorized error.
#### User Verification Process
The middleware supports two authentication paths:
**Web Application Requests:**
2025-07-21 14:12:55 -07:00
2025-07-10 22:28:36 +00:00
- Uses encrypted GitHub access token (`x-github-access-token`)
- Verifies user identity through GitHub API
- Extracts user ID and login from token
**Webhook-Generated Requests:**
2025-07-21 14:12:55 -07:00
2025-07-10 22:28:36 +00:00
- Uses explicit user headers (`x-github-user-id`, `x-github-user-login`)
- Validates user ID and login against installation token
- Ensures webhook-created runs are properly attributed
### Identity and Permissions
Upon successful authentication, the middleware returns an identity object containing:
2025-07-21 14:12:55 -07:00
2025-07-10 22:28:36 +00:00
- **User ID** for resource ownership verification
- **Display name** (GitHub login)
- **Installation name** for repository context
- **Comprehensive permissions** for LangGraph operations
<Tip>
2025-07-21 14:12:55 -07:00
The user ID serves as the primary identifier for resource access control,
ensuring users can only access their own threads, runs, and assistants.
2025-07-10 22:28:36 +00:00
</Tip>
## Resource Access Control
Open SWE implements fine-grained access control for all LangGraph resources:
### Metadata-Based Ownership
2025-07-21 14:12:55 -07:00
2025-07-10 22:28:36 +00:00
- **Create operations** automatically add user ID to resource metadata
- **Read/Update/Delete operations** verify user ID matches resource owner
- **Search operations** filter results by user ownership
## Token Access During Execution
During LangGraph run execution, encrypted tokens are accessible through the run's configurable field:
1. **Token extraction** from run configuration
2. **Decryption** using the shared encryption key
3. **Action execution** (creating issues, making commits, etc.)
<Note>
2025-07-21 14:12:55 -07:00
This design ensures tokens remain encrypted in storage and traces while being
available for necessary GitHub operations during run execution.
2025-07-10 22:28:36 +00:00
</Note>
<Tip>
2025-07-21 14:12:55 -07:00
Always ensure the `SECRETS_ENCRYPTION_KEY` environment variable is identical
between your web application and LangGraph agent deployments.
2025-07-10 22:28:36 +00:00
</Tip>