Skip to content
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

Fix #378: Authentication handlers #379

Open
wants to merge 23 commits into
base: development
Choose a base branch
from

Conversation

antoineatstariongroup
Copy link
Contributor

Prerequisites

  • I have written a descriptive pull-request title
  • I have verified that there are no overlapping pull-requests open
  • I have verified that I am following the COMET-SDK code style guidelines
  • I have provided test coverage for my change (where applicable)

Description

Fix #378

Allows 3 kind of authentication:

  • Basic Authentication
  • Internal JWT authentication, with generation of token
  • External JWT authentication (requires EE)

@@ -2,7 +2,7 @@
// <copyright file="IAuthenticationPersonDao.cs" company="Starion Group S.A.">
// Copyright (c) 2015-2023 Starion Group S.A.
//
// Author: Sam Geren�, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Th�ate
// Author: Sam Geren�, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Th�ate
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something wrong with encoding?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@@ -108,12 +109,21 @@ public async Task<AuthenticationPerson> Authenticate(string username, string pas

return null;
}
catch (NpgsqlException ex)
{
transaction?.RollbackAsync();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to rollback? i don;t think we are writing anything, so nothing to rollback to

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

/// <summary>
/// Provides the expiration times of a generated JWT token, in minutes
/// </summary>
private const int ExpirationMinutes = 30;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i propose we make this configurable

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

<Exec Command="dotnet $(VersionFileCreatorDllPath) path:$(OutDir) " YieldDuringToolExecution="True" ConsoleToMSBuild="True" />
<Message Importance="High" Text="------ VersionFileCreator tool Finished ------ " />
</Target>

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this file can be removed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

/// <returns>Value of the assert</returns>
public static bool DoesAuthorizationHeaderMatches(this HttpRequest request, string expectedAuthorizationScheme)
{
var authorizationHeader = request.Headers.Authorization;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add argumentnull check

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

this.logger.LogWarning("Identifier claim {ClaimName} missing User Claims",
appConfigService.AppConfig.AuthenticationConfig.ExternalJwtAuthenticationConfig.IdentifierClaimName);

throw new AuthorizationException();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we not add textual description to exceptino, similar to log statemnt?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

});

app.MapGet("/logout", async (HttpRequest req, HttpResponse res) => {
app.MapPost("/logout", async (HttpRequest req, HttpResponse res) =>
{
//return webServiceAuthentication.LogOutResponse(req.HttpContext);
throw new NotImplementedException();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we implement this? not sure what we need to do though

app.MapGet("/username", async (HttpRequest req, HttpResponse res) =>
{
await res.WriteAsync(res.HttpContext.User.Identity.Name);
}).RequireAuthorization(new[] { BasicAuthenticationDefaults.AuthenticationScheme });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this only work with basic then?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, I support everything is necessary?

Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
1 Security Hotspot
51.3% Coverage on New Code (required ≥ 70%)
B Maintainability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Add] authentication plugin that supports open-id connect authentication
3 participants