Skip to content

Commit 31a7228

Browse files
Доработка веб-сокетов, v2 версия api для работы с багами (#24)
* Обновлен модуль аутентификации, поддержан sinalr хэдер. Написано v2 api для работы с багами. * Протестированое стабильное старое и новое api репортов и багов
1 parent 5f82135 commit 31a7228

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+607
-267
lines changed

backend/Bugget/Authentication/AuthSchemeNames.cs renamed to backend/Authentication/AuthSchemeNames.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace Bugget.Authentication;
1+
namespace Authentication;
22

33
public static class AuthSchemeNames
44
{
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net9.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Microsoft.AspNetCore.Authorization" Version="9.0.4" />
11+
<PackageReference Include="Microsoft.AspNetCore.Authentication" Version="2.3.0" />
12+
<PackageReference Include="Microsoft.AspNetCore.Authentication.Abstractions" Version="2.3.0" />
13+
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.3.0" />
14+
</ItemGroup>
15+
16+
</Project>

backend/Bugget/Authentication/LdapAuthAttribute.cs renamed to backend/Authentication/LdapAuthAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using Microsoft.AspNetCore.Authorization;
22

3-
namespace Bugget.Authentication;
3+
namespace Authentication;
44

55
/// <summary>
66
/// Аутентификация по LDAP

backend/Bugget/Authentication/ServiceCollectionExtensions.cs renamed to backend/Authentication/ServiceCollectionExtensions.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Microsoft.AspNetCore.Authentication;
2+
using Microsoft.Extensions.DependencyInjection;
23

3-
namespace Bugget.Authentication;
4+
namespace Authentication;
45

56
public static class ServiceCollectionExtensions
67
{

backend/Bugget/Authentication/UserAuthHandler.cs renamed to backend/Authentication/UserAuthHandler.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
using System.Security.Claims;
22
using System.Text.Encodings.Web;
3-
using Bugget.Entities.Constants;
43
using Microsoft.AspNetCore.Authentication;
4+
using Microsoft.Extensions.Logging;
55
using Microsoft.Extensions.Options;
66

7-
namespace Bugget.Authentication;
7+
namespace Authentication;
88

99
public class UserAuthHandler(
1010
IOptionsMonitor<AuthenticationSchemeOptions> options,
1111
ILoggerFactory logger,
12-
UrlEncoder encoder)
13-
: AuthenticationHandler<AuthenticationSchemeOptions>(options, logger, encoder)
12+
UrlEncoder encoder,
13+
ISystemClock clock)
14+
: AuthenticationHandler<AuthenticationSchemeOptions>(options, logger, encoder, clock)
1415
{
15-
private static readonly string? LdapUserIdKey = Environment.GetEnvironmentVariable(EnvironmentConstants.LdapUserIdKeyName);
16+
private static readonly string? LdapUserIdKey = Environment.GetEnvironmentVariable("LDAP_USER_ID_KEY");
1617

1718
protected override Task<AuthenticateResult> HandleAuthenticateAsync()
1819
{
@@ -29,15 +30,15 @@ protected override Task<AuthenticateResult> HandleAuthenticateAsync()
2930

3031
var claims = new[]
3132
{
32-
new Claim(ClaimsIdentity.DefaultNameClaimType, userId)
33+
new Claim(ClaimTypes.NameIdentifier, userId),
3334
};
3435

3536
return Task.FromResult(AuthenticateResult.Success(CreateTicket(claims)));
3637
}
3738

3839
private AuthenticationTicket CreateTicket(IEnumerable<Claim> claims)
3940
{
40-
var identity = new ClaimsIdentity(claims, Scheme.Name, ClaimsIdentity.DefaultNameClaimType, ClaimsIdentity.DefaultRoleClaimType);
41+
var identity = new ClaimsIdentity(claims, Scheme.Name, ClaimTypes.NameIdentifier, ClaimsIdentity.DefaultRoleClaimType);
4142
var principal = new ClaimsPrincipal(identity);
4243
var ticket = new AuthenticationTicket(principal, Scheme.Name);
4344
return ticket;
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
using System.Security.Claims;
22

3-
namespace Bugget.Authentication;
3+
namespace Authentication;
44

55
public class UserIdentity(ClaimsPrincipal principal)
66
{
77
public string Id { get; init; } = principal.Identity?.Name ?? "undefined_id";
88
public string? TeamId { get; init; } = principal.FindFirst("team_id")?.Value;
99
public string? OrganizationId { get; init; } = principal.FindFirst("organization_id")?.Value;
10+
public string? SignalRConnectionId { get; init; } = principal.FindFirst("signalr_connection_id")?.Value;
1011
}

backend/Bugget/Authentication/UserIdentityExtensions.cs renamed to backend/Authentication/UserIdentityExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using System.Security.Claims;
22

3-
namespace Bugget.Authentication;
3+
namespace Authentication;
44

55
public static class UserIdentityExtensions
66
{

backend/Bugget.BO/Bugget.BO.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<ProjectReference Include="..\Bugget.ExternalClients\Bugget.ExternalClients.csproj" />
1111
<ProjectReference Include="..\Monade\Monade.csproj" />
1212
<ProjectReference Include="..\TaskQueue\TaskQueue.csproj" />
13+
<ProjectReference Include="..\Authentication\Authentication.csproj" />
1314
</ItemGroup>
1415

1516
</Project>

backend/Bugget.BO/Errors/BoErrors.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ public static class BoErrors
88
public static readonly NotFoundError NotFoundError = new NotFoundError("not_found", "Объект не найден");
99
public static readonly NotFoundError ReportNotFoundError = new NotFoundError("report_not_found", "Репорт не найден");
1010
public static readonly InternalServerError InternalServerError = new InternalServerError("internal_server_error", "Внутреняя ошибка сервера");
11+
public static readonly BadRequestError BugMustHaveOneField = new BadRequestError("bug_must_have_one_field", "Баг должен содержать хотя бы одно поле");
1112
}

backend/Bugget.BO/Mappers/BugMapper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace Bugget.BO.Mappers;
1111

1212
public static class BugMapper
1313
{
14-
public static Bug ToBug(this BugDto bug, int reportId, string creatorUserId)
14+
public static Bug ToBug(this BugDtoObsolete bug, int reportId, string creatorUserId)
1515
{
1616
return new Bug
1717
{
@@ -76,7 +76,7 @@ public static BugView ToView(this BugDbModel bug, IReadOnlyDictionary<string, Em
7676
};
7777
}
7878

79-
public static BugUpdate ToBugUpdate(this BugUpdateDto bugUpdateDto, int reportId, int bugId, string userId)
79+
public static BugUpdate ToBugUpdate(this BugUpdateDtoObsolete bugUpdateDto, int reportId, int bugId, string userId)
8080
{
8181
return new BugUpdate
8282
{

0 commit comments

Comments
 (0)