1
- using System ;
1
+ using Microsoft . AspNetCore . Http ;
2
+ using System ;
2
3
using System . Net . Http . Headers ;
3
4
using System . Security . Cryptography ;
4
5
using System . Text ;
5
- using Microsoft . AspNetCore . Http ;
6
6
7
7
namespace Serilog . Ui . Web . Authorization ;
8
8
9
9
public class BasicAuthenticationFilter : IUiAuthorizationFilter
10
10
{
11
- public string User { get ; set ; }
12
- public string Pass { get ; set ; }
13
-
14
11
private const string AuthenticationScheme = "Basic" ;
15
12
internal const string AuthenticationCookieName = "SerilogAuth" ;
16
13
14
+ public string UserName { get ; set ; }
15
+
16
+ public string Password { get ; set ; }
17
+
17
18
public bool Authorize ( HttpContext httpContext )
18
19
{
19
20
var header = httpContext . Request . Headers [ "Authorization" ] ;
@@ -24,7 +25,7 @@ public bool Authorize(HttpContext httpContext)
24
25
var authCookie = httpContext . Request . Cookies [ AuthenticationCookieName ] ;
25
26
if ( ! string . IsNullOrWhiteSpace ( authCookie ) )
26
27
{
27
- var hashedCredentials = EncryptCredentials ( User , Pass ) ;
28
+ var hashedCredentials = EncryptCredentials ( UserName , Password ) ;
28
29
isAuthenticated = authCookie . Equals ( hashedCredentials , StringComparison . OrdinalIgnoreCase ) ;
29
30
}
30
31
}
@@ -39,7 +40,7 @@ public bool Authorize(HttpContext httpContext)
39
40
if ( CredentialsMatch ( tokens ) )
40
41
{
41
42
isAuthenticated = true ;
42
- var hashedCredentials = EncryptCredentials ( User , Pass ) ;
43
+ var hashedCredentials = EncryptCredentials ( UserName , Password ) ;
43
44
httpContext . Response . Cookies . Append ( AuthenticationCookieName , hashedCredentials ) ;
44
45
}
45
46
}
@@ -75,7 +76,7 @@ private static (string, string) ExtractAuthenticationTokens(AuthenticationHeader
75
76
76
77
private bool CredentialsMatch ( ( string Username , string Password ) tokens )
77
78
{
78
- return tokens . Username == User && tokens . Password == Pass ;
79
+ return tokens . Username == UserName && tokens . Password == Password ;
79
80
}
80
81
81
82
private void SetChallengeResponse ( HttpContext httpContext )
0 commit comments