I have created web api project by selecting an empty project in vs.
I want to use jwt token-based authentication, I have installed nugate package IdentityModel.Tokens.Jwt.
I have added Authentication filter (created a custom class AuthenticatAtribue and implement iAuthenticationFilter)
please provide code for below methods
- public async Task AuthenticateAsync(HttpAuthenticationContext context, CancellationToken cancellationToken)
- {
-
- HttpRequestMessage request = context.Request;
- AuthenticationHeaderValue authorization = request.Headers.Authorization;
-
- if (authorization == null)
- {
- return;
- }
-
-
- if (authorization.Scheme != "Basic")
- {
- return;
- }
-
-
- if (String.IsNullOrEmpty(authorization.Parameter))
- {
- context.ErrorResult = "what should write here"
- return;
- }
- Tuple<string, string> userNameAndPassword = null;
- if (userNameAndPassword == null)
- {
-
- context.ActionContext.Response = new HttpResponseMessage(HttpStatusCode.Unauthorized);
- }
-
-
- var identity = new GenericIdentity(); what should i write here
- IPrincipal principal= new GenericPrincipal(identity, null);
- if (principal == null)
- {
- context.ErrorResult = null;
- }
-
- else
- {
- context.Principal = principal;
- }
- }
- public Task ChallengeAsync(HttpAuthenticationChallengeContext context, CancellationToken cancellationToken)
- {
please provide code for this section