problem come when valid token success the problem is next request no give me result of action executed so that what i do for that working
problem is when success valid token is OK it reach until next but not display after that action that have result
in both cases if valid token or not valid return invalid token message .
- public async Task InvokeAsync(HttpContext context, DataContext dataContext)
- {
- var validKey = false;
- // than you logic to validate token
- var CheckExistAccessToken = context.Request.Headers.ContainsKey("Authorization");
- var AccessTokenValue = context.Request.Headers["Authorization"].SingleOrDefault();
- //var token = AccessTokenValue.Substring(AccessTokenValue.IndexOf(' ') + 1);
- if (CheckExistAccessToken)
- {
- bool isvalid = _tockenvalidator.ValidateToken(AccessTokenValue);
- if (isvalid)
- {
- validKey = true;
- }
- else
- {
- validKey = false;
- }
- }
- if (!validKey)
- {
- context.Response.StatusCode = (int)HttpStatusCode.Forbidden;
- await context.Response.WriteAsync("Invalid Token");
- }
- //if valid than next middleware Invoke
- else
- {
- await _next.Invoke(context);
- // not return to me action i write on postman and return also message not valid token
- }
- }
- }
- public static class TokenExtensions
- {
- public static IApplicationBuilder UseTokenAuth(this IApplicationBuilder builder)
- {
- return builder.UseMiddleware
(); - }
- }
- on configure of startup.cs
- if (env.IsDevelopment())
- {
- app.UseDeveloperExceptionPage();
- }
- else
- {
- // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
- app.UseHsts();
- }
- app.UseTokenAuth();
- app.UseHttpsRedirection();
- app.UseStatusCodePagesWithReExecute("/error/{0}");
- app.UseMvc();
- app.UseCors("CorsData");
ahmed salahPosted Sep 14, 2019, 6:07 AM
Sai Kumar KoonaPosted Sep 14, 2019, 2:19 AM