ဤပရောဂျက်သည် အနည်းဆုံး Spring Boot အက်ပလီကေးရှင်း ဖြစ်ပြီး အောက်ပါအဖြစ် လုပ်ဆောင်သည်-
- Spring Authorization Server (client_credentials flow ဖြင့် JWT access token များထုတ်ပေးခြင်း), နှင့်
- Resource Server (ကိုယ်ပိုင်
/helloendpoint ကို ကာကွယ်ထားခြင်း) ဖြစ်သည်။
ဒါဟာ Spring blog post (2 Apr 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/helloOAuth2 လုံခြုံရေး ဖွဲ့စည်းမှုကို အောက်ပါအဆင့်များဖြင့် စမ်းသပ်နိုင်သည်-
# 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 header (bWNwLWNsaWVudDpzZWNyZXQ=) သည် mcp-client:secret ကို Base64 encode လုပ်ထားခြင်းဖြစ်သည်။
# 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 8081ingress FQDN သည် သင့် issuer (https://<fqdn>) ဖြစ်လာမည်။
Azure သည် *.azurecontainerapps.io အတွက် ယုံကြည်စိတ်ချရသော TLS certificate ကို အလိုအလျောက် ပေးအပ်သည်။
သင့် API တွင် အောက်ပါ inbound policy ကို ထည့်သွင်းပါ-
<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 ဖြင့် ဘာသာပြန်ထားပါသည်။ ကျွန်ုပ်တို့သည် တိကျမှန်ကန်မှုအတွက် ကြိုးစားသော်လည်း အလိုအလျောက် ဘာသာပြန်ခြင်းတွင် အမှားများ သို့မဟုတ် မှားယွင်းချက်များ ပါဝင်နိုင်ကြောင်း သတိပြုပါရန် မေတ္တာရပ်ခံအပ်ပါသည်။ မူရင်းစာတမ်းကို မိမိဘာသာစကားဖြင့်သာ တရားဝင်အချက်အလက်အဖြစ် ယူဆသင့်ပါသည်။ အရေးကြီးသော အချက်အလက်များအတွက် လူ့ပညာရှင်များ၏ ပရော်ဖက်ရှင်နယ် ဘာသာပြန်ခြင်းကို အကြံပြုပါသည်။ ဤဘာသာပြန်ချက်ကို အသုံးပြုရာမှ ဖြစ်ပေါ်လာနိုင်သည့် နားလည်မှုမှားယွင်းမှုများအတွက် ကျွန်ုပ်တို့သည် တာဝန်မယူပါ။