From 926c7fab4bac4b5b5ec58adc08d069edafc21132 Mon Sep 17 00:00:00 2001 From: Troy Dai Date: Fri, 5 Aug 2016 14:34:36 -0700 Subject: [PATCH] Use async-wait pattern in HandleAuthenticateOnceSafeAsync --- .../AuthenticationHandler.cs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/Microsoft.AspNetCore.Authentication/AuthenticationHandler.cs b/src/Microsoft.AspNetCore.Authentication/AuthenticationHandler.cs index 9141e8811d..d0528186c0 100644 --- a/src/Microsoft.AspNetCore.Authentication/AuthenticationHandler.cs +++ b/src/Microsoft.AspNetCore.Authentication/AuthenticationHandler.cs @@ -255,18 +255,15 @@ namespace Microsoft.AspNetCore.Authentication /// This method won't throw exception. Any exception thrown during the authentication will be convert /// to a AuthenticateResult. /// - protected Task HandleAuthenticateOnceSafeAsync() + protected async Task HandleAuthenticateOnceSafeAsync() { try { - return HandleAuthenticateOnceAsync().ContinueWith( - task => task.IsFaulted ? AuthenticateResult.Fail(task.Exception) : task.Result - ); + return await HandleAuthenticateOnceAsync(); } catch (Exception ex) { - // capture exception which is thrown before the task is actually started - return Task.FromResult(AuthenticateResult.Fail(ex)); + return AuthenticateResult.Fail(ex); } }