Update HandleRemoteCallbackAsync readability

This commit is contained in:
Troy Dai 2016-07-26 09:09:58 -07:00
parent 210c4b2061
commit 1c17bddc02
2 changed files with 10 additions and 11 deletions

View File

@ -8,7 +8,6 @@ using System.Net.Http;
using System.Net.Http.Headers; using System.Net.Http.Headers;
using System.Security.Claims; using System.Security.Claims;
using System.Text; using System.Text;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http.Authentication; using Microsoft.AspNetCore.Http.Authentication;

View File

@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System; using System;
using System.Net.Http;
using System.Security.Cryptography; using System.Security.Cryptography;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Builder;
@ -32,17 +31,18 @@ namespace Microsoft.AspNetCore.Authentication
protected virtual async Task<bool> HandleRemoteCallbackAsync() protected virtual async Task<bool> HandleRemoteCallbackAsync()
{ {
AuthenticateResult authResult = null; AuthenticationTicket ticket = null;
Exception exception = null; Exception exception = null;
try try
{ {
authResult = await HandleRemoteAuthenticateAsync(); var authResult = await HandleRemoteAuthenticateAsync();
if (authResult != null && authResult.Skipped == true) if (authResult != null && authResult.Skipped == true)
{ {
return false; return false;
} }
else if (authResult == null)
if (authResult == null)
{ {
exception = new InvalidOperationException("Invalid return state, unable to redirect."); exception = new InvalidOperationException("Invalid return state, unable to redirect.");
} }
@ -51,6 +51,8 @@ namespace Microsoft.AspNetCore.Authentication
exception = authResult?.Failure ?? exception = authResult?.Failure ??
new InvalidOperationException("Invalid return state, unable to redirect."); new InvalidOperationException("Invalid return state, unable to redirect.");
} }
ticket = authResult.Ticket;
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -67,18 +69,16 @@ namespace Microsoft.AspNetCore.Authentication
{ {
return true; return true;
} }
else if (errorContext.Skipped)
if (errorContext.Skipped)
{ {
return false; return false;
} }
else
{ throw new AggregateException("Unhandled remote failure.", exception);
throw new AggregateException("Unhandled remote failure.", exception);
}
} }
// We have a ticket if we get here // We have a ticket if we get here
var ticket = authResult.Ticket;
var context = new TicketReceivedContext(Context, Options, ticket) var context = new TicketReceivedContext(Context, Options, ticket)
{ {
ReturnUri = ticket.Properties.RedirectUri, ReturnUri = ticket.Properties.RedirectUri,