Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 6 additions & 6 deletions generators/app/templates/AuthenticationHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
using System.Net.Http.Headers;
using System.Security.Claims;
using System.Text.Encodings.Web;
using System.Text.Json;
using System.Threading.Tasks;
using JetBrains.Annotations;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.OAuth;
using Microsoft.AspNetCore.WebUtilities;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Newtonsoft.Json.Linq;

namespace AspNet.Security.OAuth.<%= name %>
{
Expand Down Expand Up @@ -51,13 +51,13 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
// TODO Append any additional query string parameters required
//endpoint = QueryHelpers.AddQueryString(endpoint, "token", tokens.AccessToken);

var request = new HttpRequestMessage(HttpMethod.Get, endpoint);
using var request = new HttpRequestMessage(HttpMethod.Get, endpoint);
request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

// TODO Add any HTTP request headers required
//request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", tokens.AccessToken);

var response = await Backchannel.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, Context.RequestAborted);
using var response = await Backchannel.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, Context.RequestAborted);
if (!response.IsSuccessStatusCode)
{
Logger.LogError("An error occurred while retrieving the user profile: the remote server " +
Expand All @@ -69,11 +69,11 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(
throw new HttpRequestException("An error occurred while retrieving the user profile from <%= name %>.");
}

var payload = JObject.Parse(await response.Content.ReadAsStringAsync());
using var payload = JsonDocument.Parse(await response.Content.ReadAsStringAsync());

var principal = new ClaimsPrincipal(identity);
var context = new OAuthCreatingTicketContext(principal, properties, Context, Scheme, Options, Backchannel, tokens, payload);
context.RunClaimActions(payload);
var context = new OAuthCreatingTicketContext(principal, properties, Context, Scheme, Options, Backchannel, tokens, payload.RootElement);
context.RunClaimActions();

await Options.Events.CreatingTicket(context);
return new AuthenticationTicket(context.Principal, context.Properties, Scheme.Name);
Expand Down
6 changes: 2 additions & 4 deletions generators/app/templates/Project.csproj
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<Import Project="..\..\build\packages.props" />

<PropertyGroup>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<TargetFramework>netcoreapp3.0</TargetFramework>
</PropertyGroup>

<PropertyGroup>
Expand All @@ -13,8 +11,8 @@
</PropertyGroup>

<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="JetBrains.Annotations" Version="$(JetBrainsVersion)" PrivateAssets="All" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.OAuth" Version="$(AspNetCoreVersion)" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "generator-aspnet-oauth",
"version": "2.0.0",
"version": "3.0.0",
"description": "Yeoman generator for OAuth Providers for ASP.NET Core",
"license": "MIT",
"main": "app/index.js",
Expand Down