From 2799aac9597c29cbfb805941a48adc86dbffa37f Mon Sep 17 00:00:00 2001 From: Uncled1023 Date: Tue, 20 Nov 2018 00:35:33 -0800 Subject: [PATCH] Fixed error handling --- Teknik/Startup.cs | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/Teknik/Startup.cs b/Teknik/Startup.cs index 0531e8f..fbeeb1c 100644 --- a/Teknik/Startup.cs +++ b/Teknik/Startup.cs @@ -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(); + } + } }