Skip to content

OAuth token refresh fails with AADSTS9010010 #1587

Open

Description

@sanjaydebnath

Describe the bug
We are using C# SDK to build our MCP and host in AKS which is oAuth protected. When we add the server in github cli at the beginning, the auth works fine. But while calling refresh_token after ~1 hour (when the access token expires) and the SDK attempts a silent refresh, the call fails with this with AADSTS9010010 (The resource parameter provided in the request doesn't match with the requested scopes).

To Reproduce
Steps to reproduce the behavior:

  1. Add a http mcp server protected by oAuth (I used internal Microsoft tenant to register an app to protect the MCP endpoint). The metadata looks like below
builder.Services.AddAuthentication(options =>
{
    options.DefaultChallengeScheme = McpAuthenticationDefaults.AuthenticationScheme;
    options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
})
.AddJwtBearer(options =>
{
    options.MapInboundClaims = false;
    options.Authority = $"{instance}/{tenantId}/v2.0";
    options.TokenValidationParameters = new TokenValidationParameters
    {
        ValidateIssuer = true,
        ValidateAudience = true,
        ValidateLifetime = true,
        ValidateIssuerSigningKey = true,
        ValidAudiences = new[] { EntraAppConstants.APIAppClientId, apiAppName },
        ValidIssuers = new[]
        {
            $"{instance}/{tenantId}/v2.0",
            $"https://sts.windows.net/{tenantId}/",
            $"{instance}/{ameTenantId}/v2.0",
            $"https://sts.windows.net/{ameTenantId}/",
        },
        NameClaimType = "name",
        RoleClaimType = "roles",
    };

    options.MetadataAddress = $"{instance}/{tenantId}/v2.0/.well-known/openid-configuration";

})
.AddMcp(options =>
{
    var metadata = new ModelContextProtocol.Authentication.ProtectedResourceMetadata
    {
        AuthorizationServers = { $"{instance}/{tenantId}/v2.0", $"{instance}/{ameTenantId}/v2.0" },
        ScopesSupported = [$"{apiAppName}/my_scope"],
    };

    options.ResourceMetadata = metadata;
});
{
"resource": "https://mcp.******.azure.com/",
"authorization_servers": [
"https://login.microsoftonline.com/72f988bf-86f1-41af-91ab-2d7cd011db47/v2.0",
"https://login.microsoftonline.com/**************/v2.0"
],
"bearer_methods_supported": [
"header"
],
"scopes_supported": [
"api://my_app_name/my_scope"
]
}

Connect the mcp from cli & get 1st time auth done, do some tool calling activity & leave the cli open for an hour. After an hour come back & try to do another tool call, and the call will fail with auth error.

Additional context
Seems same issue is present here too for python SDK: 2578

Activity

  1. added
    P2Moderate issues, valuable feature requests
    on Jul 20, 2026
  2. added this to the 2.x milestone on Jul 20, 2026
  3. spaulah commented on Nov 15, 2026

    @spaulah

    Thanks for all the work on the auth support. I've gotten a lot out of this SDK and wanted to help move this one along.

    On the open question from #1883 (which client sends the failing request, and whether it uses the correct resource): I tried this in an Entra ID test tenant with the C# client on current main (64cfd66b, which includes #1967).

    • With the Application ID URI set to the MCP server URL (Step 3 of the doc linked in OAuth authentication request fails with MS Entra-ID #648), the code exchange and the silent refresh both succeeded.
    • Without it, the C# client failed with AADSTS9010010 on the first code exchange, not on refresh.

    So in my testing the C# client sends the PRM resource correctly, and a failure that only appears at refresh may be coming from a different client (the original report mentions the GitHub CLI).

    To get that far I had to work around Entra not advertising code_challenge_methods_supported in its metadata. If that isn't already tracked, I'd be happy to open a separate issue for it. I can also share the repro setup if it would be useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Moderate issues, valuable feature requestsarea-authbugSomething isn't working

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions