यह प्रोजेक्ट एक मिनिमल Spring Boot एप्लिकेशन है जो दोनों के रूप में काम करता है:
- एक Spring Authorization Server (जो
client_credentialsफ्लो के माध्यम से JWT एक्सेस टोकन जारी करता है), और - एक Resource Server (जो अपने
/helloएंडपॉइंट की सुरक्षा करता है)।
यह Spring ब्लॉग पोस्ट (2 अप्रैल 2025) में दिखाए गए सेटअप की नकल करता है।
# build & run
./mvnw spring-boot:run
# obtain a token
curl -u mcp-client:secret -d grant_type=client_credentials \
http://localhost:8081/oauth2/token | jq -r .access_token > token.txt
# call the protected endpoint
curl -H "Authorization: Bearer $(cat token.txt)" http://localhost:8081/helloआप निम्नलिखित चरणों के साथ OAuth2 सुरक्षा कॉन्फ़िगरेशन का परीक्षण कर सकते हैं:
# This should return 401 Unauthorized, confirming OAuth2 security is active
curl -v http://localhost:8081/# Get and extract the full token response
curl -v -X POST http://localhost:8081/oauth2/token \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Authorization: Basic bWNwLWNsaWVudDpzZWNyZXQ=" \
-d "grant_type=client_credentials&scope=mcp.access"
# Or to extract just the token (requires jq)
curl -s -X POST http://localhost:8081/oauth2/token \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Authorization: Basic bWNwLWNsaWVudDpzZWNyZXQ=" \
-d "grant_type=client_credentials&scope=mcp.access" | jq -r .access_token > token.txtध्यान दें: Basic Authentication हेडर (bWNwLWNsaWVudDpzZWNyZXQ=) mcp-client:secret का Base64 एन्कोडिंग है।
# Using the saved token
curl -H "Authorization: Bearer $(cat token.txt)" http://localhost:8081/hello
# Or directly with the token value
curl -H "Authorization: Bearer eyJra...token_value...xyz" http://localhost:8081/hello"Hello from MCP OAuth2 Demo!" के साथ सफल प्रतिक्रिया यह पुष्टि करती है कि OAuth2 कॉन्फ़िगरेशन सही ढंग से काम कर रहा है।
docker build -t mcp-oauth2-demo .
docker run -p 8081:8081 mcp-oauth2-demoaz containerapp up -n mcp-oauth2 \
-g demo-rg -l westeurope \
--image <your-registry>/mcp-oauth2-demo:latest \
--ingress external --target-port 8081इंग्रेस FQDN आपका issuer बन जाता है (https://<fqdn>)।
Azure अपने आप *.azurecontainerapps.io के लिए एक विश्वसनीय TLS सर्टिफिकेट प्रदान करता है।
अपने API में यह inbound पॉलिसी जोड़ें:
<inbound>
<validate-jwt header-name="Authorization">
<openid-config url="https://<fqdn>/.well-known/openid-configuration"/>
<audiences>
<audience>mcp-client</audience>
</audiences>
</validate-jwt>
<base/>
</inbound>APIM JWKS को प्राप्त करेगा और हर अनुरोध को वैधता देगा।
अस्वीकरण:
यह दस्तावेज़ AI अनुवाद सेवा Co-op Translator का उपयोग करके अनुवादित किया गया है। जबकि हम सटीकता के लिए प्रयासरत हैं, कृपया ध्यान दें कि स्वचालित अनुवादों में त्रुटियाँ या अशुद्धियाँ हो सकती हैं। मूल दस्तावेज़ अपनी मूल भाषा में ही अधिकारिक स्रोत माना जाना चाहिए। महत्वपूर्ण जानकारी के लिए, पेशेवर मानव अनुवाद की सलाह दी जाती है। इस अनुवाद के उपयोग से उत्पन्न किसी भी गलतफहमी या गलत व्याख्या के लिए हम जिम्मेदार नहीं हैं।