Skip to content

Commit a33a678

Browse files
committed
Change user and pass properties name in BasicAuthenticationFilter.
1 parent f6c2e28 commit a33a678

File tree

3 files changed

+16
-15
lines changed

3 files changed

+16
-15
lines changed

src/Serilog.Ui.Web/Authorization/BasicAuthenticationFilter.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1-
using System;
1+
using Microsoft.AspNetCore.Http;
2+
using System;
23
using System.Net.Http.Headers;
34
using System.Security.Cryptography;
45
using System.Text;
5-
using Microsoft.AspNetCore.Http;
66

77
namespace Serilog.Ui.Web.Authorization;
88

99
public class BasicAuthenticationFilter : IUiAuthorizationFilter
1010
{
11-
public string User { get; set; }
12-
public string Pass { get; set; }
13-
1411
private const string AuthenticationScheme = "Basic";
1512
internal const string AuthenticationCookieName = "SerilogAuth";
1613

14+
public string UserName { get; set; }
15+
16+
public string Password { get; set; }
17+
1718
public bool Authorize(HttpContext httpContext)
1819
{
1920
var header = httpContext.Request.Headers["Authorization"];
@@ -24,7 +25,7 @@ public bool Authorize(HttpContext httpContext)
2425
var authCookie = httpContext.Request.Cookies[AuthenticationCookieName];
2526
if (!string.IsNullOrWhiteSpace(authCookie))
2627
{
27-
var hashedCredentials = EncryptCredentials(User, Pass);
28+
var hashedCredentials = EncryptCredentials(UserName, Password);
2829
isAuthenticated = authCookie.Equals(hashedCredentials, StringComparison.OrdinalIgnoreCase);
2930
}
3031
}
@@ -39,7 +40,7 @@ public bool Authorize(HttpContext httpContext)
3940
if (CredentialsMatch(tokens))
4041
{
4142
isAuthenticated = true;
42-
var hashedCredentials = EncryptCredentials(User, Pass);
43+
var hashedCredentials = EncryptCredentials(UserName, Password);
4344
httpContext.Response.Cookies.Append(AuthenticationCookieName, hashedCredentials);
4445
}
4546
}
@@ -75,7 +76,7 @@ private static (string, string) ExtractAuthenticationTokens(AuthenticationHeader
7576

7677
private bool CredentialsMatch((string Username, string Password) tokens)
7778
{
78-
return tokens.Username == User && tokens.Password == Pass;
79+
return tokens.Username == UserName && tokens.Password == Password;
7980
}
8081

8182
private void SetChallengeResponse(HttpContext httpContext)

src/Serilog.Ui.Web/Serilog.Ui.Web.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<PropertyGroup>
44
<TargetFrameworks>netcoreapp3.1;net5.0;net6.0;net7.0</TargetFrameworks>
55
<LangVersion>latest</LangVersion>
6-
<Version>2.5.0</Version>
6+
<Version>2.5.1</Version>
77
</PropertyGroup>
88

99
<ItemGroup>

tests/Serilog.Ui.Web.Tests/Authorization/BasicAuthenticationFilterTests.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ public async Task Authorize_WithValidCredentials_ShouldReturnTrue()
1515
// Arrange
1616
var filter = new BasicAuthenticationFilter
1717
{
18-
User = "User",
19-
Pass = "P@ss"
18+
UserName = "User",
19+
Password = "P@ss"
2020
};
2121

2222
var httpContext = new DefaultHttpContext();
@@ -37,8 +37,8 @@ public async Task Authorize_WithInvalidCredentials_ShouldReturnFalse()
3737
// Arrange
3838
var filter = new BasicAuthenticationFilter
3939
{
40-
User = "User",
41-
Pass = "P@ss"
40+
UserName = "User",
41+
Password = "P@ss"
4242
};
4343

4444
var httpContext = new DefaultHttpContext();
@@ -57,8 +57,8 @@ public async Task Authorize_WithMissingAuthorizationHeader_ShouldSetChallengeRes
5757
// Arrange
5858
var filter = new BasicAuthenticationFilter
5959
{
60-
User = "User",
61-
Pass = "P@ss"
60+
UserName = "User",
61+
Password = "P@ss"
6262
};
6363

6464
var httpContext = new DefaultHttpContext();

0 commit comments

Comments
 (0)