Skip to content

WIP: Authorization Support (Using ASP.NET Core Native AuthN/AuthZ Integration) #377

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 130 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 88 commits
Commits
Show all changes
130 commits
Select commit Hold shift + click to select a range
0bd80e6
Experimental changes in a different direction
localden May 2, 2025
ac14bb2
Fix build issues
localden May 2, 2025
e8d9a23
Cleanup
localden May 2, 2025
4b3f9f7
Cleanup
localden May 2, 2025
8c790db
Tweaks to logic
localden May 2, 2025
b9ba2b9
Update Program.cs
localden May 2, 2025
47f1937
Cleanup
localden May 2, 2025
638bd35
Update HttpMcpServerBuilderExtensions.cs
localden May 2, 2025
d1f30f8
Tweaks to config
localden May 2, 2025
3713da6
Server configuration
localden May 2, 2025
9582111
Update based on feedback
localden May 2, 2025
8b89c2d
Pop the browser open - implement that in the SDK
localden May 2, 2025
c67ef6c
Tweaks to handles
localden May 2, 2025
a439840
Mock handler
localden May 2, 2025
932e678
Make sure I am not introducing unexpected changes
localden May 2, 2025
2151d00
Rename projects
localden May 2, 2025
3bfc258
Update sample project name and location
localden May 2, 2025
70146dd
Make sure definitions are not changed
localden May 2, 2025
ec25187
Functionality consolidation
localden May 2, 2025
a3926ee
Fix name
localden May 2, 2025
405db57
Organize things better
localden May 2, 2025
a0486d3
Cleanup
localden May 2, 2025
cc2f570
Update samples/ProtectedMCPServer/Program.cs
localden May 2, 2025
4e0b508
Update samples/ProtectedMCPServer/Program.cs
localden May 2, 2025
32f7b16
Update src/ModelContextProtocol.AspNetCore/Auth/McpAuthorizationExten…
localden May 2, 2025
b5728d0
Update samples/AspNetCoreSseServer/Program.cs
localden May 2, 2025
487bbd7
Update src/ModelContextProtocol.AspNetCore/Auth/McpAuthorizationExten…
localden May 2, 2025
22b7bcc
Update src/ModelContextProtocol.AspNetCore/Auth/McpAuthorizationExten…
localden May 2, 2025
a433f5a
Contextual rename
localden May 2, 2025
31f8ce9
Added overload for custom scheme
localden May 2, 2025
48bff9c
Introduce proper constants
localden May 2, 2025
991b29b
Simplify the handling of the WWW-Authenticate implementaiton
localden May 2, 2025
5c28b62
Update Program.cs
localden May 2, 2025
1a1e48c
Remove no longer used entity
localden May 2, 2025
008f521
Move to its own file.
localden May 2, 2025
6e23f4a
Placeholder setup
localden May 2, 2025
ff8a2b7
Fix server devx
localden May 2, 2025
03438d2
Defaults are applied here - no need to redeclare
localden May 2, 2025
a4f2495
Proper authorization configuration
localden May 2, 2025
2cdee6e
Simplify defaults
localden May 2, 2025
e79dcb8
Update McpEndpointRouteBuilderExtensions.cs
localden May 2, 2025
7903c75
Update Program.cs
localden May 2, 2025
fbb1817
Simplify tool configuration
localden May 2, 2025
6aef68b
Update config
localden May 2, 2025
1fd164c
Proper setup
localden May 3, 2025
0badaf8
Update McpAuthenticationHandler.cs
localden May 3, 2025
9209b61
Update samples
localden May 3, 2025
a90d01e
Consolidate some of the PKCE logic.
localden May 3, 2025
f3a3715
Consolidate some OAuth logic
localden May 3, 2025
e044475
Update McpAuthenticationHandler.cs
localden May 3, 2025
8790a35
Clean up the helper
localden May 3, 2025
4cff084
Minor changes to PRM doc logic
localden May 3, 2025
6b768d8
Cleanup
localden May 3, 2025
e3c5c21
Remove unused namespaces
localden May 3, 2025
d77368d
Placeholder for events
localden May 3, 2025
32f2265
Simplify policy setup
localden May 3, 2025
67342cd
Policy setup
localden May 3, 2025
b37a7b9
Escaping
localden May 3, 2025
583de65
Update server configuration
localden May 3, 2025
5f15bce
Validation.
localden May 3, 2025
7c33562
Delegate Base64 encoding to a more performant implementation
localden May 3, 2025
8d4c0c4
Make sure we're consistent
localden May 3, 2025
55bb471
Implement refresh token logic
localden May 3, 2025
debdb67
Stripping out the client implementation - this needs to be re-thought
localden May 4, 2025
003f5a0
Standardize namespacing
localden May 4, 2025
ceee919
Updating the approach for client auth
localden May 4, 2025
51bb38b
Cleanup for client logic
localden May 4, 2025
afd05af
Cleanup
localden May 4, 2025
a0fbec6
Simplify client logic
localden May 4, 2025
4073efd
Complete PRM doc properties. Update for consistency
localden May 4, 2025
2e06f59
Update for consistency
localden May 4, 2025
2d7da73
Work on the basic OAuth implementation in sample
localden May 4, 2025
10cf1f7
Token acquisition logic
localden May 4, 2025
2f84981
Update token logic
localden May 4, 2025
6768089
Significantly more basic provider implementation
localden May 4, 2025
cbb5c36
Working client-server interaction
localden May 4, 2025
0aeec19
Cleanup
localden May 4, 2025
531370a
Simplification
localden May 4, 2025
d511312
Cleanup for consistency
localden May 4, 2025
1496b41
Update with better DevEx
localden May 5, 2025
6b0b7ef
Cleanup
localden May 5, 2025
a9acba8
Delete AuthorizationServerUtils.cs
localden May 5, 2025
f8650f9
Cleanup
localden May 5, 2025
d4cc3ad
Multiple scheme support
localden May 5, 2025
31f611a
Multi-scheme support
localden May 5, 2025
3852be9
Cleaner implementation
localden May 5, 2025
8f926ba
Redundant call
localden May 5, 2025
b501d23
Merge branch 'main' into localden/experimental
localden May 6, 2025
c92343c
Update src/ModelContextProtocol/Authentication/AuthorizationDelegatin…
localden May 7, 2025
c57b85c
Update src/ModelContextProtocol/Authentication/AuthorizationDelegatin…
localden May 7, 2025
bb25dbd
Update src/ModelContextProtocol/Authentication/AuthorizationDelegatin…
localden May 7, 2025
291c7ec
Update src/ModelContextProtocol.AspNetCore/Authentication/McpAuthenti…
localden May 7, 2025
d72221d
Update src/ModelContextProtocol.AspNetCore/Authentication/McpAuthoriz…
localden May 7, 2025
2945083
Clean up scheme checks
localden May 7, 2025
26f44de
Use ConfigureAwait
localden May 7, 2025
ca0cdf3
Fix LINQ issue. Simplify best scheme match check
localden May 7, 2025
45c4b30
Proper array caching
localden May 7, 2025
627e1e4
Update 401 handling logic. Remove pragma warning silencing.
localden May 7, 2025
8903c42
Update based on feedback
localden May 7, 2025
a0275ea
Update the HttpClient configuration
localden May 7, 2025
05e3550
Update for cleanup
localden May 7, 2025
e8f7012
Update McpAuthenticationHandler.cs
localden May 7, 2025
94c39bc
No direct inclusion of HTTP client factory
localden May 8, 2025
0504aee
Remove legacy packages
localden May 8, 2025
7ac5c4a
Update signature and make test explicit
localden May 8, 2025
7b6c9fd
URL check
localden May 8, 2025
c406230
Changes based on feedback
localden May 8, 2025
b8954b3
Update to use a HttpClientFactory
localden May 8, 2025
0b030c2
Update McpAuthenticationHandler.cs
localden May 8, 2025
7c6e406
Update based on feedback
localden May 8, 2025
9420013
Update McpAuthenticationOptions.cs
localden May 8, 2025
4fbf2e9
Update McpAuthenticationOptions.cs
localden May 8, 2025
22962cf
Minor optimizations to the delegating handler
localden May 8, 2025
5c94158
Update AuthorizationDelegatingHandler.cs
localden May 8, 2025
0abea22
Update AuthorizationHelpers.cs
localden May 8, 2025
58a7a3d
Update AuthorizationHelpers.cs
localden May 8, 2025
b3b8168
Update AuthorizationHelpers.cs
localden May 8, 2025
aad7ad5
Update AuthorizationHelpers.cs
localden May 8, 2025
43eb6ff
Add record support for unauthorized result
localden May 8, 2025
9a4cea0
Update BasicOAuthAuthorizationProvider.cs
localden May 8, 2025
b3766aa
Update ProtectedResourceMetadata.cs
localden May 8, 2025
bc1566e
Proper check for resource metadata
localden May 8, 2025
0857b94
Update AuthorizationHelpers.cs
localden May 8, 2025
a40325d
.NET Standard 2.0 compatibility fix
localden May 8, 2025
a0cd4ad
Naming consistency
localden May 8, 2025
fe0d8ba
Update for consistency
localden May 8, 2025
0ff4ac4
Update src/ModelContextProtocol/Authentication/AuthorizationDelegatin…
localden May 10, 2025
3b46c8d
Update src/ModelContextProtocol/Protocol/Transport/SseClientTransport…
localden May 10, 2025
8c6e1dc
Merge branch 'main' into localden/experimental
localden May 10, 2025
3602c66
Merge branch 'main' into localden/experimental
localden May 12, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,7 @@ docs/api

