1
0
mirror of https://github.com/bitwarden/server.git synced 2025-07-05 18:12:48 -05:00

Enable Nullable In Auth Repositories (#4600)

This commit is contained in:
Justin Baur
2024-08-09 09:31:06 -04:00
committed by GitHub
parent 374ef95656
commit 56d6c91b25
25 changed files with 76 additions and 30 deletions

View File

@ -2,17 +2,19 @@
using System.Text.Json.Serialization;
using Bit.Core.Utilities;
#nullable enable
namespace Bit.Core.Auth.Repositories.Cosmos;
public class Base64IdStringConverter : JsonConverter<string>
public class Base64IdStringConverter : JsonConverter<string?>
{
public override string Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) =>
public override string? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) =>
ToKey(reader.GetString());
public override void Write(Utf8JsonWriter writer, string value, JsonSerializerOptions options) =>
public override void Write(Utf8JsonWriter writer, string? value, JsonSerializerOptions options) =>
writer.WriteStringValue(ToId(value));
public static string ToId(string key)
public static string? ToId(string? key)
{
if (key == null)
{
@ -21,7 +23,7 @@ public class Base64IdStringConverter : JsonConverter<string>
return CoreHelpers.TransformToBase64Url(key);
}
public static string ToKey(string id)
public static string? ToKey(string? id)
{
if (id == null)
{

View File

@ -6,6 +6,8 @@ using Bit.Core.Settings;
using Bit.Core.Utilities;
using Microsoft.Azure.Cosmos;
#nullable enable
namespace Bit.Core.Auth.Repositories.Cosmos;
public class GrantRepository : IGrantRepository
@ -34,7 +36,7 @@ public class GrantRepository : IGrantRepository
_container = _database.GetContainer("grant");
}
public async Task<IGrant> GetByKeyAsync(string key)
public async Task<IGrant?> GetByKeyAsync(string key)
{
var id = Base64IdStringConverter.ToId(key);
try

View File

@ -1,6 +1,8 @@
using Bit.Core.Auth.Entities;
using Bit.Core.Auth.Models.Data;
#nullable enable
namespace Bit.Core.Repositories;
public interface IAuthRequestRepository : IRepository<AuthRequest, Guid>

View File

@ -2,6 +2,8 @@
using Bit.Core.Auth.Models.Data;
using Bit.Core.Auth.UserFeatures.UserKey;
#nullable enable
namespace Bit.Core.Repositories;
public interface IEmergencyAccessRepository : IRepository<EmergencyAccess, Guid>
@ -9,7 +11,7 @@ public interface IEmergencyAccessRepository : IRepository<EmergencyAccess, Guid>
Task<int> GetCountByGrantorIdEmailAsync(Guid grantorId, string email, bool onlyRegisteredUsers);
Task<ICollection<EmergencyAccessDetails>> GetManyDetailsByGrantorIdAsync(Guid grantorId);
Task<ICollection<EmergencyAccessDetails>> GetManyDetailsByGranteeIdAsync(Guid granteeId);
Task<EmergencyAccessDetails> GetDetailsByIdGrantorIdAsync(Guid id, Guid grantorId);
Task<EmergencyAccessDetails?> GetDetailsByIdGrantorIdAsync(Guid id, Guid grantorId);
Task<ICollection<EmergencyAccessNotify>> GetManyToNotifyAsync();
Task<ICollection<EmergencyAccessDetails>> GetExpiredRecoveriesAsync();

View File

@ -1,10 +1,12 @@
using Bit.Core.Auth.Models.Data;
#nullable enable
namespace Bit.Core.Auth.Repositories;
public interface IGrantRepository
{
Task<IGrant> GetByKeyAsync(string key);
Task<IGrant?> GetByKeyAsync(string key);
Task<ICollection<IGrant>> GetManyAsync(string subjectId, string sessionId, string clientId, string type);
Task SaveAsync(IGrant obj);
Task DeleteByKeyAsync(string key);

View File

@ -1,11 +1,13 @@
using Bit.Core.Auth.Entities;
using Bit.Core.Repositories;
#nullable enable
namespace Bit.Core.Auth.Repositories;
public interface ISsoConfigRepository : IRepository<SsoConfig, long>
{
Task<SsoConfig> GetByOrganizationIdAsync(Guid organizationId);
Task<SsoConfig> GetByIdentifierAsync(string identifier);
Task<SsoConfig?> GetByOrganizationIdAsync(Guid organizationId);
Task<SsoConfig?> GetByIdentifierAsync(string identifier);
Task<ICollection<SsoConfig>> GetManyByRevisionNotBeforeDate(DateTime? notBefore);
}

View File

@ -1,10 +1,12 @@
using Bit.Core.Auth.Entities;
using Bit.Core.Repositories;
#nullable enable
namespace Bit.Core.Auth.Repositories;
public interface ISsoUserRepository : IRepository<SsoUser, long>
{
Task DeleteAsync(Guid userId, Guid? organizationId);
Task<SsoUser> GetByUserIdOrganizationIdAsync(Guid organizationId, Guid userId);
Task<SsoUser?> GetByUserIdOrganizationIdAsync(Guid organizationId, Guid userId);
}

View File

@ -3,11 +3,13 @@ using Bit.Core.Auth.Models.Data;
using Bit.Core.Auth.UserFeatures.UserKey;
using Bit.Core.Repositories;
#nullable enable
namespace Bit.Core.Auth.Repositories;
public interface IWebAuthnCredentialRepository : IRepository<WebAuthnCredential, Guid>
{
Task<WebAuthnCredential> GetByIdAsync(Guid id, Guid userId);
Task<WebAuthnCredential?> GetByIdAsync(Guid id, Guid userId);
Task<ICollection<WebAuthnCredential>> GetManyByUserIdAsync(Guid userId);
Task<bool> UpdateAsync(WebAuthnCredential credential);
UpdateEncryptedDataForKeyRotation UpdateKeysForRotationAsync(Guid userId, IEnumerable<WebAuthnLoginRotateKeyData> credentials);

View File

@ -388,6 +388,8 @@ public static class CoreHelpers
/// <returns>Base64 standard formatted string</returns>
public static string TransformFromBase64Url(string input)
{
// TODO: .NET 9 Ships Base64Url in box, investigate replacing this usage with that
// Ref: https://github.com/dotnet/runtime/pull/102364
var output = input;
// 62nd char of encoding
output = output.Replace('-', '+');