Skip to content

Commit 7aa7ee1

Browse files
committed
auth docs update
1 parent 79dca9a commit 7aa7ee1

File tree

1 file changed

+22
-17
lines changed

1 file changed

+22
-17
lines changed

docs/auth.md

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -168,16 +168,16 @@ The above implementation provides an OAuth compliant way to MCP security without
168168

169169
This section discusses the reference implementation using Amazon Cognito as the IdP, supporting both Machine-to-Machine (M2M) and Session Cookie authentication methods.
170170

171+
>This section will soon be updated with detailed steps for Cognito configuration.
172+
171173
### Key Components
172174

173175
#### 1. Auth Server (`auth_server/server.py`)
174-
The enhanced auth server provides dual authentication support:
176+
The auth server provides dual authentication support:
175177
- **Primary Check**: Session cookie validation using `itsdangerous.URLSafeTimedSerializer`
176178
- **Fallback**: JWT token validation with Cognito
177179
- **Group Mapping**: Maps Cognito groups to MCP scopes via `scopes.yml` configuration
178-
- Groups are mapped to scopes using the `group_mappings` section in `scopes.yml`
179180
- Both M2M and session cookie auth use the same scope definitions
180-
- Example mappings: `mcp-admin` → unrestricted access, `mcp-user` → restricted read
181181

182182
#### 2. CLI Authentication Tool (`auth_server/cli_auth.py`)
183183
A standalone tool for user-based authentication:
@@ -204,12 +204,17 @@ Cognito supports machine-to-machine authentication, enabling Agents to have thei
204204
- MCP Server(s) function as resource servers
205205

206206
#### Authentication Flow:
207+
Run the Agent with the following command:
208+
```{.bash}
209+
python agents/agent_w_auth.py
210+
```
211+
1. Copy `agents/.env.template` to `agents/.env.agent` and set the environment variables (`COGNITO_CLIENT_ID`, `COGNITO_CLIENT_SECRET`, `COGNITO_USER_POOL_ID`) as appropriate for your setup.
207212
1. Agent startup:
208-
- Configured with client ID, client secret, and a set of scopes
213+
- Configured with client ID, client secret, and a set of scopes. _Each agent is an App Client in a Cognito user pool_.
209214
- Requests scopes (e.g., MCP Registry with tool finder and basic MCP servers)
210-
2. Cognito issues a JWT token
211-
3. Agent includes the JWT token in MCP headers
212-
4. Auth server on Nginx side:
215+
1. Cognito issues a JWT token
216+
1. Agent includes the JWT token in MCP headers
217+
1. Auth server on Nginx side:
213218
- Retrieves JWT token
214219
- Calls Cognito to validate token and get allowed scopes
215220
- Returns 200 or 403 based on:
@@ -219,10 +224,10 @@ Cognito supports machine-to-machine authentication, enabling Agents to have thei
219224

220225
#### Advantages
221226
1. Leverages existing Cognito user identities and groups
222-
2. No need to manage separate M2M credentials for user-initiated actions
223-
3. Maintains user context throughout the session
224-
4. Compatible with existing web-based authentication flow
225-
5. Auth server handles both authentication methods transparently
227+
1. No need to manage separate M2M credentials for user-initiated actions
228+
1. Maintains user context throughout the session
229+
1. Compatible with existing web-based authentication flow
230+
1. Auth server handles both authentication methods transparently
226231

227232
### 2. Session Cookie Authentication
228233

@@ -236,8 +241,7 @@ The CLI tool handles the OAuth flow with Cognito and saves the session cookie lo
236241

237242
```bash
238243
# Run the CLI authentication tool
239-
cd auth_server
240-
python cli_auth.py
244+
python agents/cli_auth.py
241245

242246
# This will:
243247
# 1. Open your browser to Cognito hosted UI
@@ -247,13 +251,15 @@ python cli_auth.py
247251
```
248252

249253
Required environment variables:
250-
- `COGNITO_DOMAIN`: Your Cognito domain (e.g., 'mcp-gateway')
254+
- `COGNITO_USER_POOL_ID`: Your Cognito user pool id
251255
- `COGNITO_CLIENT_ID`: OAuth client ID configured for PKCE flow
252256
- `SECRET_KEY`: Must match the registry's SECRET_KEY for cookie compatibility
253257

254258
##### b. Agent with Session Cookie Support
255259

256-
The enhanced agent (`agents/agent_w_auth.py`) now supports session cookie authentication:
260+
Copy `agents/.env.template` to `agents/.env.user` and set the environment variables (`COGNITO_CLIENT_ID`, `COGNITO_CLIENT_SECRET`, `COGNITO_USER_POOL_ID`, `SECRET_KEY`) as appropriate for your setup.
261+
262+
The agent (`agents/agent_w_auth.py`) supports session cookie authentication:
257263

258264
```bash
259265
# Use agent with session cookie
@@ -269,14 +275,13 @@ Key features:
269275
- Automatically reads cookie and includes in request headers
270276
- Falls back to M2M if session cookie flag not provided
271277

272-
##### c. Auth Server Enhancements
278+
##### c. Auth Server
273279

274280
The auth server validates session cookies alongside JWT tokens:
275281
- Checks for `mcp_gateway_session` cookie in request headers
276282
- Validates cookie signature using `itsdangerous.URLSafeTimedSerializer`
277283
- Maps Cognito groups to MCP scopes using `scopes.yml` configuration:
278284
- Configuration-driven mapping ensures consistency with M2M authentication
279-
- Group mappings defined in `group_mappings` section of `scopes.yml`
280285
- Single source of truth for all permission definitions
281286
- Falls back to JWT validation if no valid cookie found
282287

0 commit comments

Comments
 (0)