Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Update GitLab for ASP.NET Core 3.0
Update the GitLab provider to support ASP.NET Core 3.0.
  • Loading branch information
martincostello committed Jul 23, 2019
commit 7e718151012d514cbeb3b4c82a71122703a1a717
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ project.lock.json

# Build results

.dotnetcli/
artifacts/
coverage/
coverage.*
[Dd]ebug/
[Rr]elease/
x64/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<Import Project="..\..\build\packages.props" />

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

<PropertyGroup>
Expand All @@ -13,8 +13,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>
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ public static AuthenticationBuilder AddGitLab(
/// <param name="configuration">The delegate used to configure the GitLab options.</param>
/// <returns>The <see cref="AuthenticationBuilder"/>.</returns>
public static AuthenticationBuilder AddGitLab(
[NotNull] this AuthenticationBuilder builder, [NotNull] string scheme,
[NotNull] this AuthenticationBuilder builder,
[NotNull] string scheme,
[NotNull] Action<GitLabAuthenticationOptions> configuration)
{
return builder.AddGitLab(scheme, GitLabAuthenticationDefaults.DisplayName, configuration);
Expand All @@ -67,7 +68,8 @@ public static AuthenticationBuilder AddGitLab(
/// <returns>The <see cref="AuthenticationBuilder"/>.</returns>
public static AuthenticationBuilder AddGitLab(
[NotNull] this AuthenticationBuilder builder,
[NotNull] string scheme, [NotNull] string caption,
[NotNull] string scheme,
[NotNull] string caption,
[NotNull] Action<GitLabAuthenticationOptions> configuration)
{
return builder.AddOAuth<GitLabAuthenticationOptions, GitLabAuthenticationHandler>(scheme, caption, configuration);
Expand Down
13 changes: 8 additions & 5 deletions src/AspNet.Security.OAuth.GitLab/GitLabAuthenticationHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
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.Extensions.Logging;
using Microsoft.Extensions.Options;
using Newtonsoft.Json.Linq;

namespace AspNet.Security.OAuth.GitLab
{
Expand All @@ -29,7 +29,10 @@ public GitLabAuthenticationHandler(
{
}

protected override async Task<AuthenticationTicket> CreateTicketAsync(ClaimsIdentity identity, AuthenticationProperties properties, OAuthTokenResponse tokens)
protected override async Task<AuthenticationTicket> CreateTicketAsync(
ClaimsIdentity identity,
AuthenticationProperties properties,
OAuthTokenResponse tokens)
{
// Get the GitLab user
var request = new HttpRequestMessage(HttpMethod.Get, Options.UserInformationEndpoint);
Expand All @@ -48,11 +51,11 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync(ClaimsIden
throw new HttpRequestException("An error occurred while retrieving the user profile.");
}

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
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,18 @@

namespace AspNet.Security.OAuth.GitLab
{
/// <summary>
/// Defines a set of options used by <see cref="GitLabAuthenticationHandler"/>.
/// </summary>
public class GitLabAuthenticationOptions : OAuthOptions
{
/// <summary>
/// Initializes a new <see cref="GitLabAuthenticationOptions"/>.
/// Initializes a new instance of the <see cref="GitLabAuthenticationOptions"/> class.
/// </summary>
public GitLabAuthenticationOptions()
{
CallbackPath = GitLabAuthenticationDefaults.CallbackPath;
AuthorizationEndpoint = GitLabAuthenticationDefaults.AuthorizationEndpoint;
CallbackPath = GitLabAuthenticationDefaults.CallbackPath;
TokenEndpoint = GitLabAuthenticationDefaults.TokenEndpoint;
UserInformationEndpoint = GitLabAuthenticationDefaults.UserInformationEndpoint;

Expand Down