aspnet-contrib / AspNet.Security.OAuth.Providers

OAuth 2.0 social authentication providers for ASP.NET Core
Apache License 2.0
2.34k stars 533 forks source link

AoT support #815

Closed martincostello closed 8 months ago

martincostello commented 8 months ago

Add support for native AoT for the libraries.

After my adventures getting this working for Polly, I thought I'd give it a try here, and it seemed to be relatively simple.

The only changes required were for the Trovo and Yammer providers to use AoT-friendly JSON serialization. Everything else appears to Just Work™️.

Tested by:

  1. Adding the following to the Mvc.Sample project file:
    <PropertyGroup>
      <PublishAot>true</PublishAot>
      <SelfContained>true</SelfContained>
      <TrimmerSingleWarn>false</TrimmerSingleWarn>
    </PropertyGroup>
    <ItemGroup>
      <TrimmerRootAssembly Include="@(ProjectReference->'%(Filename)')" />
    </ItemGroup>
  2. Commenting out services.AddMvc() (because it's not supported)
  3. Running dotnet publish for the Mvc.Sample project.

Only one warning is output, and that's from MVC's own lack of support.

ILC : Trim analysis warning IL2026: Microsoft.AspNetCore.Mvc.Routing.ConventionalRouteEntry.ConventionalRouteEntry(String,String,RouteValueDictionary,IDictionary`2<String,Object>,RouteValueDictionary,Int32,List`1<Acion`1<EndpointBuilder>>,List`1<Action`1<EndpointBuilder>>): Using member 'Microsoft.AspNetCore.Routing.Patterns.RoutePatternFactory.Parse(String,Object,Object)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. This API may perform reflection on supplied parameters which may be trimmed if not referenced directly. Initialize a RouteValueDictionary with route values to avoid this issue. [C:\Coding\aspnet-contrib\AspNet.Security.OAuth.Providers\samples\Mvc.Client\Mvc.Client.csproj]

Thoughts?

kevinchalet commented 8 months ago

Everything else appears to Just Work™️.

Looks almost too easy to be true 🤣

martincostello commented 8 months ago

Cool - I'll just do a double-check locally that I haven't messed up the serialization format and then I'll merge this in for the v8 release.

martincostello commented 8 months ago

Yep, it works as expected. The payloads before and after are:

Trovo

{"redirect_uri":"http://localhost/signin-trovo","code":"a6ed8e7f-471f-44f1-903b-65946475f351","client_secret":"my-client-secret","grant_type":"authorization_code"}

Yammer

{"access_token":"ajsdfiasd7f6asdf8o","token_type":"","refresh_token":"","expires_in":""}