# Rider
.idea/
.idea_modules/
.idea_modules/

# Misc project metadata
.specs/
14 changes: 5 additions & 9 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,39 @@
<System10Version>10.0.0-preview.3.25171.5</System10Version>
<MicrosoftExtensionsAIVersion>9.4.3-preview.1.25230.7</MicrosoftExtensionsAIVersion>
</PropertyGroup>

<!-- Product dependencies netstandard -->
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<PackageVersion Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="9.0.0-preview.5.24272.6" />
<PackageVersion Include="Microsoft.Bcl.Memory" Version="9.0.4" />
<PackageVersion Include="Microsoft.Extensions.Hosting.Abstractions" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.3" />
<PackageVersion Include="System.IO.Pipelines" Version="8.0.0" />
<PackageVersion Include="System.Text.Json" Version="8.0.5" />
<PackageVersion Include="System.Threading.Channels" Version="8.0.0" />
</ItemGroup>

<!-- Product dependencies LTS -->
<ItemGroup Condition="'$(TargetFramework)' == 'net8.0'">
<PackageVersion Include="Microsoft.Extensions.Hosting.Abstractions" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.3" />
<PackageVersion Include="System.IO.Pipelines" Version="8.0.0" />
</ItemGroup>

<!-- Product dependencies .NET 9 -->
<ItemGroup Condition="'$(TargetFramework)' == 'net9.0'">
<PackageVersion Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="9.0.0-preview.5.24306.11" />
<PackageVersion Include="Microsoft.Extensions.Hosting.Abstractions" Version="9.0.4" />
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.4" />
<PackageVersion Include="Microsoft.IdentityModel.Tokens" Version="7.4.1" />
<PackageVersion Include="System.IO.Pipelines" Version="9.0.4" />
</ItemGroup>

