Skip to content

Commit 8744b89

Browse files
committed
Readme updated
1 parent 3279ac0 commit 8744b89

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

README.md

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -132,18 +132,23 @@ using AspNetCore.Authentication.Basic;
132132
public class BasicUserValidationService : IBasicUserValidationService
133133
{
134134
private readonly ILogger<BasicUserValidationService> _logger;
135-
136-
public BasicUserValidationService(ILogger<BasicUserValidationService> logger)
135+
private readonly IUserRepository _userRepository;
136+
137+
public BasicUserValidationService(ILogger<BasicUserValidationService> logger, IUserRepository userRepository)
137138
{
138139
_logger = logger;
140+
_userRepository = userRepository;
139141
}
140142

141-
public Task<bool> IsValidAsync(string username, string password)
143+
public async Task<bool> IsValidAsync(string username, string password)
142144
{
143145
try
144146
{
145-
// write your implementation here and return true or false depending on the validation..
146-
return Task.FromResult(true);
147+
// NOTE: DO NOT USE THIS IMPLEMENTATION. THIS IS FOR DEMO PURPOSE ONLY
148+
// Write your implementation here and return true or false depending on the validation..
149+
var user = await _userRepository.GetUserByUsername(username);
150+
var isValid = user != null && user.Password == password;
151+
return isValid;
147152
}
148153
catch (Exception e)
149154
{
@@ -164,8 +169,8 @@ Required to be set if SuppressWWWAuthenticateHeader is not set to true. It is us
164169

165170
### SuppressWWWAuthenticateHeader
166171
Default value is false.
167-
When set to true, it will NOT return WWW-Authenticate response header when challenging un-authenticated requests.
168-
When set to false, it will return WWW-Authenticate response header when challenging un-authenticated requests.
172+
If set to true, it will NOT return WWW-Authenticate response header when challenging un-authenticated requests.
173+
If set to false, it will return WWW-Authenticate response header when challenging un-authenticated requests.
169174

170175
### IgnoreAuthenticationIfAllowAnonymous (available on ASP.NET Core 3.0 onwards)
171176
Default value is false.
@@ -177,15 +182,15 @@ The application may implement the interface fully, or it may create an instance
177182
- #### OnValidateCredentials
178183
A delegate assigned to this property will be invoked just before validating credentials.
179184
You must provide a delegate for this property for authentication to occur.
180-
In your delegate you should either call context.ValidationSucceeded() which will handle construction of authentication principal from the user details which will be assiged the context.Principal property and call context.Success(), or construct an authentication principal from the user details & attach it to the context.Principal property and finally call context.Success() method.
185+
In your delegate you should either call context.ValidationSucceeded() which will handle construction of authentication claims principal from the user details which will be assiged the context.Principal property and calls context.Success(), or construct an authentication claims principal from the user details and assign it to the context.Principal property and finally call context.Success() method.
181186
If only context.Principal property set without calling context.Success() method then, Success() method is automaticalled called.
182187

183188
- #### OnAuthenticationSucceeded
184189
A delegate assigned to this property will be invoked when the authentication succeeds. It will not be called if OnValidateCredentials delegate is assigned.
185190
It can be used for adding claims, headers, etc to the response.
186191

187192
- #### OnAuthenticationFailed
188-
A delegate assigned to this property will be invoked when the authentication fails.
193+
A delegate assigned to this property will be invoked when any unexpected exception is thrown within the library.
189194

190195
- #### OnHandleChallenge
191196
A delegate assigned to this property will be invoked before a challenge is sent back to the caller when handling unauthorized response.

0 commit comments

Comments
 (0)