modelcontextprotocol / modelcontextprotocol/csharp-sdk

OAuth authentication request fails with MS Entra-ID

Open
#648 5 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

area-auth bug P2 ready for work
Dominant language
C#
Stars
4.5k
Forks
814
Avg merge
9d 19h
Merged PRs (30d)
4

Description

Hi, I just checked out the 0.3.0-preview.3 release and I modified the ProtectedMCPServer and ProtectedMCPClient samples to use MS Entra-ID as OAUTH server (see code snippets below):
The URL that is created by the mcp server for starting the OAUTH flow looks like this:

https://login.microsoftonline.com/<tenant-id>/oauth2/v2.0/authorize?client_id=xxxxx&redirect_uri=http%3a%2f%2flocalhost%3a1179%2fcallback&response_type=code&code_challenge=q09KNTJ_gyVsLnvjSSX46MYl_DcPTuNhosF6U5n9KOs&code_challenge_method=S256&resource=http%3a%2f%2flocalhost%3a7077%2f&scope=api%3a%2f%xxxx-xxxxx-xxxxx%2fmcp.tools

This url contains a resource and a scope parameter.
But MS Entra-ID complains about the resource parameter, as in OAuth 2.0 it should be the scope parameter used:
AADSTS901002: The 'resource' request parameter is not supported.

What is your idea or hint to solve this problem?

My changes:
Client: I added the ClientId which I configured in Azure portal

var transport = new SseClientTransport(new()
{
    Endpoint = new Uri(serverUrl),
    Name = "Secure Weather Client",
    OAuth = new()
    {
        ClientName = "ProtectedMcpClient",
        ClientId = "xxxx-xxxxx-xxxx-xxxx",
        RedirectUri = new Uri("http://localhost:1179/callback"),
        AuthorizationRedirectDelegate = HandleAuthorizationUrlAsync,
    }
}, httpClient, consoleLoggerFactory);

Server:
changed the OAuth server url:
var inMemoryOAuthServerUrl = "https://login.microsoftonline.com/<tenant-id>/v2.0";

changed ScopesSupported analog to the Azure Portal definition:
ScopesSupported = ["api://7e7eaf63-375a-4a0d-9872-574fdb5e08d6/mcp.tools"],

Thanks
Markus

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the ProtectedMCPServer and ProtectedMCPClient samples, then trace the OAuth options on SseClientTransport and the inMemoryOAuthServerUrl/ScopesSupported settings. Reproduce the authorization URL against MS Entra-ID and inspect where the resource parameter is added. Done means the generated request is accepted by Entra-ID using the configured scope and the OAuth flow completes.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
api, authentication
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.