1
0
mirror of https://git.teknik.io/Teknikode/Teknik.git synced 2023-08-02 14:16:22 +02:00

Fixed error handling

This commit is contained in:
Uncled1023 2018-11-20 00:35:33 -08:00
parent ed0f427f88
commit 2799aac959

View File

@ -200,20 +200,7 @@ namespace Teknik
RoleClaimType = JwtClaimTypes.Role
};
options.Events.OnMessageReceived = ctx =>
{
if (!string.IsNullOrEmpty(ctx.ProtocolMessage.Error))
{
// We need to throw an actual error (not the one they do)
switch (ctx.ProtocolMessage.Error)
{
case "access_denied":
ctx.Response.StatusCode = 403;
break;
}
}
return Task.CompletedTask;
};
options.Events.OnRemoteFailure = HandleOnRemoteFailure;
});
services.AddAuthorization(options =>
@ -315,5 +302,13 @@ namespace Teknik
routes.BuildRoutes(config);
});
}
private async Task HandleOnRemoteFailure(RemoteFailureContext context)
{
if (context.Failure.Message.Contains("access_denied"))
context.Response.StatusCode = 403;
context.HandleResponse();
}
}
}