Documentation Index
Fetch the complete documentation index at: https://mintlify.com/microsoft/mcp-for-beginners/llms.txt
Use this file to discover all available pages before exploring further.
Overview
OAuth2 is the industry-standard protocol for authorization, enabling secure access to resources without sharing credentials. In MCP implementations, OAuth2 provides a robust way to authenticate and authorize clients (such as AI agents) accessing MCP servers and their tools. This lesson demonstrates how to implement OAuth2 using Spring Boot, acting as both an Authorization Server and a Resource Server.Project overview
This project is a minimal Spring Boot application that:- Acts as a Spring Authorization Server — issuing JWT access tokens via the
client_credentialsflow - Acts as a Resource Server — protecting its own
/helloendpoint
Client credentials flow
Machine-to-machine OAuth2 — no user login required
JWT tokens
Stateless, verifiable access tokens with configurable scopes
Azure Container Apps
Production-ready deployment with automatic TLS
APIM integration
Validate JWTs at the API gateway layer
Quick start (local)
Testing the OAuth2 configuration
1. Verify the server is running and secured
2. Get an access token using client credentials
The Basic Authentication header
bWNwLWNsaWVudDpzZWNyZXQ= is the Base64 encoding of mcp-client:secret.3. Access the protected endpoint
Container deployment
Deploy to Azure Container Apps
https://<fqdn>). Azure provides a trusted TLS certificate automatically for *.azurecontainerapps.io.
Wire into Azure API Management
Add this inbound policy to your API to validate JWTs at the gateway:How the flow works
Security considerations
Use HTTPS everywhere
Always use HTTPS in production to protect tokens in transit
Short token lifetimes
Configure short-lived access tokens and use refresh tokens appropriately
Scope validation
Validate the
scope claim in the JWT on every resource server requestRotate secrets
Regularly rotate client secrets and use managed identities where possible