fix AllowAnonymous

This commit is contained in:
pavelbannov 2019-05-31 13:47:47 +03:00
parent 3bb4c88929
commit af712c7ea8
3 changed files with 12 additions and 7 deletions

View File

@ -29,11 +29,11 @@ namespace ASC.Web.Api.Handlers
var token = Context.Request.Cookies["asc_auth_key"] ?? Context.Request.Headers["Authorization"];
var result = SecurityContext.AuthenticateMe(token);
if (!result)
{
throw new AuthenticationException(HttpStatusCode.Unauthorized.ToString());
}
return Task.FromResult(AuthenticateResult.Success(new AuthenticationTicket(Context.User, new AuthenticationProperties(), Scheme.Name)));
return Task.FromResult(
result ?
AuthenticateResult.Success(new AuthenticationTicket(Context.User, new AuthenticationProperties(), Scheme.Name)) :
AuthenticateResult.Fail(new AuthenticationException(HttpStatusCode.Unauthorized.ToString()))
);
}
}
}

View File

@ -30,6 +30,11 @@ namespace ASC.Api.Core.Middleware
try
{
await next(context);
if(context.Response.StatusCode == 401)
{
error = new AuthenticationException(HttpStatusCode.Unauthorized.ToString());
}
}
catch(AuthenticationException exception)
{

View File

@ -72,10 +72,10 @@ namespace ASC.Web.Api
app.UseRouting();
app.UseResponseWrapper();
app.UseAuthentication();
app.UseResponseWrapper();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();