Skip to content
This repository was archived by the owner on Jan 23, 2020. It is now read-only.

Commit 05c5e14

Browse files
committed
Adding error handling
1 parent 74b4fe9 commit 05c5e14

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

TodoListWebApp/App_Start/Startup.Auth.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System;
99
using System.Threading.Tasks;
1010
using TodoListWebApp.Utils;
11+
using Microsoft.IdentityModel.Protocols;
1112

1213
namespace TodoListWebApp
1314
{
@@ -42,11 +43,19 @@ public void ConfigureAuth(IApplicationBuilder app)
4243
options.PostLogoutRedirectUri = Configuration.Get("AzureAd:PostLogoutRedirectUri");
4344
options.Notifications = new OpenIdConnectAuthenticationNotifications
4445
{
45-
AuthorizationCodeReceived = OnAuthorizationCodeReceived
46+
AuthorizationCodeReceived = OnAuthorizationCodeReceived,
47+
AuthenticationFailed = OnAuthenticationFailed
4648
};
4749
});
4850
}
4951

52+
private Task OnAuthenticationFailed(AuthenticationFailedNotification<OpenIdConnectMessage, OpenIdConnectAuthenticationOptions> notification)
53+
{
54+
notification.HandleResponse();
55+
notification.Response.Redirect("/Home/Error?message=" + notification.Exception.Message);
56+
return Task.FromResult(0);
57+
}
58+
5059
public async Task OnAuthorizationCodeReceived(AuthorizationCodeReceivedNotification notification)
5160
{
5261
// Acquire a Token for the Graph API and cache it. In the TodoListController, we'll use the cache to acquire a token to the Todo List API

TodoListWebApp/Controllers/HomeController.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ public IActionResult Contact()
2626
return View();
2727
}
2828

29-
public IActionResult Error()
29+
public IActionResult Error(string message)
3030
{
31+
ViewBag.Message = message;
3132
return View("~/Views/Shared/Error.cshtml");
3233
}
3334
}

TodoListWebApp/Views/Shared/Error.cshtml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@
33
}
44

55
<h1 class="text-danger">Error.</h1>
6-
<h2 class="text-danger">An error occurred while processing your request.</h2>
6+
<h2 class="text-danger">We're having trouble signing you in.</h2>
7+
8+
@ViewBag.Message

0 commit comments

Comments
 (0)