Skip to content

Commit db1166c

Browse files
committed
improve instructions
1 parent 73b4879 commit db1166c

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

exercises/02.init/02.problem.params/README.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Auth Params
22

3-
👨‍💼 In EpicMe, when a user tries to access a protected journal entry, it's not enough to simply block them. We need to let them know why. If a request is missing the right credentials, the server should respond with a `WWW-Authenticate` header that includes extra details, called auth params, so the client understands what went wrong and how to fix it.
3+
👨‍💼 In EpicMe, when a user tries to access a protected journal entry, it's not enough to simply block them. We need to let them what to do about it. If a request is missing the right credentials, the server should respond with a `WWW-Authenticate` header that includes extra details, called auth params, so the client understands what went wrong and how to fix it.
44

55
For example, if a robot tries to fetch `/api/lemonade` without the right credentials, the response should include a realm and a resource_metadata parameter:
66

exercises/02.init/README.mdx

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Without this check, anyone could access protected endpoints on resource servers
2222
```ts
2323
const authHeader = request.headers.get('authorization')
2424
if (!authHeader) {
25-
return new Response('Missing Authorization header', {
25+
return new Response('Unauthorized', {
2626
status: 401,
2727
headers: {
2828
'WWW-Authenticate': 'Bearer',
@@ -36,6 +36,19 @@ if (!authHeader) {
3636
clients what kind of authentication is required.
3737
</callout-warning>
3838

39+
## MCP Authentication Flow
40+
41+
```mermaid
42+
sequenceDiagram
43+
participant MCPClient as MCP Client
44+
participant MCPServer as MCP Server
45+
46+
MCPClient->>MCPServer: Request to /mcp (no Authorization header)
47+
MCPServer->>MCPClient: 401 Unauthorized<br/>WWW-Authenticate...
48+
MCPClient->>MCPServer: GET https://api.example.com/metadata
49+
MCPServer->>MCPClient: Resource metadata response
50+
```
51+
3952
## About the WWW-Authenticate Header
4053

4154
The `WWW-Authenticate` header tells the client what authentication scheme is required and can include additional parameters (called "auth params") that provide more details about how to authenticate.
@@ -46,15 +59,16 @@ The simplest value is just the scheme:
4659
WWW-Authenticate: Bearer
4760
```
4861

49-
But you can also include auth params, such as `realm`, `error`, or `error_description`:
62+
But you can also include auth params, such as `realm`, `error`, `error_description`, or `resource_metadata`:
5063

5164
```
52-
WWW-Authenticate: Bearer realm="example", error="invalid_token", error_description="The access token expired"
65+
WWW-Authenticate: Bearer realm="example", error="invalid_token", error_description="The access token expired", resource_metadata="https://example.com/.well-known/oauth-protected-resource/mcp"
5366
```
5467

5568
- **realm**: A string identifying the protected area (useful for clients to display to users)
5669
- **error**: A short error code (like `invalid_token` or `insufficient_scope`)
5770
- **error_description**: A human-readable explanation of the error
71+
- **resource_metadata**: A URL pointing to metadata about the resource server (helps clients understand what they're accessing)
5872

5973
These parameters help clients understand why authentication failed and what to do next. You can include as many or as few as make sense for your use case.
6074

0 commit comments

Comments
 (0)