Skip to content

Commit

Permalink
AoT support
Browse files Browse the repository at this point in the history
Add support for native AoT for the libraries.
  • Loading branch information
martincostello committed Nov 9, 2023
1 parent 492d96b commit cedd813
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 8 deletions.
8 changes: 8 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@
<EnableNETAnalyzers>true</EnableNETAnalyzers>
</PropertyGroup>

<PropertyGroup Condition=" '$(IsPackable)' == 'true' ">
<EnableAotAnalyzer>true</EnableAotAnalyzer>
<EnableSingleFileAnalyzer>true</EnableSingleFileAnalyzer>
<EnableTrimAnalyzer>true</EnableTrimAnalyzer>
<IsAotCompatible>true</IsAotCompatible>
<IsTrimmable>true</IsTrimmable>
</PropertyGroup>

<PropertyGroup>
<EnablePackageValidation>$(IsPackable)</EnablePackageValidation>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion samples/Mvc.Client/Mvc.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<IsShipping>false</IsShipping>
<TargetFrameworks>$(DefaultNetCoreTargetFramework)</TargetFrameworks>
<TargetFramework>$(DefaultNetCoreTargetFramework)</TargetFramework>
<UserSecretsId>AspNet.Security.OAuth.Providers.Mvc.Client</UserSecretsId>
</PropertyGroup>

Expand Down
10 changes: 9 additions & 1 deletion src/AspNet.Security.OAuth.Trovo/TrovoAuthenticationHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using System.Text;
using System.Text.Encodings.Web;
using System.Text.Json;
using System.Text.Json.Serialization;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;

Expand Down Expand Up @@ -72,11 +73,13 @@ protected override async Task<OAuthTokenResponse> ExchangeCodeAsync([NotNull] OA
context.Properties.Items.Remove(OAuthConstants.CodeVerifierKey);
}

var content = JsonSerializer.Serialize(tokenRequestParameters, AppJsonSerializerContext.Default.DictionaryStringString);

using var request = new HttpRequestMessage(HttpMethod.Post, Options.TokenEndpoint);

request.Headers.Add(ClientIdHeaderName, Options.ClientId);
request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue(MediaTypeNames.Application.Json));
request.Content = new StringContent(JsonSerializer.Serialize(tokenRequestParameters), Encoding.UTF8, MediaTypeNames.Application.Json);
request.Content = new StringContent(content, Encoding.UTF8, MediaTypeNames.Application.Json);

using var response = await Backchannel.SendAsync(request, Context.RequestAborted);

Expand All @@ -91,6 +94,11 @@ protected override async Task<OAuthTokenResponse> ExchangeCodeAsync([NotNull] OA
return OAuthTokenResponse.Success(payload);
}

[JsonSerializable(typeof(Dictionary<string, string>))]
internal sealed partial class AppJsonSerializerContext : JsonSerializerContext
{
}

private static partial class Log
{
internal static async Task UserProfileErrorAsync(ILogger logger, HttpResponseMessage response, CancellationToken cancellationToken)
Expand Down
30 changes: 24 additions & 6 deletions src/AspNet.Security.OAuth.Yammer/YammerAuthenticationHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Security.Claims;
using System.Text.Encodings.Web;
using System.Text.Json;
using System.Text.Json.Serialization;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;

Expand Down Expand Up @@ -85,15 +86,32 @@ protected override async Task<OAuthTokenResponse> ExchangeCodeAsync([NotNull] OA
using var payload = JsonDocument.Parse(await response.Content.ReadAsStringAsync(Context.RequestAborted));
var accessToken = payload.RootElement.GetProperty("access_token").GetString("token");

var token = new
var token = new OAuthToken()
{
access_token = accessToken,
token_type = string.Empty,
refresh_token = string.Empty,
expires_in = string.Empty,
AccessToken = accessToken,
};

return OAuthTokenResponse.Success(JsonSerializer.SerializeToDocument(token));
return OAuthTokenResponse.Success(JsonSerializer.SerializeToDocument(token, AppJsonSerializerContext.Default.OAuthToken));
}

[JsonSerializable(typeof(OAuthToken))]
internal sealed partial class AppJsonSerializerContext : JsonSerializerContext
{
}

internal sealed class OAuthToken
{
[JsonPropertyName("access_token")]
public string? AccessToken { get; set; }

[JsonPropertyName("token_type")]
public string TokenType { get; set; } = string.Empty;

[JsonPropertyName("refresh_token")]
public string RefreshToken { get; set; } = string.Empty;

[JsonPropertyName("expires_in")]
public string ExpiresIn { get; set; } = string.Empty;
}

private static partial class Log
Expand Down

0 comments on commit cedd813

Please sign in to comment.