fix: Improve error handling for Azure-specific errors not captured in OAuth2 strategy

This commit is contained in:
Tom Moor
2021-04-18 22:41:27 -07:00
parent 04b8d7ae7b
commit 317c52df62
6 changed files with 35 additions and 27 deletions

View File

@@ -24,6 +24,17 @@ export default function createMiddleware(providerName: string) {
return ctx.redirect(`/?notice=auth-error`);
}
// Handle errors from Azure which come in the format: message, Trace ID,
// Correlation ID, Timestamp in these two query string parameters.
const { error, error_description } = ctx.request.query;
if (error && error_description) {
console.error(error_description);
// Display only the descriptive message to the user, log the rest
const description = error_description.split("Trace ID")[0];
return ctx.redirect(`/?notice=auth-error&description=${description}`);
}
if (result.user.isSuspended) {
return ctx.redirect("/?notice=suspended");
}