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:
parent
ed0f427f88
commit
2799aac959
@ -200,20 +200,7 @@ namespace Teknik
|
|||||||
RoleClaimType = JwtClaimTypes.Role
|
RoleClaimType = JwtClaimTypes.Role
|
||||||
};
|
};
|
||||||
|
|
||||||
options.Events.OnMessageReceived = ctx =>
|
options.Events.OnRemoteFailure = HandleOnRemoteFailure;
|
||||||
{
|
|
||||||
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;
|
|
||||||
};
|
|
||||||
});
|
});
|
||||||
|
|
||||||
services.AddAuthorization(options =>
|
services.AddAuthorization(options =>
|
||||||
@ -315,5 +302,13 @@ namespace Teknik
|
|||||||
routes.BuildRoutes(config);
|
routes.BuildRoutes(config);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task HandleOnRemoteFailure(RemoteFailureContext context)
|
||||||
|
{
|
||||||
|
if (context.Failure.Message.Contains("access_denied"))
|
||||||
|
context.Response.StatusCode = 403;
|
||||||
|
context.HandleResponse();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user