<!-- Product dependencies shared -->
<ItemGroup>
<PackageVersion Include="Microsoft.Extensions.AI.Abstractions" Version="$(MicrosoftExtensionsAIVersion)" />
<PackageVersion Include="Microsoft.Extensions.AI" Version="$(MicrosoftExtensionsAIVersion)" />
<PackageVersion Include="System.Net.ServerSentEvents" Version="$(System10Version)" />
</ItemGroup>

<ItemGroup>

<!-- Build Infra & Packaging -->
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="8.0.0" />

<!-- Testing dependencies -->
<PackageVersion Include="Anthropic.SDK" Version="5.0.0" />
<PackageVersion Include="coverlet.collector" Version="6.0.4">
Expand All @@ -61,8 +57,8 @@
<PackageVersion Include="OpenTelemetry.Exporter.InMemory" Version="1.11.2" />
<PackageVersion Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.11.2" />
<PackageVersion Include="OpenTelemetry.Instrumentation.Http " Version="1.11.0" />
<PackageVersion Include="OpenTelemetry.Extensions.Hosting" Version="1.11.2" />
<PackageVersion Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.11.1" />
<PackageVersion Include="OpenTelemetry.Extensions.Hosting" Version="1.11.2" />
<PackageVersion Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.11.1" />
<PackageVersion Include="Serilog.Extensions.Hosting" Version="9.0.0" />
<PackageVersion Include="Serilog.Extensions.Logging" Version="9.0.0" />
<PackageVersion Include="Serilog.Sinks.Console" Version="6.0.0" />
Expand Down
14 changes: 14 additions & 0 deletions ModelContextProtocol.sln
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ModelContextProtocol.AspNet
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ModelContextProtocol.AspNetCore.Tests", "tests\ModelContextProtocol.AspNetCore.Tests\ModelContextProtocol.AspNetCore.Tests.csproj", "{85557BA6-3D29-4C95-A646-2A972B1C2F25}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProtectedMCPClient", "samples\ProtectedMCPClient\ProtectedMCPClient.csproj", "{CF41BB82-4E3E-5E86-BCB6-0DF3A1B48CF2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProtectedMCPServer", "samples\ProtectedMCPServer\ProtectedMCPServer.csproj", "{80944644-54DC-2AFF-C60E-9885AD81E509}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -110,6 +114,14 @@ Global
{85557BA6-3D29-4C95-A646-2A972B1C2F25}.Debug|Any CPU.Build.0 = Debug|Any CPU
{85557BA6-3D29-4C95-A646-2A972B1C2F25}.Release|Any CPU.ActiveCfg = Release|Any CPU
{85557BA6-3D29-4C95-A646-2A972B1C2F25}.Release|Any CPU.Build.0 = Release|Any CPU
{CF41BB82-4E3E-5E86-BCB6-0DF3A1B48CF2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CF41BB82-4E3E-5E86-BCB6-0DF3A1B48CF2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CF41BB82-4E3E-5E86-BCB6-0DF3A1B48CF2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CF41BB82-4E3E-5E86-BCB6-0DF3A1B48CF2}.Release|Any CPU.Build.0 = Release|Any CPU
{80944644-54DC-2AFF-C60E-9885AD81E509}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{80944644-54DC-2AFF-C60E-9885AD81E509}.Debug|Any CPU.Build.0 = Debug|Any CPU
{80944644-54DC-2AFF-C60E-9885AD81E509}.Release|Any CPU.ActiveCfg = Release|Any CPU
{80944644-54DC-2AFF-C60E-9885AD81E509}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -128,6 +140,8 @@ Global
{17B8453F-AB72-99C5-E5EA-D0B065A6AE65} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
{37B6A5E0-9995-497D-8B43-3BC6870CC716} = {A2F1F52A-9107-4BF8-8C3F-2F6670E7D0AD}
{85557BA6-3D29-4C95-A646-2A972B1C2F25} = {2A77AF5C-138A-4EBB-9A13-9205DCD67928}
{CF41BB82-4E3E-5E86-BCB6-0DF3A1B48CF2} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
{80944644-54DC-2AFF-C60E-9885AD81E509} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {384A3888-751F-4D75-9AE5-587330582D89}
Expand Down
Loading
Loading