docs: explain how to get TokenInfo (#502)
This commit is contained in:
parent
4fa725857c
commit
8b6391b173
2 changed files with 14 additions and 0 deletions
|
|
@ -254,6 +254,13 @@ If [`RequireBearerTokenOptions.ResourceMetadataURL`](https://pkg.go.dev/github.c
|
|||
the middleware function sets the WWW-Authenticate header as required by the [Protected Resource
|
||||
Metadata spec](https://datatracker.ietf.org/doc/html/rfc9728).
|
||||
|
||||
Server handlers, such as tool handlers, can obtain the `TokenInfo` returned by the `TokenVerifier`
|
||||
from `req.Extra.TokenInfo`, where `req` is the handler's request. (For example, a
|
||||
[`CallToolRequest`](https://pkg.go.dev/github.com/modelcontextprotocol/go-sdk/mcp#CallToolRequest).)
|
||||
HTTP handlers wrapped by the `RequireBearerToken` middleware can obtain the `TokenInfo` from the context
|
||||
with [`auth.TokenInfoFromContext`](https://pkg.go.dev/github.com/modelcontextprotocol/go-sdk/auth#TokenInfoFromContext).
|
||||
|
||||
|
||||
The [_auth middleware example_](https://github.com/modelcontextprotocol/go-sdk/tree/main/examples/server/auth-middleware) shows how to implement authorization for both JWT tokens and API keys.
|
||||
|
||||
### Client
|
||||
|
|
|
|||
|
|
@ -181,6 +181,13 @@ If [`RequireBearerTokenOptions.ResourceMetadataURL`](https://pkg.go.dev/github.c
|
|||
the middleware function sets the WWW-Authenticate header as required by the [Protected Resource
|
||||
Metadata spec](https://datatracker.ietf.org/doc/html/rfc9728).
|
||||
|
||||
Server handlers, such as tool handlers, can obtain the `TokenInfo` returned by the `TokenVerifier`
|
||||
from `req.Extra.TokenInfo`, where `req` is the handler's request. (For example, a
|
||||
[`CallToolRequest`](https://pkg.go.dev/github.com/modelcontextprotocol/go-sdk/mcp#CallToolRequest).)
|
||||
HTTP handlers wrapped by the `RequireBearerToken` middleware can obtain the `TokenInfo` from the context
|
||||
with [`auth.TokenInfoFromContext`](https://pkg.go.dev/github.com/modelcontextprotocol/go-sdk/auth#TokenInfoFromContext).
|
||||
|
||||
|
||||
The [_auth middleware example_](https://github.com/modelcontextprotocol/go-sdk/tree/main/examples/server/auth-middleware) shows how to implement authorization for both JWT tokens and API keys.
|
||||
|
||||
### Client
|
||||
|
|
|
|||
Loading…
Reference in a new issue