Skip to content

Commit 96a8229

Browse files
committed
Make Roles optional in ApiKey and Credential classes
Updated the `ApiKey` and `Credential` record classes to make the `Roles` parameter optional by providing a default value of `null`. This change allows for the creation of instances without explicitly specifying roles. Overrode the `Equals` method in both classes to provide custom equality comparisons. Refactored the `GetHashCode` methods to use expression-bodied members for simplicity.
1 parent f7302b4 commit 96a8229

2 files changed

Lines changed: 4 additions & 10 deletions

File tree

src/SimpleAuthentication.Abstractions/ApiKey/ApiKey.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace SimpleAuthentication.ApiKey;
66
/// <param name="Value">The API key value</param>
77
/// <param name="UserName">The user name associated with the current key</param>
88
/// <param name="Roles">The list of roles to assign to the user</param>
9-
public record class ApiKey(string Value, string UserName, IEnumerable<string> Roles)
9+
public record class ApiKey(string Value, string UserName, IEnumerable<string>? Roles = null)
1010
{
1111
/// <inheritdoc />
1212
public virtual bool Equals(ApiKey? other)
@@ -25,8 +25,5 @@ public virtual bool Equals(ApiKey? other)
2525
}
2626

2727
/// <inheritdoc />
28-
public override int GetHashCode()
29-
{
30-
return HashCode.Combine(Value, UserName);
31-
}
28+
public override int GetHashCode() => HashCode.Combine(Value, UserName);
3229
}

src/SimpleAuthentication.Abstractions/BasicAuthentication/Credential.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace SimpleAuthentication.BasicAuthentication;
66
/// <param name="UserName">The user name</param>
77
/// <param name="Password">The password</param>
88
/// <param name="Roles">The list of roles to assign to the user</param>
9-
public record class Credential(string UserName, string Password, IEnumerable<string> Roles)
9+
public record class Credential(string UserName, string Password, IEnumerable<string>? Roles = null)
1010
{
1111
/// <inheritdoc />
1212
public virtual bool Equals(Credential? other)
@@ -25,8 +25,5 @@ public virtual bool Equals(Credential? other)
2525
}
2626

2727
/// <inheritdoc />
28-
public override int GetHashCode()
29-
{
30-
return HashCode.Combine(UserName, Password);
31-
}
28+
public override int GetHashCode() => HashCode.Combine(UserName, Password);
3229
}

0 commit comments

Comments
 (0)