Clean up auth types, copywrite headers, file names, exceptions.
This commit is contained in:
parent
91242245f3
commit
38fb911afc
|
|
@ -1,9 +1,10 @@
|
|||
using Microsoft.AspNet.Builder;
|
||||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.Framework.DependencyInjection;
|
||||
using Microsoft.AspNet.Security.OpenIdConnect;
|
||||
using Microsoft.AspNet.Http.Security;
|
||||
using Microsoft.AspNet.Security;
|
||||
using Microsoft.AspNet.Security.Cookies;
|
||||
using Microsoft.AspNet.Security.OpenIdConnect;
|
||||
using Microsoft.Framework.DependencyInjection;
|
||||
|
||||
namespace OpenIdConnectSample
|
||||
{
|
||||
|
|
@ -16,14 +17,13 @@ namespace OpenIdConnectSample
|
|||
services.AddDataProtection();
|
||||
services.Configure<ExternalAuthenticationOptions>(options =>
|
||||
{
|
||||
options.SignInAsAuthenticationType = OpenIdConnectAuthenticationDefaults.AuthenticationType;
|
||||
options.SignInAsAuthenticationType = CookieAuthenticationDefaults.AuthenticationType;
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
app.UseCookieAuthentication(options =>
|
||||
{
|
||||
options.AuthenticationType = OpenIdConnectAuthenticationDefaults.AuthenticationType;
|
||||
});
|
||||
|
||||
app.UseOpenIdConnectAuthentication(options =>
|
||||
|
|
@ -31,8 +31,6 @@ namespace OpenIdConnectSample
|
|||
options.ClientId = "fe78e0b4-6fe7-47e6-812c-fb75cee266a4";
|
||||
options.Authority = "https://login.windows.net/cyrano.onmicrosoft.com";
|
||||
options.RedirectUri = "http://localhost:42023";
|
||||
options.SignInAsAuthenticationType = OpenIdConnectAuthenticationDefaults.AuthenticationType;
|
||||
options.AuthenticationType = OpenIdConnectAuthenticationDefaults.AuthenticationType;
|
||||
});
|
||||
|
||||
app.Run(async context =>
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.IdentityModel.Tokens;
|
||||
using System.Linq;
|
||||
using System.Runtime.ExceptionServices;
|
||||
using System.Security.Claims;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Http;
|
||||
|
|
@ -38,7 +37,6 @@ namespace Microsoft.AspNet.Security.OAuthBearer
|
|||
/// <returns></returns>
|
||||
protected override async Task<AuthenticationTicket> AuthenticateCoreAsync()
|
||||
{
|
||||
ExceptionDispatchInfo authFailedEx = null;
|
||||
string token = null;
|
||||
try
|
||||
{
|
||||
|
|
@ -144,16 +142,10 @@ namespace Microsoft.AspNet.Security.OAuthBearer
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// We can't await inside a catch block, capture and handle outside.
|
||||
authFailedEx = ExceptionDispatchInfo.Capture(ex);
|
||||
}
|
||||
|
||||
if (authFailedEx != null)
|
||||
{
|
||||
_logger.WriteError("Exception occurred while processing message", authFailedEx.SourceException);
|
||||
_logger.WriteError("Exception occurred while processing message", ex);
|
||||
|
||||
// Refresh the configuration for exceptions that may be caused by key rollovers. The user can also request a refresh in the notification.
|
||||
if (Options.RefreshOnIssuerKeyNotFound && authFailedEx.SourceException.GetType().Equals(typeof(SecurityTokenSignatureKeyNotFoundException)))
|
||||
if (Options.RefreshOnIssuerKeyNotFound && ex.GetType().Equals(typeof(SecurityTokenSignatureKeyNotFoundException)))
|
||||
{
|
||||
Options.ConfigurationManager.RequestRefresh();
|
||||
}
|
||||
|
|
@ -162,7 +154,7 @@ namespace Microsoft.AspNet.Security.OAuthBearer
|
|||
new AuthenticationFailedNotification<HttpContext, OAuthBearerAuthenticationOptions>(Context, Options)
|
||||
{
|
||||
ProtocolMessage = Context,
|
||||
Exception = authFailedEx.SourceException
|
||||
Exception = ex
|
||||
};
|
||||
|
||||
await Options.Notifications.AuthenticationFailed(authenticationFailedNotification);
|
||||
|
|
@ -176,10 +168,8 @@ namespace Microsoft.AspNet.Security.OAuthBearer
|
|||
return null;
|
||||
}
|
||||
|
||||
authFailedEx.Throw();
|
||||
throw;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected override void ApplyResponseChallenge()
|
||||
|
|
@ -189,6 +179,11 @@ namespace Microsoft.AspNet.Security.OAuthBearer
|
|||
|
||||
protected override async Task ApplyResponseChallengeAsync()
|
||||
{
|
||||
if ((Response.StatusCode != 401) || (ChallengeContext == null))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
await Options.Notifications.ApplyChallenge(new AuthenticationChallengeNotification<OAuthBearerAuthenticationOptions>(Context, Options));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
|
||||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
namespace Microsoft.AspNet.Security.OpenIdConnect
|
||||
{
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
|
||||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.Security.OpenIdConnect;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
|
||||
|
||||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
namespace Microsoft.AspNet.Security.OpenIdConnect
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
|
||||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using Microsoft.AspNet.Security.OpenIdConnect;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
|
||||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
|
||||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
|
||||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
|
||||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.IdentityModel.Tokens;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.ExceptionServices;
|
||||
using System.Security.Claims;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Http;
|
||||
|
|
@ -122,7 +122,7 @@ namespace Microsoft.AspNet.Security.OpenIdConnect
|
|||
}
|
||||
|
||||
// order for redirect_uri
|
||||
// 1. challenge.Properties.RedirectUri
|
||||
// 1. challenge.Properties.RedirectUri
|
||||
// 2. CurrentUri
|
||||
AuthenticationProperties properties = new AuthenticationProperties(ChallengeContext.Properties);
|
||||
if (string.IsNullOrEmpty(properties.RedirectUri))
|
||||
|
|
@ -224,7 +224,6 @@ namespace Microsoft.AspNet.Security.OpenIdConnect
|
|||
return null;
|
||||
}
|
||||
|
||||
ExceptionDispatchInfo authFailedEx = null;
|
||||
try
|
||||
{
|
||||
var messageReceivedNotification = new MessageReceivedNotification<OpenIdConnectMessage, OpenIdConnectAuthenticationOptions>(Context, Options)
|
||||
|
|
@ -410,16 +409,10 @@ namespace Microsoft.AspNet.Security.OpenIdConnect
|
|||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
// We can't await inside a catch block, capture and handle outside.
|
||||
authFailedEx = ExceptionDispatchInfo.Capture(exception);
|
||||
}
|
||||
|
||||
if (authFailedEx != null)
|
||||
{
|
||||
_logger.WriteError("Exception occurred while processing message", authFailedEx.SourceException);
|
||||
_logger.WriteError("Exception occurred while processing message", exception);
|
||||
|
||||
// Refresh the configuration for exceptions that may be caused by key rollovers. The user can also request a refresh in the notification.
|
||||
if (Options.RefreshOnIssuerKeyNotFound && authFailedEx.SourceException.GetType().Equals(typeof(SecurityTokenSignatureKeyNotFoundException)))
|
||||
if (Options.RefreshOnIssuerKeyNotFound && exception.GetType().Equals(typeof(SecurityTokenSignatureKeyNotFoundException)))
|
||||
{
|
||||
Options.ConfigurationManager.RequestRefresh();
|
||||
}
|
||||
|
|
@ -427,7 +420,7 @@ namespace Microsoft.AspNet.Security.OpenIdConnect
|
|||
var authenticationFailedNotification = new AuthenticationFailedNotification<OpenIdConnectMessage, OpenIdConnectAuthenticationOptions>(Context, Options)
|
||||
{
|
||||
ProtocolMessage = openIdConnectMessage,
|
||||
Exception = authFailedEx.SourceException
|
||||
Exception = exception
|
||||
};
|
||||
|
||||
await Options.Notifications.AuthenticationFailed(authenticationFailedNotification);
|
||||
|
|
@ -441,10 +434,8 @@ namespace Microsoft.AspNet.Security.OpenIdConnect
|
|||
return null;
|
||||
}
|
||||
|
||||
authFailedEx.Throw();
|
||||
throw;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
|
||||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
|
||||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
Loading…
Reference in New Issue