Browse Source

Fixed error handling

tags/3.0.0^2
Teknikode 1 year ago
parent
commit
2799aac959
1 changed files with 9 additions and 14 deletions
  1. 9
    14
      Teknik/Startup.cs

+ 9
- 14
Teknik/Startup.cs 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();
}

}
}

Loading…
Cancel
Save