Remove authentication from names, async events
This commit is contained in:
parent
0f06b6a09a
commit
e8090a3176
|
|
@ -41,7 +41,7 @@ namespace OpenIdConnectSample
|
|||
{
|
||||
if (!context.User.Identities.Any(identity => identity.IsAuthenticated))
|
||||
{
|
||||
await context.Authentication.ChallengeAsync(OpenIdConnectAuthenticationDefaults.AuthenticationScheme, new AuthenticationProperties { RedirectUri = "/" });
|
||||
await context.Authentication.ChallengeAsync(OpenIdConnectDefaults.AuthenticationScheme, new AuthenticationProperties { RedirectUri = "/" });
|
||||
|
||||
context.Response.ContentType = "text/plain";
|
||||
await context.Response.WriteAsync("Hello First timer");
|
||||
|
|
|
|||
|
|
@ -52,21 +52,17 @@ namespace CookieSample
|
|||
options.AppSecret = "a124463c4719c94b4228d9a240e5dc1a";
|
||||
});
|
||||
|
||||
var googleOptions = new OAuthAuthenticationOptions
|
||||
app.UseOAuthAuthentication(new OAuthOptions
|
||||
{
|
||||
AuthenticationScheme = "Google-AccessToken",
|
||||
Caption = "Google-AccessToken",
|
||||
ClientId = "560027070069-37ldt4kfuohhu3m495hk2j4pjp92d382.apps.googleusercontent.com",
|
||||
ClientSecret = "n2Q-GEw9RQjzcRbU3qhfTj8f",
|
||||
CallbackPath = new PathString("/signin-google-token"),
|
||||
AuthorizationEndpoint = GoogleAuthenticationDefaults.AuthorizationEndpoint,
|
||||
TokenEndpoint = GoogleAuthenticationDefaults.TokenEndpoint
|
||||
};
|
||||
googleOptions.Scope.Add("openid");
|
||||
googleOptions.Scope.Add("profile");
|
||||
googleOptions.Scope.Add("email");
|
||||
|
||||
app.UseOAuthAuthentication(googleOptions);
|
||||
AuthorizationEndpoint = GoogleDefaults.AuthorizationEndpoint,
|
||||
TokenEndpoint = GoogleDefaults.TokenEndpoint,
|
||||
Scope = { "openid", "profile", "email" }
|
||||
});
|
||||
|
||||
// https://console.developers.google.com/project
|
||||
app.UseGoogleAuthentication(options =>
|
||||
|
|
@ -99,18 +95,17 @@ namespace CookieSample
|
|||
The sample app can then be run via:
|
||||
dnx . web
|
||||
*/
|
||||
var msOAuthOptions = new OAuthAuthenticationOptions
|
||||
app.UseOAuthAuthentication(new OAuthOptions
|
||||
{
|
||||
AuthenticationScheme = "Microsoft-AccessToken",
|
||||
Caption = "MicrosoftAccount-AccessToken - Requires project changes",
|
||||
ClientId = "00000000480FF62E",
|
||||
ClientSecret = "bLw2JIvf8Y1TaToipPEqxTVlOeJwCUsr",
|
||||
CallbackPath = new PathString("/signin-microsoft-token"),
|
||||
AuthorizationEndpoint = MicrosoftAccountAuthenticationDefaults.AuthorizationEndpoint,
|
||||
TokenEndpoint = MicrosoftAccountAuthenticationDefaults.TokenEndpoint
|
||||
};
|
||||
msOAuthOptions.Scope.Add("wl.basic");
|
||||
app.UseOAuthAuthentication(msOAuthOptions);
|
||||
AuthorizationEndpoint = MicrosoftAccountDefaults.AuthorizationEndpoint,
|
||||
TokenEndpoint = MicrosoftAccountDefaults.TokenEndpoint,
|
||||
Scope = { "wl.basic" }
|
||||
});
|
||||
|
||||
app.UseMicrosoftAccountAuthentication(options =>
|
||||
{
|
||||
|
|
@ -121,7 +116,7 @@ namespace CookieSample
|
|||
});
|
||||
|
||||
// https://github.com/settings/applications/
|
||||
app.UseOAuthAuthentication(new OAuthAuthenticationOptions
|
||||
app.UseOAuthAuthentication(new OAuthOptions
|
||||
{
|
||||
AuthenticationScheme = "GitHub-AccessToken",
|
||||
Caption = "Github-AccessToken",
|
||||
|
|
@ -132,7 +127,7 @@ namespace CookieSample
|
|||
TokenEndpoint = "https://github.com/login/oauth/access_token"
|
||||
});
|
||||
|
||||
app.UseOAuthAuthentication(new OAuthAuthenticationOptions
|
||||
app.UseOAuthAuthentication(new OAuthOptions
|
||||
{
|
||||
AuthenticationScheme = "GitHub",
|
||||
Caption = "Github",
|
||||
|
|
@ -145,7 +140,7 @@ namespace CookieSample
|
|||
ClaimsIssuer = "OAuth2-Github",
|
||||
SaveTokensAsClaims = false,
|
||||
// Retrieving user information is unique to each provider.
|
||||
Events = new OAuthAuthenticationEvents
|
||||
Events = new OAuthEvents
|
||||
{
|
||||
OnAuthenticated = async context =>
|
||||
{
|
||||
|
|
|
|||
|
|
@ -38,6 +38,5 @@ namespace Microsoft.AspNet.Builder
|
|||
return app.UseMiddleware<CookieAuthenticationMiddleware>(options,
|
||||
new ConfigureOptions<CookieAuthenticationOptions>(o => { }));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -132,7 +132,7 @@ namespace Microsoft.AspNet.Authentication.Cookies
|
|||
{
|
||||
var exceptionContext = new CookieExceptionContext(Context, Options,
|
||||
CookieExceptionContext.ExceptionLocation.Authenticate, exception, ticket);
|
||||
Options.Events.Exception(exceptionContext);
|
||||
await Options.Events.Exception(exceptionContext);
|
||||
if (exceptionContext.Rethrow)
|
||||
{
|
||||
throw;
|
||||
|
|
@ -210,7 +210,7 @@ namespace Microsoft.AspNet.Authentication.Cookies
|
|||
{
|
||||
var exceptionContext = new CookieExceptionContext(Context, Options,
|
||||
CookieExceptionContext.ExceptionLocation.FinishResponse, exception, ticket);
|
||||
Options.Events.Exception(exceptionContext);
|
||||
await Options.Events.Exception(exceptionContext);
|
||||
if (exceptionContext.Rethrow)
|
||||
{
|
||||
throw;
|
||||
|
|
@ -249,7 +249,7 @@ namespace Microsoft.AspNet.Authentication.Cookies
|
|||
signInContext.Properties.ExpiresUtc = issuedUtc.Add(Options.ExpireTimeSpan);
|
||||
}
|
||||
|
||||
Options.Events.ResponseSignIn(signInContext);
|
||||
await Options.Events.ResponseSignIn(signInContext);
|
||||
|
||||
if (signInContext.Properties.IsPersistent)
|
||||
{
|
||||
|
|
@ -286,7 +286,7 @@ namespace Microsoft.AspNet.Authentication.Cookies
|
|||
signInContext.Principal,
|
||||
signInContext.Properties);
|
||||
|
||||
Options.Events.ResponseSignedIn(signedInContext);
|
||||
await Options.Events.ResponseSignedIn(signedInContext);
|
||||
|
||||
var shouldLoginRedirect = Options.LoginPath.HasValue && OriginalPath == Options.LoginPath;
|
||||
ApplyHeaders(shouldLoginRedirect);
|
||||
|
|
@ -295,7 +295,7 @@ namespace Microsoft.AspNet.Authentication.Cookies
|
|||
{
|
||||
var exceptionContext = new CookieExceptionContext(Context, Options,
|
||||
CookieExceptionContext.ExceptionLocation.SignIn, exception, ticket);
|
||||
Options.Events.Exception(exceptionContext);
|
||||
await Options.Events.Exception(exceptionContext);
|
||||
if (exceptionContext.Rethrow)
|
||||
{
|
||||
throw;
|
||||
|
|
@ -319,7 +319,7 @@ namespace Microsoft.AspNet.Authentication.Cookies
|
|||
Options,
|
||||
cookieOptions);
|
||||
|
||||
Options.Events.ResponseSignOut(context);
|
||||
await Options.Events.ResponseSignOut(context);
|
||||
|
||||
Options.CookieManager.DeleteCookie(
|
||||
Context,
|
||||
|
|
@ -333,7 +333,7 @@ namespace Microsoft.AspNet.Authentication.Cookies
|
|||
{
|
||||
var exceptionContext = new CookieExceptionContext(Context, Options,
|
||||
CookieExceptionContext.ExceptionLocation.SignOut, exception, ticket);
|
||||
Options.Events.Exception(exceptionContext);
|
||||
await Options.Events.Exception(exceptionContext);
|
||||
if (exceptionContext.Rethrow)
|
||||
{
|
||||
throw;
|
||||
|
|
@ -373,7 +373,7 @@ namespace Microsoft.AspNet.Authentication.Cookies
|
|||
return path[0] == '/' && path[1] != '/' && path[1] != '\\';
|
||||
}
|
||||
|
||||
protected override Task<bool> HandleForbiddenAsync(ChallengeContext context)
|
||||
protected async override Task<bool> HandleForbiddenAsync(ChallengeContext context)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
|
@ -385,22 +385,22 @@ namespace Microsoft.AspNet.Authentication.Cookies
|
|||
Options.AccessDeniedPath;
|
||||
|
||||
var redirectContext = new CookieApplyRedirectContext(Context, Options, accessDeniedUri);
|
||||
Options.Events.ApplyRedirect(redirectContext);
|
||||
await Options.Events.ApplyRedirect(redirectContext);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
var exceptionContext = new CookieExceptionContext(Context, Options,
|
||||
CookieExceptionContext.ExceptionLocation.Forbidden, exception, ticket: null);
|
||||
Options.Events.Exception(exceptionContext);
|
||||
await Options.Events.Exception(exceptionContext);
|
||||
if (exceptionContext.Rethrow)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
return Task.FromResult(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override Task<bool> HandleUnauthorizedAsync([NotNull] ChallengeContext context)
|
||||
protected override async Task<bool> HandleUnauthorizedAsync([NotNull] ChallengeContext context)
|
||||
{
|
||||
var redirectUri = new AuthenticationProperties(context.Properties).RedirectUri;
|
||||
try
|
||||
|
|
@ -412,19 +412,19 @@ namespace Microsoft.AspNet.Authentication.Cookies
|
|||
|
||||
var loginUri = Options.LoginPath + QueryString.Create(Options.ReturnUrlParameter, redirectUri);
|
||||
var redirectContext = new CookieApplyRedirectContext(Context, Options, BuildRedirectUri(loginUri));
|
||||
Options.Events.ApplyRedirect(redirectContext);
|
||||
await Options.Events.ApplyRedirect(redirectContext);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
var exceptionContext = new CookieExceptionContext(Context, Options,
|
||||
CookieExceptionContext.ExceptionLocation.Unauthorized, exception, ticket: null);
|
||||
Options.Events.Exception(exceptionContext);
|
||||
await Options.Events.Exception(exceptionContext);
|
||||
if (exceptionContext.Rethrow)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
return Task.FromResult(true);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,27 +21,31 @@ namespace Microsoft.AspNet.Authentication.Cookies
|
|||
/// <summary>
|
||||
/// A delegate assigned to this property will be invoked when the related method is called
|
||||
/// </summary>
|
||||
public Action<CookieResponseSignInContext> OnResponseSignIn { get; set; } = context => { };
|
||||
public Func<CookieResponseSignInContext, Task> OnResponseSignIn { get; set; } = context => Task.FromResult(0);
|
||||
|
||||
/// <summary>
|
||||
/// A delegate assigned to this property will be invoked when the related method is called
|
||||
/// </summary>
|
||||
public Action<CookieResponseSignedInContext> OnResponseSignedIn { get; set; } = context => { };
|
||||
public Func<CookieResponseSignedInContext, Task> OnResponseSignedIn { get; set; } = context => Task.FromResult(0);
|
||||
|
||||
/// <summary>
|
||||
/// A delegate assigned to this property will be invoked when the related method is called
|
||||
/// </summary>
|
||||
public Action<CookieResponseSignOutContext> OnResponseSignOut { get; set; } = context => { };
|
||||
public Func<CookieResponseSignOutContext, Task> OnResponseSignOut { get; set; } = context => Task.FromResult(0);
|
||||
|
||||
/// <summary>
|
||||
/// A delegate assigned to this property will be invoked when the related method is called
|
||||
/// </summary>
|
||||
public Action<CookieApplyRedirectContext> OnApplyRedirect { get; set; } = context => context.Response.Redirect(context.RedirectUri);
|
||||
public Func<CookieApplyRedirectContext, Task> OnApplyRedirect { get; set; } = context =>
|
||||
{
|
||||
context.Response.Redirect(context.RedirectUri);
|
||||
return Task.FromResult(0);
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// A delegate assigned to this property will be invoked when the related method is called
|
||||
/// </summary>
|
||||
public Action<CookieExceptionContext> OnException { get; set; } = context => { };
|
||||
public Func<CookieExceptionContext, Task> OnException { get; set; } = context => Task.FromResult(0);
|
||||
|
||||
/// <summary>
|
||||
/// Implements the interface method by invoking the related delegate method
|
||||
|
|
@ -54,30 +58,30 @@ namespace Microsoft.AspNet.Authentication.Cookies
|
|||
/// Implements the interface method by invoking the related delegate method
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
public virtual void ResponseSignIn(CookieResponseSignInContext context) => OnResponseSignIn(context);
|
||||
public virtual Task ResponseSignIn(CookieResponseSignInContext context) => OnResponseSignIn(context);
|
||||
|
||||
/// <summary>
|
||||
/// Implements the interface method by invoking the related delegate method
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
public virtual void ResponseSignedIn(CookieResponseSignedInContext context) => OnResponseSignedIn(context);
|
||||
public virtual Task ResponseSignedIn(CookieResponseSignedInContext context) => OnResponseSignedIn(context);
|
||||
|
||||
/// <summary>
|
||||
/// Implements the interface method by invoking the related delegate method
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
public virtual void ResponseSignOut(CookieResponseSignOutContext context) => OnResponseSignOut(context);
|
||||
public virtual Task ResponseSignOut(CookieResponseSignOutContext context) => OnResponseSignOut(context);
|
||||
|
||||
/// <summary>
|
||||
/// Implements the interface method by invoking the related delegate method
|
||||
/// </summary>
|
||||
/// <param name="context">Contains information about the event</param>
|
||||
public virtual void ApplyRedirect(CookieApplyRedirectContext context) => OnApplyRedirect(context);
|
||||
public virtual Task ApplyRedirect(CookieApplyRedirectContext context) => OnApplyRedirect(context);
|
||||
|
||||
/// <summary>
|
||||
/// Implements the interface method by invoking the related delegate method
|
||||
/// </summary>
|
||||
/// <param name="context">Contains information about the event</param>
|
||||
public virtual void Exception(CookieExceptionContext context) => OnException(context);
|
||||
public virtual Task Exception(CookieExceptionContext context) => OnException(context);
|
||||
}
|
||||
}
|
||||
|
|
@ -23,30 +23,30 @@ namespace Microsoft.AspNet.Authentication.Cookies
|
|||
/// implementing this method the claims and extra information that go into the ticket may be altered.
|
||||
/// </summary>
|
||||
/// <param name="context">Contains information about the login session as well as the user <see cref="System.Security.Claims.ClaimsIdentity"/>.</param>
|
||||
void ResponseSignIn(CookieResponseSignInContext context);
|
||||
Task ResponseSignIn(CookieResponseSignInContext context);
|
||||
|
||||
/// <summary>
|
||||
/// Called when an endpoint has provided sign in information after it is converted into a cookie.
|
||||
/// </summary>
|
||||
/// <param name="context">Contains information about the login session as well as the user <see cref="System.Security.Claims.ClaimsIdentity"/>.</param>
|
||||
void ResponseSignedIn(CookieResponseSignedInContext context);
|
||||
Task ResponseSignedIn(CookieResponseSignedInContext context);
|
||||
|
||||
/// <summary>
|
||||
/// Called when a Challenge, SignIn, or SignOut causes a redirect in the cookie middleware
|
||||
/// </summary>
|
||||
/// <param name="context">Contains information about the event</param>
|
||||
void ApplyRedirect(CookieApplyRedirectContext context);
|
||||
Task ApplyRedirect(CookieApplyRedirectContext context);
|
||||
|
||||
/// <summary>
|
||||
/// Called during the sign-out flow to augment the cookie cleanup process.
|
||||
/// </summary>
|
||||
/// <param name="context">Contains information about the login session as well as information about the authentication cookie.</param>
|
||||
void ResponseSignOut(CookieResponseSignOutContext context);
|
||||
Task ResponseSignOut(CookieResponseSignOutContext context);
|
||||
|
||||
/// <summary>
|
||||
/// Called when an exception occurs during request or response processing.
|
||||
/// </summary>
|
||||
/// <param name="context">Contains information about the exception that occurred</param>
|
||||
void Exception(CookieExceptionContext context);
|
||||
Task Exception(CookieExceptionContext context);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ using Microsoft.Framework.OptionsModel;
|
|||
namespace Microsoft.AspNet.Builder
|
||||
{
|
||||
/// <summary>
|
||||
/// Extension methods for using <see cref="FacebookAuthenticationMiddleware"/>.
|
||||
/// Extension methods for using <see cref="FacebookMiddleware"/>.
|
||||
/// </summary>
|
||||
public static class FacebookAppBuilderExtensions
|
||||
{
|
||||
|
|
@ -18,10 +18,10 @@ namespace Microsoft.AspNet.Builder
|
|||
/// </summary>
|
||||
/// <param name="app">The <see cref="IApplicationBuilder"/> passed to the configure method.</param>
|
||||
/// <returns>The updated <see cref="IApplicationBuilder"/>.</returns>
|
||||
public static IApplicationBuilder UseFacebookAuthentication([NotNull] this IApplicationBuilder app, Action<FacebookAuthenticationOptions> configureOptions = null)
|
||||
public static IApplicationBuilder UseFacebookAuthentication([NotNull] this IApplicationBuilder app, Action<FacebookOptions> configureOptions = null)
|
||||
{
|
||||
return app.UseMiddleware<FacebookAuthenticationMiddleware>(
|
||||
new ConfigureOptions<FacebookAuthenticationOptions>(configureOptions ?? (o => { })));
|
||||
return app.UseMiddleware<FacebookMiddleware>(
|
||||
new ConfigureOptions<FacebookOptions>(configureOptions ?? (o => { })));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
namespace Microsoft.AspNet.Authentication.Facebook
|
||||
{
|
||||
public static class FacebookAuthenticationDefaults
|
||||
public static class FacebookDefaults
|
||||
{
|
||||
public const string AuthenticationScheme = "Facebook";
|
||||
|
||||
|
|
@ -17,9 +17,9 @@ using Newtonsoft.Json.Linq;
|
|||
|
||||
namespace Microsoft.AspNet.Authentication.Facebook
|
||||
{
|
||||
internal class FacebookAuthenticationHandler : OAuthAuthenticationHandler<FacebookAuthenticationOptions>
|
||||
internal class FacebookHandler : OAuthHandler<FacebookOptions>
|
||||
{
|
||||
public FacebookAuthenticationHandler(HttpClient httpClient)
|
||||
public FacebookHandler(HttpClient httpClient)
|
||||
: base(httpClient)
|
||||
{
|
||||
}
|
||||
|
|
@ -68,25 +68,25 @@ namespace Microsoft.AspNet.Authentication.Facebook
|
|||
Principal = new ClaimsPrincipal(identity)
|
||||
};
|
||||
|
||||
var identifier = FacebookAuthenticationHelper.GetId(payload);
|
||||
var identifier = FacebookHelper.GetId(payload);
|
||||
if (!string.IsNullOrEmpty(identifier))
|
||||
{
|
||||
identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, identifier, ClaimValueTypes.String, Options.ClaimsIssuer));
|
||||
}
|
||||
|
||||
var userName = FacebookAuthenticationHelper.GetUserName(payload);
|
||||
var userName = FacebookHelper.GetUserName(payload);
|
||||
if (!string.IsNullOrEmpty(userName))
|
||||
{
|
||||
identity.AddClaim(new Claim(ClaimsIdentity.DefaultNameClaimType, userName, ClaimValueTypes.String, Options.ClaimsIssuer));
|
||||
}
|
||||
|
||||
var email = FacebookAuthenticationHelper.GetEmail(payload);
|
||||
var email = FacebookHelper.GetEmail(payload);
|
||||
if (!string.IsNullOrEmpty(email))
|
||||
{
|
||||
identity.AddClaim(new Claim(ClaimTypes.Email, email, ClaimValueTypes.String, Options.ClaimsIssuer));
|
||||
}
|
||||
|
||||
var name = FacebookAuthenticationHelper.GetName(payload);
|
||||
var name = FacebookHelper.GetName(payload);
|
||||
if (!string.IsNullOrEmpty(name))
|
||||
{
|
||||
identity.AddClaim(new Claim("urn:facebook:name", name, ClaimValueTypes.String, Options.ClaimsIssuer));
|
||||
|
|
@ -98,7 +98,7 @@ namespace Microsoft.AspNet.Authentication.Facebook
|
|||
}
|
||||
}
|
||||
|
||||
var link = FacebookAuthenticationHelper.GetLink(payload);
|
||||
var link = FacebookHelper.GetLink(payload);
|
||||
if (!string.IsNullOrEmpty(link))
|
||||
{
|
||||
identity.AddClaim(new Claim("urn:facebook:link", link, ClaimValueTypes.String, Options.ClaimsIssuer));
|
||||
|
|
@ -10,7 +10,7 @@ namespace Microsoft.AspNet.Authentication.Facebook
|
|||
/// Contains static methods that allow to extract user's information from a <see cref="JObject"/>
|
||||
/// instance retrieved from Facebook after a successful authentication process.
|
||||
/// </summary>
|
||||
public static class FacebookAuthenticationHelper
|
||||
public static class FacebookHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the Facebook user ID.
|
||||
|
|
@ -16,10 +16,10 @@ namespace Microsoft.AspNet.Authentication.Facebook
|
|||
/// <summary>
|
||||
/// An ASP.NET middleware for authenticating users using Facebook.
|
||||
/// </summary>
|
||||
public class FacebookAuthenticationMiddleware : OAuthAuthenticationMiddleware<FacebookAuthenticationOptions>
|
||||
public class FacebookMiddleware : OAuthMiddleware<FacebookOptions>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new <see cref="FacebookAuthenticationMiddleware"/>.
|
||||
/// Initializes a new <see cref="FacebookMiddleware"/>.
|
||||
/// </summary>
|
||||
/// <param name="next">The next middleware in the HTTP pipeline to invoke.</param>
|
||||
/// <param name="dataProtectionProvider"></param>
|
||||
|
|
@ -28,14 +28,14 @@ namespace Microsoft.AspNet.Authentication.Facebook
|
|||
/// <param name="sharedOptions"></param>
|
||||
/// <param name="options">Configuration options for the middleware.</param>
|
||||
/// <param name="configureOptions"></param>
|
||||
public FacebookAuthenticationMiddleware(
|
||||
public FacebookMiddleware(
|
||||
[NotNull] RequestDelegate next,
|
||||
[NotNull] IDataProtectionProvider dataProtectionProvider,
|
||||
[NotNull] ILoggerFactory loggerFactory,
|
||||
[NotNull] IUrlEncoder encoder,
|
||||
[NotNull] IOptions<SharedAuthenticationOptions> sharedOptions,
|
||||
[NotNull] IOptions<FacebookAuthenticationOptions> options,
|
||||
ConfigureOptions<FacebookAuthenticationOptions> configureOptions = null)
|
||||
[NotNull] IOptions<FacebookOptions> options,
|
||||
ConfigureOptions<FacebookOptions> configureOptions = null)
|
||||
: base(next, dataProtectionProvider, loggerFactory, encoder, sharedOptions, options, configureOptions)
|
||||
{
|
||||
if (string.IsNullOrEmpty(Options.AppId))
|
||||
|
|
@ -51,10 +51,10 @@ namespace Microsoft.AspNet.Authentication.Facebook
|
|||
/// <summary>
|
||||
/// Provides the <see cref="AuthenticationHandler"/> object for processing authentication-related requests.
|
||||
/// </summary>
|
||||
/// <returns>An <see cref="AuthenticationHandler"/> configured with the <see cref="FacebookAuthenticationOptions"/> supplied to the constructor.</returns>
|
||||
protected override AuthenticationHandler<FacebookAuthenticationOptions> CreateHandler()
|
||||
/// <returns>An <see cref="AuthenticationHandler"/> configured with the <see cref="FacebookOptions"/> supplied to the constructor.</returns>
|
||||
protected override AuthenticationHandler<FacebookOptions> CreateHandler()
|
||||
{
|
||||
return new FacebookAuthenticationHandler(Backchannel);
|
||||
return new FacebookHandler(Backchannel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,29 +1,28 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System.Security.Claims;
|
||||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.Authentication.OAuth;
|
||||
|
||||
namespace Microsoft.AspNet.Authentication.Facebook
|
||||
{
|
||||
/// <summary>
|
||||
/// Configuration options for <see cref="FacebookAuthenticationMiddleware"/>.
|
||||
/// Configuration options for <see cref="FacebookMiddleware"/>.
|
||||
/// </summary>
|
||||
public class FacebookAuthenticationOptions : OAuthAuthenticationOptions
|
||||
public class FacebookOptions : OAuthOptions
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new <see cref="FacebookAuthenticationOptions"/>.
|
||||
/// Initializes a new <see cref="FacebookOptions"/>.
|
||||
/// </summary>
|
||||
public FacebookAuthenticationOptions()
|
||||
public FacebookOptions()
|
||||
{
|
||||
AuthenticationScheme = FacebookAuthenticationDefaults.AuthenticationScheme;
|
||||
AuthenticationScheme = FacebookDefaults.AuthenticationScheme;
|
||||
Caption = AuthenticationScheme;
|
||||
CallbackPath = new PathString("/signin-facebook");
|
||||
SendAppSecretProof = true;
|
||||
AuthorizationEndpoint = FacebookAuthenticationDefaults.AuthorizationEndpoint;
|
||||
TokenEndpoint = FacebookAuthenticationDefaults.TokenEndpoint;
|
||||
UserInformationEndpoint = FacebookAuthenticationDefaults.UserInformationEndpoint;
|
||||
AuthorizationEndpoint = FacebookDefaults.AuthorizationEndpoint;
|
||||
TokenEndpoint = FacebookDefaults.TokenEndpoint;
|
||||
UserInformationEndpoint = FacebookDefaults.UserInformationEndpoint;
|
||||
SaveTokensAsClaims = false;
|
||||
}
|
||||
|
||||
|
|
@ -9,18 +9,18 @@ using Microsoft.Framework.Internal;
|
|||
namespace Microsoft.Framework.DependencyInjection
|
||||
{
|
||||
/// <summary>
|
||||
/// Extension methods for using <see cref="FacebookAuthenticationMiddleware"/>.
|
||||
/// Extension methods for using <see cref="FacebookMiddleware"/>.
|
||||
/// </summary>
|
||||
public static class FacebookServiceCollectionExtensions
|
||||
{
|
||||
public static IServiceCollection AddFacebookAuthentication([NotNull] this IServiceCollection services, [NotNull] Action<FacebookAuthenticationOptions> configure)
|
||||
public static IServiceCollection AddFacebookAuthentication([NotNull] this IServiceCollection services, [NotNull] Action<FacebookOptions> configure)
|
||||
{
|
||||
return services.Configure(configure);
|
||||
}
|
||||
|
||||
public static IServiceCollection AddFacebookAuthentication([NotNull] this IServiceCollection services, [NotNull] IConfiguration config)
|
||||
{
|
||||
return services.Configure<FacebookAuthenticationOptions>(config);
|
||||
return services.Configure<FacebookOptions>(config);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -9,7 +9,7 @@ using Microsoft.Framework.OptionsModel;
|
|||
namespace Microsoft.AspNet.Builder
|
||||
{
|
||||
/// <summary>
|
||||
/// Extension methods for using <see cref="GoogleAuthenticationMiddleware"/>.
|
||||
/// Extension methods for using <see cref="GoogleMiddleware"/>.
|
||||
/// </summary>
|
||||
public static class GoogleAppBuilderExtensions
|
||||
{
|
||||
|
|
@ -20,10 +20,10 @@ namespace Microsoft.AspNet.Builder
|
|||
/// <param name="configureOptions">Used to configure Middleware options.</param>
|
||||
/// <param name="optionsName">Name of the options instance to be used</param>
|
||||
/// <returns>The updated <see cref="IApplicationBuilder"/>.</returns>
|
||||
public static IApplicationBuilder UseGoogleAuthentication([NotNull] this IApplicationBuilder app, Action<GoogleAuthenticationOptions> configureOptions = null, string optionsName = "")
|
||||
public static IApplicationBuilder UseGoogleAuthentication([NotNull] this IApplicationBuilder app, Action<GoogleOptions> configureOptions = null, string optionsName = "")
|
||||
{
|
||||
return app.UseMiddleware<GoogleAuthenticationMiddleware>(
|
||||
new ConfigureOptions<GoogleAuthenticationOptions>(configureOptions ?? (o => { })));
|
||||
return app.UseMiddleware<GoogleMiddleware>(
|
||||
new ConfigureOptions<GoogleOptions>(configureOptions ?? (o => { })));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
namespace Microsoft.AspNet.Authentication.Google
|
||||
{
|
||||
public static class GoogleAuthenticationDefaults
|
||||
public static class GoogleDefaults
|
||||
{
|
||||
public const string AuthenticationScheme = "Google";
|
||||
|
||||
|
|
@ -14,9 +14,9 @@ using Newtonsoft.Json.Linq;
|
|||
|
||||
namespace Microsoft.AspNet.Authentication.Google
|
||||
{
|
||||
internal class GoogleAuthenticationHandler : OAuthAuthenticationHandler<GoogleAuthenticationOptions>
|
||||
internal class GoogleHandler : OAuthHandler<GoogleOptions>
|
||||
{
|
||||
public GoogleAuthenticationHandler(HttpClient httpClient)
|
||||
public GoogleHandler(HttpClient httpClient)
|
||||
: base(httpClient)
|
||||
{
|
||||
}
|
||||
|
|
@ -38,37 +38,37 @@ namespace Microsoft.AspNet.Authentication.Google
|
|||
Principal = new ClaimsPrincipal(identity)
|
||||
};
|
||||
|
||||
var identifier = GoogleAuthenticationHelper.GetId(payload);
|
||||
var identifier = GoogleHelper.GetId(payload);
|
||||
if (!string.IsNullOrEmpty(identifier))
|
||||
{
|
||||
identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, identifier, ClaimValueTypes.String, Options.ClaimsIssuer));
|
||||
}
|
||||
|
||||
var givenName = GoogleAuthenticationHelper.GetGivenName(payload);
|
||||
var givenName = GoogleHelper.GetGivenName(payload);
|
||||
if (!string.IsNullOrEmpty(givenName))
|
||||
{
|
||||
identity.AddClaim(new Claim(ClaimTypes.GivenName, givenName, ClaimValueTypes.String, Options.ClaimsIssuer));
|
||||
}
|
||||
|
||||
var familyName = GoogleAuthenticationHelper.GetFamilyName(payload);
|
||||
var familyName = GoogleHelper.GetFamilyName(payload);
|
||||
if (!string.IsNullOrEmpty(familyName))
|
||||
{
|
||||
identity.AddClaim(new Claim(ClaimTypes.Surname, familyName, ClaimValueTypes.String, Options.ClaimsIssuer));
|
||||
}
|
||||
|
||||
var name = GoogleAuthenticationHelper.GetName(payload);
|
||||
var name = GoogleHelper.GetName(payload);
|
||||
if (!string.IsNullOrEmpty(name))
|
||||
{
|
||||
identity.AddClaim(new Claim(ClaimTypes.Name, name, ClaimValueTypes.String, Options.ClaimsIssuer));
|
||||
}
|
||||
|
||||
var email = GoogleAuthenticationHelper.GetEmail(payload);
|
||||
var email = GoogleHelper.GetEmail(payload);
|
||||
if (!string.IsNullOrEmpty(email))
|
||||
{
|
||||
identity.AddClaim(new Claim(ClaimTypes.Email, email, ClaimValueTypes.String, Options.ClaimsIssuer));
|
||||
}
|
||||
|
||||
var profile = GoogleAuthenticationHelper.GetProfile(payload);
|
||||
var profile = GoogleHelper.GetProfile(payload);
|
||||
if (!string.IsNullOrEmpty(profile))
|
||||
{
|
||||
identity.AddClaim(new Claim("urn:google:profile", profile, ClaimValueTypes.String, Options.ClaimsIssuer));
|
||||
|
|
@ -10,7 +10,7 @@ namespace Microsoft.AspNet.Authentication.Google
|
|||
/// Contains static methods that allow to extract user's information from a <see cref="JObject"/>
|
||||
/// instance retrieved from Google after a successful authentication process.
|
||||
/// </summary>
|
||||
public static class GoogleAuthenticationHelper
|
||||
public static class GoogleHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the Google user ID.
|
||||
|
|
@ -16,10 +16,10 @@ namespace Microsoft.AspNet.Authentication.Google
|
|||
/// An ASP.NET middleware for authenticating users using Google OAuth 2.0.
|
||||
/// </summary>
|
||||
[SuppressMessage("Microsoft.Design", "CA1001:TypesThatOwnDisposableFieldsShouldBeDisposable", Justification = "Middleware are not disposable.")]
|
||||
public class GoogleAuthenticationMiddleware : OAuthAuthenticationMiddleware<GoogleAuthenticationOptions>
|
||||
public class GoogleMiddleware : OAuthMiddleware<GoogleOptions>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new <see cref="GoogleAuthenticationMiddleware"/>.
|
||||
/// Initializes a new <see cref="GoogleMiddleware"/>.
|
||||
/// </summary>
|
||||
/// <param name="next">The next middleware in the HTTP pipeline to invoke.</param>
|
||||
/// <param name="dataProtectionProvider"></param>
|
||||
|
|
@ -28,14 +28,14 @@ namespace Microsoft.AspNet.Authentication.Google
|
|||
/// <param name="sharedOptions"></param>
|
||||
/// <param name="options">Configuration options for the middleware.</param>
|
||||
/// <param name="configureOptions"></param>
|
||||
public GoogleAuthenticationMiddleware(
|
||||
public GoogleMiddleware(
|
||||
[NotNull] RequestDelegate next,
|
||||
[NotNull] IDataProtectionProvider dataProtectionProvider,
|
||||
[NotNull] ILoggerFactory loggerFactory,
|
||||
[NotNull] IUrlEncoder encoder,
|
||||
[NotNull] IOptions<SharedAuthenticationOptions> sharedOptions,
|
||||
[NotNull] IOptions<GoogleAuthenticationOptions> options,
|
||||
ConfigureOptions<GoogleAuthenticationOptions> configureOptions = null)
|
||||
[NotNull] IOptions<GoogleOptions> options,
|
||||
ConfigureOptions<GoogleOptions> configureOptions = null)
|
||||
: base(next, dataProtectionProvider, loggerFactory, encoder, sharedOptions, options, configureOptions)
|
||||
{
|
||||
if (Options.Scope.Count == 0)
|
||||
|
|
@ -52,10 +52,10 @@ namespace Microsoft.AspNet.Authentication.Google
|
|||
/// <summary>
|
||||
/// Provides the <see cref="AuthenticationHandler"/> object for processing authentication-related requests.
|
||||
/// </summary>
|
||||
/// <returns>An <see cref="AuthenticationHandler"/> configured with the <see cref="GoogleAuthenticationOptions"/> supplied to the constructor.</returns>
|
||||
protected override AuthenticationHandler<GoogleAuthenticationOptions> CreateHandler()
|
||||
/// <returns>An <see cref="AuthenticationHandler"/> configured with the <see cref="GoogleOptions"/> supplied to the constructor.</returns>
|
||||
protected override AuthenticationHandler<GoogleOptions> CreateHandler()
|
||||
{
|
||||
return new GoogleAuthenticationHandler(Backchannel);
|
||||
return new GoogleHandler(Backchannel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -7,21 +7,21 @@ using Microsoft.AspNet.Http;
|
|||
namespace Microsoft.AspNet.Authentication.Google
|
||||
{
|
||||
/// <summary>
|
||||
/// Configuration options for <see cref="GoogleAuthenticationMiddleware"/>.
|
||||
/// Configuration options for <see cref="GoogleMiddleware"/>.
|
||||
/// </summary>
|
||||
public class GoogleAuthenticationOptions : OAuthAuthenticationOptions
|
||||
public class GoogleOptions : OAuthOptions
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new <see cref="GoogleAuthenticationOptions"/>.
|
||||
/// Initializes a new <see cref="GoogleOptions"/>.
|
||||
/// </summary>
|
||||
public GoogleAuthenticationOptions()
|
||||
public GoogleOptions()
|
||||
{
|
||||
AuthenticationScheme = GoogleAuthenticationDefaults.AuthenticationScheme;
|
||||
AuthenticationScheme = GoogleDefaults.AuthenticationScheme;
|
||||
Caption = AuthenticationScheme;
|
||||
CallbackPath = new PathString("/signin-google");
|
||||
AuthorizationEndpoint = GoogleAuthenticationDefaults.AuthorizationEndpoint;
|
||||
TokenEndpoint = GoogleAuthenticationDefaults.TokenEndpoint;
|
||||
UserInformationEndpoint = GoogleAuthenticationDefaults.UserInformationEndpoint;
|
||||
AuthorizationEndpoint = GoogleDefaults.AuthorizationEndpoint;
|
||||
TokenEndpoint = GoogleDefaults.TokenEndpoint;
|
||||
UserInformationEndpoint = GoogleDefaults.UserInformationEndpoint;
|
||||
SaveTokensAsClaims = false;
|
||||
}
|
||||
|
||||
|
|
@ -9,18 +9,18 @@ using Microsoft.Framework.Internal;
|
|||
namespace Microsoft.Framework.DependencyInjection
|
||||
{
|
||||
/// <summary>
|
||||
/// Extension methods for using <see cref="GoogleAuthenticationMiddleware"/>.
|
||||
/// Extension methods for using <see cref="GoogleMiddleware"/>.
|
||||
/// </summary>
|
||||
public static class GoogleServiceCollectionExtensions
|
||||
{
|
||||
public static IServiceCollection AddGoogleAuthentication([NotNull] this IServiceCollection services, [NotNull] Action<GoogleAuthenticationOptions> configure)
|
||||
public static IServiceCollection AddGoogleAuthentication([NotNull] this IServiceCollection services, [NotNull] Action<GoogleOptions> configure)
|
||||
{
|
||||
return services.Configure(configure);
|
||||
}
|
||||
|
||||
public static IServiceCollection AddGoogleAuthentication([NotNull] this IServiceCollection services, [NotNull] IConfiguration config)
|
||||
{
|
||||
return services.Configure<GoogleAuthenticationOptions>(config);
|
||||
return services.Configure<GoogleOptions>(config);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -5,9 +5,9 @@ using Microsoft.AspNet.Http;
|
|||
|
||||
namespace Microsoft.AspNet.Authentication.JwtBearer
|
||||
{
|
||||
public class AuthenticationChallengeContext : BaseControlContext<JwtBearerAuthenticationOptions>
|
||||
public class AuthenticationChallengeContext : BaseControlContext<JwtBearerOptions>
|
||||
{
|
||||
public AuthenticationChallengeContext(HttpContext context, JwtBearerAuthenticationOptions options)
|
||||
public AuthenticationChallengeContext(HttpContext context, JwtBearerOptions options)
|
||||
: base(context, options)
|
||||
{
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,9 +6,9 @@ using Microsoft.AspNet.Http;
|
|||
|
||||
namespace Microsoft.AspNet.Authentication.JwtBearer
|
||||
{
|
||||
public class AuthenticationFailedContext : BaseControlContext<JwtBearerAuthenticationOptions>
|
||||
public class AuthenticationFailedContext : BaseControlContext<JwtBearerOptions>
|
||||
{
|
||||
public AuthenticationFailedContext(HttpContext context, JwtBearerAuthenticationOptions options)
|
||||
public AuthenticationFailedContext(HttpContext context, JwtBearerOptions options)
|
||||
: base(context, options)
|
||||
{
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,7 @@
|
|||
// Copyright (c) .NET Foundation. 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;
|
||||
using Microsoft.AspNet.Http;
|
||||
|
||||
/// <summary>
|
||||
/// Specifies events which the <see cref="JwtBearerAuthenticationMiddleware"></see> invokes to enable developer control over the authentication process. />
|
||||
|
|
@ -13,7 +11,7 @@ namespace Microsoft.AspNet.Authentication.JwtBearer
|
|||
/// <summary>
|
||||
/// Jwt bearer token middleware events.
|
||||
/// </summary>
|
||||
public interface IJwtBearerAuthenticationEvents
|
||||
public interface IJwtBearerEvents
|
||||
{
|
||||
/// <summary>
|
||||
/// Invoked if exceptions are thrown during request processing. The exceptions will be re-thrown after this event unless suppressed.
|
||||
|
|
@ -13,7 +13,7 @@ namespace Microsoft.AspNet.Authentication.JwtBearer
|
|||
/// <summary>
|
||||
/// Jwt bearer token middleware events.
|
||||
/// </summary>
|
||||
public class JwtBearerAuthenticationEvents : IJwtBearerAuthenticationEvents
|
||||
public class JwtBearerEvents : IJwtBearerEvents
|
||||
{
|
||||
/// <summary>
|
||||
/// Invoked if exceptions are thrown during request processing. The exceptions will be re-thrown after this event unless suppressed.
|
||||
|
|
@ -5,9 +5,9 @@ using Microsoft.AspNet.Http;
|
|||
|
||||
namespace Microsoft.AspNet.Authentication.JwtBearer
|
||||
{
|
||||
public class MessageReceivedContext : BaseControlContext<JwtBearerAuthenticationOptions>
|
||||
public class MessageReceivedContext : BaseControlContext<JwtBearerOptions>
|
||||
{
|
||||
public MessageReceivedContext(HttpContext context, JwtBearerAuthenticationOptions options)
|
||||
public MessageReceivedContext(HttpContext context, JwtBearerOptions options)
|
||||
: base(context, options)
|
||||
{
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,9 +5,9 @@ using Microsoft.AspNet.Http;
|
|||
|
||||
namespace Microsoft.AspNet.Authentication.JwtBearer
|
||||
{
|
||||
public class SecurityTokenReceivedContext : BaseControlContext<JwtBearerAuthenticationOptions>
|
||||
public class SecurityTokenReceivedContext : BaseControlContext<JwtBearerOptions>
|
||||
{
|
||||
public SecurityTokenReceivedContext(HttpContext context, JwtBearerAuthenticationOptions options)
|
||||
public SecurityTokenReceivedContext(HttpContext context, JwtBearerOptions options)
|
||||
: base(context, options)
|
||||
{
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,9 +5,9 @@ using Microsoft.AspNet.Http;
|
|||
|
||||
namespace Microsoft.AspNet.Authentication.JwtBearer
|
||||
{
|
||||
public class SecurityTokenValidatedContext : BaseControlContext<JwtBearerAuthenticationOptions>
|
||||
public class SecurityTokenValidatedContext : BaseControlContext<JwtBearerOptions>
|
||||
{
|
||||
public SecurityTokenValidatedContext(HttpContext context, JwtBearerAuthenticationOptions options)
|
||||
public SecurityTokenValidatedContext(HttpContext context, JwtBearerOptions options)
|
||||
: base(context, options)
|
||||
{
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,10 +24,10 @@ namespace Microsoft.AspNet.Builder
|
|||
/// <param name="app">The application builder</param>
|
||||
/// <param name="options">Options which control the processing of the bearer header.</param>
|
||||
/// <returns>The application builder</returns>
|
||||
public static IApplicationBuilder UseJwtBearerAuthentication([NotNull] this IApplicationBuilder app, Action<JwtBearerAuthenticationOptions> configureOptions = null, string optionsName = "")
|
||||
public static IApplicationBuilder UseJwtBearerAuthentication([NotNull] this IApplicationBuilder app, Action<JwtBearerOptions> configureOptions = null, string optionsName = "")
|
||||
{
|
||||
return app.UseMiddleware<JwtBearerAuthenticationMiddleware>(
|
||||
new ConfigureOptions<JwtBearerAuthenticationOptions>(configureOptions ?? (o => { })));
|
||||
return app.UseMiddleware<JwtBearerMiddleware>(
|
||||
new ConfigureOptions<JwtBearerOptions>(configureOptions ?? (o => { })));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ namespace Microsoft.AspNet.Authentication.JwtBearer
|
|||
/// <summary>
|
||||
/// Default values used by authorization server and bearer authentication.
|
||||
/// </summary>
|
||||
public static class JwtBearerAuthenticationDefaults
|
||||
public static class JwtBearerDefaults
|
||||
{
|
||||
/// <summary>
|
||||
/// Default value for AuthenticationScheme property in the JwtBearerAuthenticationOptions and
|
||||
|
|
@ -5,7 +5,6 @@ using System;
|
|||
using System.IdentityModel.Tokens;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.Http.Authentication;
|
||||
using Microsoft.AspNet.Http.Features.Authentication;
|
||||
using Microsoft.Framework.Logging;
|
||||
|
|
@ -13,7 +12,7 @@ using Microsoft.IdentityModel.Protocols.OpenIdConnect;
|
|||
|
||||
namespace Microsoft.AspNet.Authentication.JwtBearer
|
||||
{
|
||||
public class JwtBearerAuthenticationHandler : AuthenticationHandler<JwtBearerAuthenticationOptions>
|
||||
public class JwtBearerHandler : AuthenticationHandler<JwtBearerOptions>
|
||||
{
|
||||
private OpenIdConnectConfiguration _configuration;
|
||||
|
||||
|
|
@ -18,24 +18,24 @@ namespace Microsoft.AspNet.Authentication.JwtBearer
|
|||
/// created by application code directly, instead it is added by calling the the IAppBuilder UseJwtBearerAuthentication
|
||||
/// extension method.
|
||||
/// </summary>
|
||||
public class JwtBearerAuthenticationMiddleware : AuthenticationMiddleware<JwtBearerAuthenticationOptions>
|
||||
public class JwtBearerMiddleware : AuthenticationMiddleware<JwtBearerOptions>
|
||||
{
|
||||
/// <summary>
|
||||
/// Bearer authentication component which is added to an HTTP pipeline. This constructor is not
|
||||
/// called by application code directly, instead it is added by calling the the IAppBuilder UseJwtBearerAuthentication
|
||||
/// extension method.
|
||||
/// </summary>
|
||||
public JwtBearerAuthenticationMiddleware(
|
||||
public JwtBearerMiddleware(
|
||||
[NotNull] RequestDelegate next,
|
||||
[NotNull] ILoggerFactory loggerFactory,
|
||||
[NotNull] IUrlEncoder encoder,
|
||||
[NotNull] IOptions<JwtBearerAuthenticationOptions> options,
|
||||
ConfigureOptions<JwtBearerAuthenticationOptions> configureOptions)
|
||||
[NotNull] IOptions<JwtBearerOptions> options,
|
||||
ConfigureOptions<JwtBearerOptions> configureOptions)
|
||||
: base(next, options, loggerFactory, encoder, configureOptions)
|
||||
{
|
||||
if (Options.Events == null)
|
||||
{
|
||||
Options.Events = new JwtBearerAuthenticationEvents();
|
||||
Options.Events = new JwtBearerEvents();
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(Options.TokenValidationParameters.ValidAudience) && !string.IsNullOrEmpty(Options.Audience))
|
||||
|
|
@ -75,9 +75,9 @@ namespace Microsoft.AspNet.Authentication.JwtBearer
|
|||
/// Called by the AuthenticationMiddleware base class to create a per-request handler.
|
||||
/// </summary>
|
||||
/// <returns>A new instance of the request handler</returns>
|
||||
protected override AuthenticationHandler<JwtBearerAuthenticationOptions> CreateHandler()
|
||||
protected override AuthenticationHandler<JwtBearerOptions> CreateHandler()
|
||||
{
|
||||
return new JwtBearerAuthenticationHandler();
|
||||
return new JwtBearerHandler();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -14,14 +14,14 @@ namespace Microsoft.AspNet.Authentication.JwtBearer
|
|||
/// <summary>
|
||||
/// Options class provides information needed to control Bearer Authentication middleware behavior
|
||||
/// </summary>
|
||||
public class JwtBearerAuthenticationOptions : AuthenticationOptions
|
||||
public class JwtBearerOptions : AuthenticationOptions
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates an instance of bearer authentication options with default values.
|
||||
/// </summary>
|
||||
public JwtBearerAuthenticationOptions() : base()
|
||||
public JwtBearerOptions() : base()
|
||||
{
|
||||
AuthenticationScheme = JwtBearerAuthenticationDefaults.AuthenticationScheme;
|
||||
AuthenticationScheme = JwtBearerDefaults.AuthenticationScheme;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -45,14 +45,14 @@ namespace Microsoft.AspNet.Authentication.JwtBearer
|
|||
/// <summary>
|
||||
/// Gets or sets the challenge to put in the "WWW-Authenticate" header.
|
||||
/// </summary>
|
||||
public string Challenge { get; set; } = JwtBearerAuthenticationDefaults.AuthenticationScheme;
|
||||
public string Challenge { get; set; } = JwtBearerDefaults.AuthenticationScheme;
|
||||
|
||||
/// <summary>
|
||||
/// The object provided by the application to process events raised by the bearer authentication middleware.
|
||||
/// The application may implement the interface fully, or it may create an instance of JwtBearerAuthenticationEvents
|
||||
/// and assign delegates only to the events it wants to process.
|
||||
/// </summary>
|
||||
public IJwtBearerAuthenticationEvents Events { get; set; } = new JwtBearerAuthenticationEvents();
|
||||
public IJwtBearerEvents Events { get; set; } = new JwtBearerEvents();
|
||||
|
||||
/// <summary>
|
||||
/// The HttpMessageHandler used to retrieve metadata.
|
||||
|
|
@ -13,14 +13,14 @@ namespace Microsoft.Framework.DependencyInjection
|
|||
/// </summary>
|
||||
public static class JwtBearerServiceCollectionExtensions
|
||||
{
|
||||
public static IServiceCollection ConfigureJwtBearerAuthentication([NotNull] this IServiceCollection services, [NotNull] Action<JwtBearerAuthenticationOptions> configure)
|
||||
public static IServiceCollection AddJwtBearerAuthentication([NotNull] this IServiceCollection services, [NotNull] Action<JwtBearerOptions> configure)
|
||||
{
|
||||
return services.Configure(configure);
|
||||
}
|
||||
|
||||
public static IServiceCollection ConfigureJwtBearerAuthentication([NotNull] this IServiceCollection services, [NotNull] IConfiguration config)
|
||||
public static IServiceCollection AddJwtBearerAuthentication([NotNull] this IServiceCollection services, [NotNull] IConfiguration config)
|
||||
{
|
||||
return services.ConfigureJwtBearerAuthentication(config);
|
||||
return services.Configure<JwtBearerOptions>(config);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,14 +9,14 @@ using Microsoft.Framework.OptionsModel;
|
|||
namespace Microsoft.AspNet.Builder
|
||||
{
|
||||
/// <summary>
|
||||
/// Extension methods for using <see cref="MicrosoftAccountAuthenticationMiddleware"/>
|
||||
/// Extension methods for using <see cref="MicrosoftAccountMiddleware"/>
|
||||
/// </summary>
|
||||
public static class MicrosoftAccountAuthenticationExtensions
|
||||
{
|
||||
public static IApplicationBuilder UseMicrosoftAccountAuthentication([NotNull] this IApplicationBuilder app, Action<MicrosoftAccountAuthenticationOptions> configureOptions = null)
|
||||
public static IApplicationBuilder UseMicrosoftAccountAuthentication([NotNull] this IApplicationBuilder app, Action<MicrosoftAccountOptions> configureOptions = null)
|
||||
{
|
||||
return app.UseMiddleware<MicrosoftAccountAuthenticationMiddleware>(
|
||||
new ConfigureOptions<MicrosoftAccountAuthenticationOptions>(configureOptions ?? (o => { })));
|
||||
return app.UseMiddleware<MicrosoftAccountMiddleware>(
|
||||
new ConfigureOptions<MicrosoftAccountOptions>(configureOptions ?? (o => { })));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,28 +0,0 @@
|
|||
// Copyright (c) .NET Foundation. 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.Authentication.OAuth;
|
||||
|
||||
namespace Microsoft.AspNet.Authentication.MicrosoftAccount
|
||||
{
|
||||
/// <summary>
|
||||
/// Configuration options for <see cref="MicrosoftAccountAuthenticationMiddleware"/>.
|
||||
/// </summary>
|
||||
public class MicrosoftAccountAuthenticationOptions : OAuthAuthenticationOptions
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new <see cref="MicrosoftAccountAuthenticationOptions"/>.
|
||||
/// </summary>
|
||||
public MicrosoftAccountAuthenticationOptions()
|
||||
{
|
||||
AuthenticationScheme = MicrosoftAccountAuthenticationDefaults.AuthenticationScheme;
|
||||
Caption = AuthenticationScheme;
|
||||
CallbackPath = new PathString("/signin-microsoft");
|
||||
AuthorizationEndpoint = MicrosoftAccountAuthenticationDefaults.AuthorizationEndpoint;
|
||||
TokenEndpoint = MicrosoftAccountAuthenticationDefaults.TokenEndpoint;
|
||||
UserInformationEndpoint = MicrosoftAccountAuthenticationDefaults.UserInformationEndpoint;
|
||||
SaveTokensAsClaims = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
namespace Microsoft.AspNet.Authentication.MicrosoftAccount
|
||||
{
|
||||
public static class MicrosoftAccountAuthenticationDefaults
|
||||
public static class MicrosoftAccountDefaults
|
||||
{
|
||||
public const string AuthenticationScheme = "Microsoft";
|
||||
|
||||
|
|
@ -11,9 +11,9 @@ using Newtonsoft.Json.Linq;
|
|||
|
||||
namespace Microsoft.AspNet.Authentication.MicrosoftAccount
|
||||
{
|
||||
internal class MicrosoftAccountAuthenticationHandler : OAuthAuthenticationHandler<MicrosoftAccountAuthenticationOptions>
|
||||
internal class MicrosoftAccountHandler : OAuthHandler<MicrosoftAccountOptions>
|
||||
{
|
||||
public MicrosoftAccountAuthenticationHandler(HttpClient httpClient)
|
||||
public MicrosoftAccountHandler(HttpClient httpClient)
|
||||
: base(httpClient)
|
||||
{
|
||||
}
|
||||
|
|
@ -34,21 +34,21 @@ namespace Microsoft.AspNet.Authentication.MicrosoftAccount
|
|||
Principal = new ClaimsPrincipal(identity)
|
||||
};
|
||||
|
||||
var identifier = MicrosoftAccountAuthenticationHelper.GetId(payload);
|
||||
var identifier = MicrosoftAccountHelper.GetId(payload);
|
||||
if (!string.IsNullOrEmpty(identifier))
|
||||
{
|
||||
identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, identifier, ClaimValueTypes.String, Options.ClaimsIssuer));
|
||||
identity.AddClaim(new Claim("urn:microsoftaccount:id", identifier, ClaimValueTypes.String, Options.ClaimsIssuer));
|
||||
}
|
||||
|
||||
var name = MicrosoftAccountAuthenticationHelper.GetName(payload);
|
||||
var name = MicrosoftAccountHelper.GetName(payload);
|
||||
if (!string.IsNullOrEmpty(name))
|
||||
{
|
||||
identity.AddClaim(new Claim(ClaimTypes.Name, name, ClaimValueTypes.String, Options.ClaimsIssuer));
|
||||
identity.AddClaim(new Claim("urn:microsoftaccount:name", name, ClaimValueTypes.String, Options.ClaimsIssuer));
|
||||
}
|
||||
|
||||
var email = MicrosoftAccountAuthenticationHelper.GetEmail(payload);
|
||||
var email = MicrosoftAccountHelper.GetEmail(payload);
|
||||
if (!string.IsNullOrEmpty(email))
|
||||
{
|
||||
identity.AddClaim(new Claim(ClaimTypes.Email, email, ClaimValueTypes.String, Options.ClaimsIssuer));
|
||||
|
|
@ -10,7 +10,7 @@ namespace Microsoft.AspNet.Authentication.MicrosoftAccount
|
|||
/// Contains static methods that allow to extract user's information from a <see cref="JObject"/>
|
||||
/// instance retrieved from Google after a successful authentication process.
|
||||
/// </summary>
|
||||
public static class MicrosoftAccountAuthenticationHelper
|
||||
public static class MicrosoftAccountHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the Microsoft Account user ID.
|
||||
|
|
@ -14,10 +14,10 @@ namespace Microsoft.AspNet.Authentication.MicrosoftAccount
|
|||
/// <summary>
|
||||
/// An ASP.NET middleware for authenticating users using the Microsoft Account service.
|
||||
/// </summary>
|
||||
public class MicrosoftAccountAuthenticationMiddleware : OAuthAuthenticationMiddleware<MicrosoftAccountAuthenticationOptions>
|
||||
public class MicrosoftAccountMiddleware : OAuthMiddleware<MicrosoftAccountOptions>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new <see cref="MicrosoftAccountAuthenticationMiddleware"/>.
|
||||
/// Initializes a new <see cref="MicrosoftAccountMiddleware"/>.
|
||||
/// </summary>
|
||||
/// <param name="next">The next middleware in the HTTP pipeline to invoke.</param>
|
||||
/// <param name="dataProtectionProvider"></param>
|
||||
|
|
@ -26,14 +26,14 @@ namespace Microsoft.AspNet.Authentication.MicrosoftAccount
|
|||
/// <param name="sharedOptions"></param>
|
||||
/// <param name="options">Configuration options for the middleware.</param>
|
||||
/// <param name="configureOptions"></param>
|
||||
public MicrosoftAccountAuthenticationMiddleware(
|
||||
public MicrosoftAccountMiddleware(
|
||||
[NotNull] RequestDelegate next,
|
||||
[NotNull] IDataProtectionProvider dataProtectionProvider,
|
||||
[NotNull] ILoggerFactory loggerFactory,
|
||||
[NotNull] IUrlEncoder encoder,
|
||||
[NotNull] IOptions<SharedAuthenticationOptions> sharedOptions,
|
||||
[NotNull] IOptions<MicrosoftAccountAuthenticationOptions> options,
|
||||
ConfigureOptions<MicrosoftAccountAuthenticationOptions> configureOptions = null)
|
||||
[NotNull] IOptions<MicrosoftAccountOptions> options,
|
||||
ConfigureOptions<MicrosoftAccountOptions> configureOptions = null)
|
||||
: base(next, dataProtectionProvider, loggerFactory, encoder, sharedOptions, options, configureOptions)
|
||||
{
|
||||
if (Options.Scope.Count == 0)
|
||||
|
|
@ -47,10 +47,10 @@ namespace Microsoft.AspNet.Authentication.MicrosoftAccount
|
|||
/// <summary>
|
||||
/// Provides the <see cref="AuthenticationHandler"/> object for processing authentication-related requests.
|
||||
/// </summary>
|
||||
/// <returns>An <see cref="AuthenticationHandler"/> configured with the <see cref="MicrosoftAccountAuthenticationOptions"/> supplied to the constructor.</returns>
|
||||
protected override AuthenticationHandler<MicrosoftAccountAuthenticationOptions> CreateHandler()
|
||||
/// <returns>An <see cref="AuthenticationHandler"/> configured with the <see cref="MicrosoftAccountOptions"/> supplied to the constructor.</returns>
|
||||
protected override AuthenticationHandler<MicrosoftAccountOptions> CreateHandler()
|
||||
{
|
||||
return new MicrosoftAccountAuthenticationHandler(Backchannel);
|
||||
return new MicrosoftAccountHandler(Backchannel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
// Copyright (c) .NET Foundation. 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.Authentication.OAuth;
|
||||
|
||||
namespace Microsoft.AspNet.Authentication.MicrosoftAccount
|
||||
{
|
||||
/// <summary>
|
||||
/// Configuration options for <see cref="MicrosoftAccountMiddleware"/>.
|
||||
/// </summary>
|
||||
public class MicrosoftAccountOptions : OAuthOptions
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new <see cref="MicrosoftAccountOptions"/>.
|
||||
/// </summary>
|
||||
public MicrosoftAccountOptions()
|
||||
{
|
||||
AuthenticationScheme = MicrosoftAccountDefaults.AuthenticationScheme;
|
||||
Caption = AuthenticationScheme;
|
||||
CallbackPath = new PathString("/signin-microsoft");
|
||||
AuthorizationEndpoint = MicrosoftAccountDefaults.AuthorizationEndpoint;
|
||||
TokenEndpoint = MicrosoftAccountDefaults.TokenEndpoint;
|
||||
UserInformationEndpoint = MicrosoftAccountDefaults.UserInformationEndpoint;
|
||||
SaveTokensAsClaims = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -9,18 +9,18 @@ using Microsoft.Framework.Internal;
|
|||
namespace Microsoft.Framework.DependencyInjection
|
||||
{
|
||||
/// <summary>
|
||||
/// Extension methods for using <see cref="MicrosoftAccountAuthenticationMiddleware"/>
|
||||
/// Extension methods for using <see cref="MicrosoftAccountMiddleware"/>
|
||||
/// </summary>
|
||||
public static class MicrosoftAccountServiceCollectionExtensions
|
||||
{
|
||||
public static IServiceCollection AddMicrosoftAccountAuthentication([NotNull] this IServiceCollection services, [NotNull] Action<MicrosoftAccountAuthenticationOptions> configure)
|
||||
public static IServiceCollection AddMicrosoftAccountAuthentication([NotNull] this IServiceCollection services, [NotNull] Action<MicrosoftAccountOptions> configure)
|
||||
{
|
||||
return services.Configure(configure);
|
||||
}
|
||||
|
||||
public static IServiceCollection AddMicrosoftAccountAuthentication([NotNull] this IServiceCollection services, [NotNull] IConfiguration config)
|
||||
{
|
||||
return services.Configure<MicrosoftAccountAuthenticationOptions>(config);
|
||||
return services.Configure<MicrosoftAccountOptions>(config);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,9 +6,9 @@ using System.Threading.Tasks;
|
|||
namespace Microsoft.AspNet.Authentication.OAuth
|
||||
{
|
||||
/// <summary>
|
||||
/// Specifies callback methods which the <see cref="OAuthAuthenticationMiddleware"/> invokes to enable developer control over the authentication process.
|
||||
/// Specifies callback methods which the <see cref="OAuthMiddleware"/> invokes to enable developer control over the authentication process.
|
||||
/// </summary>
|
||||
public interface IOAuthAuthenticationEvents
|
||||
public interface IOAuthEvents
|
||||
{
|
||||
/// <summary>
|
||||
/// Invoked after the provider successfully authenticates a user. This can be used to retrieve user information.
|
||||
|
|
@ -29,6 +29,6 @@ namespace Microsoft.AspNet.Authentication.OAuth
|
|||
/// Called when a Challenge causes a redirect to the authorize endpoint.
|
||||
/// </summary>
|
||||
/// <param name="context">Contains redirect URI and <see cref="AuthenticationProperties"/> of the challenge.</param>
|
||||
void ApplyRedirect(OAuthApplyRedirectContext context);
|
||||
Task ApplyRedirect(OAuthApplyRedirectContext context);
|
||||
}
|
||||
}
|
||||
|
|
@ -9,7 +9,7 @@ namespace Microsoft.AspNet.Authentication.OAuth
|
|||
/// <summary>
|
||||
/// Context passed when a Challenge causes a redirect to authorize endpoint in the Microsoft account middleware.
|
||||
/// </summary>
|
||||
public class OAuthApplyRedirectContext : BaseContext<OAuthAuthenticationOptions>
|
||||
public class OAuthApplyRedirectContext : BaseContext<OAuthOptions>
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new context object.
|
||||
|
|
@ -17,7 +17,7 @@ namespace Microsoft.AspNet.Authentication.OAuth
|
|||
/// <param name="context">The HTTP request context.</param>
|
||||
/// <param name="properties">The authentication properties of the challenge.</param>
|
||||
/// <param name="redirectUri">The initial redirect URI.</param>
|
||||
public OAuthApplyRedirectContext(HttpContext context, OAuthAuthenticationOptions options, AuthenticationProperties properties, string redirectUri)
|
||||
public OAuthApplyRedirectContext(HttpContext context, OAuthOptions options, AuthenticationProperties properties, string redirectUri)
|
||||
: base(context, options)
|
||||
{
|
||||
RedirectUri = redirectUri;
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ namespace Microsoft.AspNet.Authentication.OAuth
|
|||
/// <summary>
|
||||
/// Contains information about the login session as well as the user <see cref="System.Security.Claims.ClaimsIdentity"/>.
|
||||
/// </summary>
|
||||
public class OAuthAuthenticatedContext : BaseContext<OAuthAuthenticationOptions>
|
||||
public class OAuthAuthenticatedContext : BaseContext<OAuthOptions>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new <see cref="OAuthAuthenticatedContext"/>.
|
||||
|
|
@ -26,7 +26,7 @@ namespace Microsoft.AspNet.Authentication.OAuth
|
|||
/// <param name="tokens">The tokens returned from the token endpoint.</param>
|
||||
public OAuthAuthenticatedContext(
|
||||
[NotNull] HttpContext context,
|
||||
[NotNull] OAuthAuthenticationOptions options,
|
||||
[NotNull] OAuthOptions options,
|
||||
[NotNull] HttpClient backchannel,
|
||||
[NotNull] OAuthTokenResponse tokens)
|
||||
: this(context, options, backchannel, tokens, user: new JObject())
|
||||
|
|
@ -43,7 +43,7 @@ namespace Microsoft.AspNet.Authentication.OAuth
|
|||
/// <param name="user">The JSON-serialized user.</param>
|
||||
public OAuthAuthenticatedContext(
|
||||
[NotNull] HttpContext context,
|
||||
[NotNull] OAuthAuthenticationOptions options,
|
||||
[NotNull] OAuthOptions options,
|
||||
[NotNull] HttpClient backchannel,
|
||||
[NotNull] OAuthTokenResponse tokens,
|
||||
[NotNull] JObject user)
|
||||
|
|
|
|||
|
|
@ -7,9 +7,9 @@ using System.Threading.Tasks;
|
|||
namespace Microsoft.AspNet.Authentication.OAuth
|
||||
{
|
||||
/// <summary>
|
||||
/// Default <see cref="IOAuthAuthenticationEvents"/> implementation.
|
||||
/// Default <see cref="IOAuthEvents"/> implementation.
|
||||
/// </summary>
|
||||
public class OAuthAuthenticationEvents : IOAuthAuthenticationEvents
|
||||
public class OAuthEvents : IOAuthEvents
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the function that is invoked when the Authenticated method is invoked.
|
||||
|
|
@ -24,7 +24,11 @@ namespace Microsoft.AspNet.Authentication.OAuth
|
|||
/// <summary>
|
||||
/// Gets or sets the delegate that is invoked when the ApplyRedirect method is invoked.
|
||||
/// </summary>
|
||||
public Action<OAuthApplyRedirectContext> OnApplyRedirect { get; set; } = context => context.Response.Redirect(context.RedirectUri);
|
||||
public Func<OAuthApplyRedirectContext, Task> OnApplyRedirect { get; set; } = context =>
|
||||
{
|
||||
context.Response.Redirect(context.RedirectUri);
|
||||
return Task.FromResult(0);
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Invoked after the provider successfully authenticates a user.
|
||||
|
|
@ -44,6 +48,6 @@ namespace Microsoft.AspNet.Authentication.OAuth
|
|||
/// Called when a Challenge causes a redirect to authorize endpoint in the OAuth middleware.
|
||||
/// </summary>
|
||||
/// <param name="context">Contains redirect URI and <see cref="AuthenticationProperties"/> of the challenge.</param>
|
||||
public virtual void ApplyRedirect(OAuthApplyRedirectContext context) => OnApplyRedirect(context);
|
||||
public virtual Task ApplyRedirect(OAuthApplyRedirectContext context) => OnApplyRedirect(context);
|
||||
}
|
||||
}
|
||||
|
|
@ -9,9 +9,9 @@ using Microsoft.Framework.OptionsModel;
|
|||
namespace Microsoft.AspNet.Builder
|
||||
{
|
||||
/// <summary>
|
||||
/// Extension methods for using <see cref="OAuthAuthenticationMiddleware"/>
|
||||
/// Extension methods for using <see cref="OAuthMiddleware"/>
|
||||
/// </summary>
|
||||
public static class OAuthAuthenticationExtensions
|
||||
public static class OAuthExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Authenticate users using OAuth.
|
||||
|
|
@ -19,11 +19,11 @@ namespace Microsoft.AspNet.Builder
|
|||
/// <param name="app">The <see cref="IApplicationBuilder"/> passed to the configure method.</param>
|
||||
/// <param name="options">The middleware configuration options.</param>
|
||||
/// <returns>The updated <see cref="IApplicationBuilder"/>.</returns>
|
||||
public static IApplicationBuilder UseOAuthAuthentication([NotNull] this IApplicationBuilder app, [NotNull] IOptions<OAuthAuthenticationOptions> options)
|
||||
public static IApplicationBuilder UseOAuthAuthentication([NotNull] this IApplicationBuilder app, [NotNull] IOptions<OAuthOptions> options)
|
||||
{
|
||||
return app.UseMiddleware<OAuthAuthenticationMiddleware<OAuthAuthenticationOptions>>(
|
||||
return app.UseMiddleware<OAuthMiddleware<OAuthOptions>>(
|
||||
options,
|
||||
new ConfigureOptions<OAuthAuthenticationOptions>(o => { }));
|
||||
new ConfigureOptions<OAuthOptions>(o => { }));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -20,11 +20,11 @@ using Newtonsoft.Json.Linq;
|
|||
|
||||
namespace Microsoft.AspNet.Authentication.OAuth
|
||||
{
|
||||
public class OAuthAuthenticationHandler<TOptions> : AuthenticationHandler<TOptions> where TOptions : OAuthAuthenticationOptions
|
||||
public class OAuthHandler<TOptions> : AuthenticationHandler<TOptions> where TOptions : OAuthOptions
|
||||
{
|
||||
private static readonly RandomNumberGenerator CryptoRandom = RandomNumberGenerator.Create();
|
||||
|
||||
public OAuthAuthenticationHandler(HttpClient backchannel)
|
||||
public OAuthHandler(HttpClient backchannel)
|
||||
{
|
||||
Backchannel = backchannel;
|
||||
}
|
||||
|
|
@ -199,7 +199,7 @@ namespace Microsoft.AspNet.Authentication.OAuth
|
|||
return new AuthenticationTicket(context.Principal, context.Properties, Options.AuthenticationScheme);
|
||||
}
|
||||
|
||||
protected override Task<bool> HandleUnauthorizedAsync([NotNull] ChallengeContext context)
|
||||
protected override async Task<bool> HandleUnauthorizedAsync([NotNull] ChallengeContext context)
|
||||
{
|
||||
var properties = new AuthenticationProperties(context.Properties);
|
||||
if (string.IsNullOrEmpty(properties.RedirectUri))
|
||||
|
|
@ -215,8 +215,8 @@ namespace Microsoft.AspNet.Authentication.OAuth
|
|||
var redirectContext = new OAuthApplyRedirectContext(
|
||||
Context, Options,
|
||||
properties, authorizationEndpoint);
|
||||
Options.Events.ApplyRedirect(redirectContext);
|
||||
return Task.FromResult(true);
|
||||
await Options.Events.ApplyRedirect(redirectContext);
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override Task HandleSignOutAsync(SignOutContext context)
|
||||
|
|
@ -18,7 +18,7 @@ namespace Microsoft.AspNet.Authentication.OAuth
|
|||
/// An ASP.NET middleware for authenticating users using OAuth services.
|
||||
/// </summary>
|
||||
[SuppressMessage("Microsoft.Design", "CA1001:TypesThatOwnDisposableFieldsShouldBeDisposable", Justification = "Middleware are not disposable.")]
|
||||
public class OAuthAuthenticationMiddleware<TOptions> : AuthenticationMiddleware<TOptions> where TOptions : OAuthAuthenticationOptions, new()
|
||||
public class OAuthMiddleware<TOptions> : AuthenticationMiddleware<TOptions> where TOptions : OAuthOptions, new()
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new <see cref="OAuthAuthenticationMiddleware"/>.
|
||||
|
|
@ -27,7 +27,7 @@ namespace Microsoft.AspNet.Authentication.OAuth
|
|||
/// <param name="dataProtectionProvider"></param>
|
||||
/// <param name="loggerFactory"></param>
|
||||
/// <param name="options">Configuration options for the middleware.</param>
|
||||
public OAuthAuthenticationMiddleware(
|
||||
public OAuthMiddleware(
|
||||
[NotNull] RequestDelegate next,
|
||||
[NotNull] IDataProtectionProvider dataProtectionProvider,
|
||||
[NotNull] ILoggerFactory loggerFactory,
|
||||
|
|
@ -65,7 +65,7 @@ namespace Microsoft.AspNet.Authentication.OAuth
|
|||
|
||||
if (Options.Events == null)
|
||||
{
|
||||
Options.Events = new OAuthAuthenticationEvents();
|
||||
Options.Events = new OAuthEvents();
|
||||
}
|
||||
|
||||
if (Options.StateDataFormat == null)
|
||||
|
|
@ -91,10 +91,10 @@ namespace Microsoft.AspNet.Authentication.OAuth
|
|||
/// <summary>
|
||||
/// Provides the <see cref="AuthenticationHandler"/> object for processing authentication-related requests.
|
||||
/// </summary>
|
||||
/// <returns>An <see cref="AuthenticationHandler"/> configured with the <see cref="OAuthAuthenticationOptions"/> supplied to the constructor.</returns>
|
||||
/// <returns>An <see cref="AuthenticationHandler"/> configured with the <see cref="OAuthOptions"/> supplied to the constructor.</returns>
|
||||
protected override AuthenticationHandler<TOptions> CreateHandler()
|
||||
{
|
||||
return new OAuthAuthenticationHandler<TOptions>(Backchannel);
|
||||
return new OAuthHandler<TOptions>(Backchannel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -11,9 +11,9 @@ using Microsoft.Framework.OptionsModel;
|
|||
namespace Microsoft.AspNet.Authentication.OAuth
|
||||
{
|
||||
/// <summary>
|
||||
/// Configuration options for <see cref="OAuthAuthenticationMiddleware"/>.
|
||||
/// Configuration options for <see cref="OAuthMiddleware"/>.
|
||||
/// </summary>
|
||||
public class OAuthAuthenticationOptions : AuthenticationOptions, IOptions<OAuthAuthenticationOptions>
|
||||
public class OAuthOptions : AuthenticationOptions, IOptions<OAuthOptions>
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the provider-assigned client id.
|
||||
|
|
@ -67,9 +67,9 @@ namespace Microsoft.AspNet.Authentication.OAuth
|
|||
public HttpMessageHandler BackchannelHttpHandler { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the <see cref="IOAuthAuthenticationEvents"/> used to handle authentication events.
|
||||
/// Gets or sets the <see cref="IOAuthEvents"/> used to handle authentication events.
|
||||
/// </summary>
|
||||
public IOAuthAuthenticationEvents Events { get; set; } = new OAuthAuthenticationEvents();
|
||||
public IOAuthEvents Events { get; set; } = new OAuthEvents();
|
||||
|
||||
/// <summary>
|
||||
/// A list of permissions to request.
|
||||
|
|
@ -103,7 +103,7 @@ namespace Microsoft.AspNet.Authentication.OAuth
|
|||
/// </summary>
|
||||
public bool SaveTokensAsClaims { get; set; } = true;
|
||||
|
||||
OAuthAuthenticationOptions IOptions<OAuthAuthenticationOptions>.Value
|
||||
OAuthOptions IOptions<OAuthOptions>.Value
|
||||
{
|
||||
get
|
||||
{
|
||||
|
|
@ -7,9 +7,9 @@ using Microsoft.IdentityModel.Protocols.OpenIdConnect;
|
|||
|
||||
namespace Microsoft.AspNet.Authentication.OpenIdConnect
|
||||
{
|
||||
public class AuthenticationFailedContext : BaseControlContext<OpenIdConnectAuthenticationOptions>
|
||||
public class AuthenticationFailedContext : BaseControlContext<OpenIdConnectOptions>
|
||||
{
|
||||
public AuthenticationFailedContext(HttpContext context, OpenIdConnectAuthenticationOptions options)
|
||||
public AuthenticationFailedContext(HttpContext context, OpenIdConnectOptions options)
|
||||
: base(context, options)
|
||||
{
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,12 +11,12 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect
|
|||
/// <summary>
|
||||
/// This Context can be used to be informed when an 'AuthorizationCode' is received over the OpenIdConnect protocol.
|
||||
/// </summary>
|
||||
public class AuthorizationCodeReceivedContext : BaseControlContext<OpenIdConnectAuthenticationOptions>
|
||||
public class AuthorizationCodeReceivedContext : BaseControlContext<OpenIdConnectOptions>
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a <see cref="AuthorizationCodeReceivedContext"/>
|
||||
/// </summary>
|
||||
public AuthorizationCodeReceivedContext(HttpContext context, OpenIdConnectAuthenticationOptions options)
|
||||
public AuthorizationCodeReceivedContext(HttpContext context, OpenIdConnectOptions options)
|
||||
: base(context, options)
|
||||
{
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,12 +6,12 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect
|
|||
/// <summary>
|
||||
/// This Context can be used to be informed when an 'AuthorizationCode' is redeemed for tokens at the token endpoint.
|
||||
/// </summary>
|
||||
public class AuthorizationCodeRedeemedContext : BaseControlContext<OpenIdConnectAuthenticationOptions>
|
||||
public class AuthorizationCodeRedeemedContext : BaseControlContext<OpenIdConnectOptions>
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a <see cref="AuthorizationCodeRedeemedContext"/>
|
||||
/// </summary>
|
||||
public AuthorizationCodeRedeemedContext(HttpContext context, OpenIdConnectAuthenticationOptions options)
|
||||
public AuthorizationCodeRedeemedContext(HttpContext context, OpenIdConnectOptions options)
|
||||
: base(context, options)
|
||||
{
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,9 +6,9 @@ using System.Threading.Tasks;
|
|||
namespace Microsoft.AspNet.Authentication.OpenIdConnect
|
||||
{
|
||||
/// <summary>
|
||||
/// Specifies events which the <see cref="OpenIdConnectAuthenticationMiddleware" />invokes to enable developer control over the authentication process.
|
||||
/// Specifies events which the <see cref="OpenIdConnectMiddleware" />invokes to enable developer control over the authentication process.
|
||||
/// </summary>
|
||||
public interface IOpenIdConnectAuthenticationEvents
|
||||
public interface IOpenIdConnectEvents
|
||||
{
|
||||
/// <summary>
|
||||
/// Invoked if exceptions are thrown during request processing. The exceptions will be re-thrown after this event unless suppressed.
|
||||
|
|
@ -6,9 +6,9 @@ using Microsoft.IdentityModel.Protocols.OpenIdConnect;
|
|||
|
||||
namespace Microsoft.AspNet.Authentication.OpenIdConnect
|
||||
{
|
||||
public class MessageReceivedContext : BaseControlContext<OpenIdConnectAuthenticationOptions>
|
||||
public class MessageReceivedContext : BaseControlContext<OpenIdConnectOptions>
|
||||
{
|
||||
public MessageReceivedContext(HttpContext context, OpenIdConnectAuthenticationOptions options)
|
||||
public MessageReceivedContext(HttpContext context, OpenIdConnectOptions options)
|
||||
: base(context, options)
|
||||
{
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,9 +7,9 @@ using System.Threading.Tasks;
|
|||
namespace Microsoft.AspNet.Authentication.OpenIdConnect
|
||||
{
|
||||
/// <summary>
|
||||
/// Specifies events which the <see cref="OpenIdConnectAuthenticationMiddleware" />invokes to enable developer control over the authentication process.
|
||||
/// Specifies events which the <see cref="OpenIdConnectMiddleware" />invokes to enable developer control over the authentication process.
|
||||
/// </summary>
|
||||
public class OpenIdConnectAuthenticationEvents : IOpenIdConnectAuthenticationEvents
|
||||
public class OpenIdConnectEvents : IOpenIdConnectEvents
|
||||
{
|
||||
/// <summary>
|
||||
/// Invoked if exceptions are thrown during request processing. The exceptions will be re-thrown after this event unless suppressed.
|
||||
|
|
@ -14,9 +14,9 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect
|
|||
/// </summary>
|
||||
/// <typeparam name="TMessage">protocol specific message.</typeparam>
|
||||
/// <typeparam name="TOptions">protocol specific options.</typeparam>
|
||||
public class RedirectToIdentityProviderContext : BaseControlContext<OpenIdConnectAuthenticationOptions>
|
||||
public class RedirectToIdentityProviderContext : BaseControlContext<OpenIdConnectOptions>
|
||||
{
|
||||
public RedirectToIdentityProviderContext([NotNull] HttpContext context, [NotNull] OpenIdConnectAuthenticationOptions options)
|
||||
public RedirectToIdentityProviderContext([NotNull] HttpContext context, [NotNull] OpenIdConnectOptions options)
|
||||
: base(context, options)
|
||||
{
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,9 +6,9 @@ using Microsoft.IdentityModel.Protocols.OpenIdConnect;
|
|||
|
||||
namespace Microsoft.AspNet.Authentication.OpenIdConnect
|
||||
{
|
||||
public class SecurityTokenReceivedContext : BaseControlContext<OpenIdConnectAuthenticationOptions>
|
||||
public class SecurityTokenReceivedContext : BaseControlContext<OpenIdConnectOptions>
|
||||
{
|
||||
public SecurityTokenReceivedContext(HttpContext context, OpenIdConnectAuthenticationOptions options)
|
||||
public SecurityTokenReceivedContext(HttpContext context, OpenIdConnectOptions options)
|
||||
: base(context, options)
|
||||
{
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,9 +6,9 @@ using Microsoft.IdentityModel.Protocols.OpenIdConnect;
|
|||
|
||||
namespace Microsoft.AspNet.Authentication.OpenIdConnect
|
||||
{
|
||||
public class SecurityTokenValidatedContext : BaseControlContext<OpenIdConnectAuthenticationOptions>
|
||||
public class SecurityTokenValidatedContext : BaseControlContext<OpenIdConnectOptions>
|
||||
{
|
||||
public SecurityTokenValidatedContext(HttpContext context, OpenIdConnectAuthenticationOptions options)
|
||||
public SecurityTokenValidatedContext(HttpContext context, OpenIdConnectOptions options)
|
||||
: base(context, options)
|
||||
{
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect
|
|||
/// <summary>
|
||||
/// Default values related to OpenIdConnect authentication middleware
|
||||
/// </summary>
|
||||
public static class OpenIdConnectAuthenticationDefaults
|
||||
public static class OpenIdConnectDefaults
|
||||
{
|
||||
/// <summary>
|
||||
/// Constant used to identify state in openIdConnect protocol message.
|
||||
|
|
@ -14,12 +14,12 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect
|
|||
public const string AuthenticationPropertiesKey = "OpenIdConnect.AuthenticationProperties";
|
||||
|
||||
/// <summary>
|
||||
/// The default value used for OpenIdConnectAuthenticationOptions.AuthenticationScheme.
|
||||
/// The default value used for OpenIdConnectOptions.AuthenticationScheme.
|
||||
/// </summary>
|
||||
public const string AuthenticationScheme = "OpenIdConnect";
|
||||
|
||||
/// <summary>
|
||||
/// The default value for OpenIdConnectAuthenticationOptions.Caption.
|
||||
/// The default value for OpenIdConnectOptions.Caption.
|
||||
/// </summary>
|
||||
public const string Caption = "OpenIdConnect";
|
||||
|
||||
|
|
@ -8,31 +8,31 @@ using Microsoft.Framework.OptionsModel;
|
|||
namespace Microsoft.AspNet.Builder
|
||||
{
|
||||
/// <summary>
|
||||
/// Extension methods for using <see cref="OpenIdConnectAuthenticationMiddleware"/>
|
||||
/// Extension methods for using <see cref="OpenIdConnectMiddleware"/>
|
||||
/// </summary>
|
||||
public static class OpenIdConnectAuthenticationExtensions
|
||||
public static class OpenIdConnectExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Adds the <see cref="OpenIdConnectAuthenticationMiddleware"/> into the ASP.NET runtime.
|
||||
/// Adds the <see cref="OpenIdConnectMiddleware"/> into the ASP.NET runtime.
|
||||
/// </summary>
|
||||
/// <param name="app">The application builder</param>
|
||||
/// <param name="options">Options which control the processing of the OpenIdConnect protocol and token validation.</param>
|
||||
/// <returns>The application builder</returns>
|
||||
public static IApplicationBuilder UseOpenIdConnectAuthentication(this IApplicationBuilder app, Action<OpenIdConnectAuthenticationOptions> configureOptions = null)
|
||||
public static IApplicationBuilder UseOpenIdConnectAuthentication(this IApplicationBuilder app, Action<OpenIdConnectOptions> configureOptions = null)
|
||||
{
|
||||
return app.UseMiddleware<OpenIdConnectAuthenticationMiddleware>(
|
||||
new ConfigureOptions<OpenIdConnectAuthenticationOptions>(configureOptions ?? (o => { })));
|
||||
return app.UseMiddleware<OpenIdConnectMiddleware>(
|
||||
new ConfigureOptions<OpenIdConnectOptions>(configureOptions ?? (o => { })));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the <see cref="OpenIdConnectAuthenticationMiddleware"/> into the ASP.NET runtime.
|
||||
/// Adds the <see cref="OpenIdConnectMiddleware"/> into the ASP.NET runtime.
|
||||
/// </summary>
|
||||
/// <param name="app">The application builder</param>
|
||||
/// <param name="options">Options which control the processing of the OpenIdConnect protocol and token validation.</param>
|
||||
/// <returns>The application builder</returns>
|
||||
public static IApplicationBuilder UseOpenIdConnectAuthentication(this IApplicationBuilder app, IOptions<OpenIdConnectAuthenticationOptions> options)
|
||||
public static IApplicationBuilder UseOpenIdConnectAuthentication(this IApplicationBuilder app, IOptions<OpenIdConnectOptions> options)
|
||||
{
|
||||
return app.UseMiddleware<OpenIdConnectAuthenticationMiddleware>(options);
|
||||
return app.UseMiddleware<OpenIdConnectMiddleware>(options);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -6,7 +6,6 @@ using System.Collections.Generic;
|
|||
using System.Globalization;
|
||||
using System.IdentityModel.Tokens;
|
||||
using System.IdentityModel.Tokens.Jwt;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Headers;
|
||||
|
|
@ -29,7 +28,7 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect
|
|||
/// <summary>
|
||||
/// A per-request authentication handler for the OpenIdConnectAuthenticationMiddleware.
|
||||
/// </summary>
|
||||
public class OpenIdConnectAuthenticationHandler : AuthenticationHandler<OpenIdConnectAuthenticationOptions>
|
||||
public class OpenIdConnectHandler : AuthenticationHandler<OpenIdConnectOptions>
|
||||
{
|
||||
private const string NonceProperty = "N";
|
||||
private const string UriSchemeDelimiter = "://";
|
||||
|
|
@ -55,7 +54,7 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect
|
|||
|
||||
protected HttpClient Backchannel { get; private set; }
|
||||
|
||||
public OpenIdConnectAuthenticationHandler(HttpClient backchannel)
|
||||
public OpenIdConnectHandler(HttpClient backchannel)
|
||||
{
|
||||
Backchannel = backchannel;
|
||||
}
|
||||
|
|
@ -111,7 +110,7 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect
|
|||
|
||||
message = redirectToIdentityProviderContext.ProtocolMessage;
|
||||
|
||||
if (Options.AuthenticationMethod == OpenIdConnectAuthenticationMethod.RedirectGet)
|
||||
if (Options.AuthenticationMethod == OpenIdConnectRedirectBehavior.RedirectGet)
|
||||
{
|
||||
var redirectUri = message.CreateLogoutRequestUrl();
|
||||
if (!Uri.IsWellFormedUriString(redirectUri, UriKind.Absolute))
|
||||
|
|
@ -121,7 +120,7 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect
|
|||
|
||||
Response.Redirect(redirectUri);
|
||||
}
|
||||
else if (Options.AuthenticationMethod == OpenIdConnectAuthenticationMethod.FormPost)
|
||||
else if (Options.AuthenticationMethod == OpenIdConnectRedirectBehavior.FormPost)
|
||||
{
|
||||
var inputs = new StringBuilder();
|
||||
foreach (var parameter in message.Parameters)
|
||||
|
|
@ -244,7 +243,7 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect
|
|||
|
||||
if (!string.IsNullOrEmpty(redirectToIdentityProviderContext.ProtocolMessage.State))
|
||||
{
|
||||
properties.Items[OpenIdConnectAuthenticationDefaults.UserstatePropertiesKey] = redirectToIdentityProviderContext.ProtocolMessage.State;
|
||||
properties.Items[OpenIdConnectDefaults.UserstatePropertiesKey] = redirectToIdentityProviderContext.ProtocolMessage.State;
|
||||
}
|
||||
|
||||
message = redirectToIdentityProviderContext.ProtocolMessage;
|
||||
|
|
@ -259,12 +258,12 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect
|
|||
if (!string.IsNullOrEmpty(redirectUriForCode))
|
||||
{
|
||||
// When redeeming a 'code' for an AccessToken, this value is needed
|
||||
properties.Items.Add(OpenIdConnectAuthenticationDefaults.RedirectUriForCodePropertiesKey, redirectUriForCode);
|
||||
properties.Items.Add(OpenIdConnectDefaults.RedirectUriForCodePropertiesKey, redirectUriForCode);
|
||||
}
|
||||
|
||||
message.State = Options.StateDataFormat.Protect(properties);
|
||||
|
||||
if (Options.AuthenticationMethod == OpenIdConnectAuthenticationMethod.RedirectGet)
|
||||
if (Options.AuthenticationMethod == OpenIdConnectRedirectBehavior.RedirectGet)
|
||||
{
|
||||
var redirectUri = message.CreateAuthenticationRequestUrl();
|
||||
if (!Uri.IsWellFormedUriString(redirectUri, UriKind.Absolute))
|
||||
|
|
@ -276,7 +275,7 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect
|
|||
|
||||
return true;
|
||||
}
|
||||
else if (Options.AuthenticationMethod == OpenIdConnectAuthenticationMethod.FormPost)
|
||||
else if (Options.AuthenticationMethod == OpenIdConnectRedirectBehavior.FormPost)
|
||||
{
|
||||
var inputs = new StringBuilder();
|
||||
foreach (var parameter in message.Parameters)
|
||||
|
|
@ -387,7 +386,7 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect
|
|||
}
|
||||
|
||||
string userstate = null;
|
||||
properties.Items.TryGetValue(OpenIdConnectAuthenticationDefaults.UserstatePropertiesKey, out userstate);
|
||||
properties.Items.TryGetValue(OpenIdConnectDefaults.UserstatePropertiesKey, out userstate);
|
||||
message.State = userstate;
|
||||
}
|
||||
|
||||
|
|
@ -661,7 +660,7 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect
|
|||
/// Adds the nonce to <see cref="HttpResponse.Cookies"/>.
|
||||
/// </summary>
|
||||
/// <param name="nonce">the nonce to remember.</param>
|
||||
/// <remarks><see cref="HttpResponse.Cookies.Append"/>is called to add a cookie with the name: 'OpenIdConnectAuthenticationDefaults.Nonce + <see cref="OpenIdConnectAuthenticationOptions.StringDataFormat.Protect"/>(nonce)'.
|
||||
/// <remarks><see cref="HttpResponse.Cookies.Append"/>is called to add a cookie with the name: 'OpenIdConnectAuthenticationDefaults.Nonce + <see cref="OpenIdConnectOptions.StringDataFormat.Protect"/>(nonce)'.
|
||||
/// The value of the cookie is: "N".</remarks>
|
||||
private void WriteNonceCookie(string nonce)
|
||||
{
|
||||
|
|
@ -671,7 +670,7 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect
|
|||
}
|
||||
|
||||
Response.Cookies.Append(
|
||||
OpenIdConnectAuthenticationDefaults.CookieNoncePrefix + Options.StringDataFormat.Protect(nonce),
|
||||
OpenIdConnectDefaults.CookieNoncePrefix + Options.StringDataFormat.Protect(nonce),
|
||||
NonceProperty,
|
||||
new CookieOptions
|
||||
{
|
||||
|
|
@ -687,7 +686,7 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect
|
|||
/// <param name="nonce">the nonce that we are looking for.</param>
|
||||
/// <returns>echos 'nonce' if a cookie is found that matches, null otherwise.</returns>
|
||||
/// <remarks>Examine <see cref="HttpRequest.Cookies.Keys"/> that start with the prefix: 'OpenIdConnectAuthenticationDefaults.Nonce'.
|
||||
/// <see cref="OpenIdConnectAuthenticationOptions.StringDataFormat.Unprotect"/> is used to obtain the actual 'nonce'. If the nonce is found, then <see cref="HttpResponse.Cookies.Delete"/> is called.</remarks>
|
||||
/// <see cref="OpenIdConnectOptions.StringDataFormat.Unprotect"/> is used to obtain the actual 'nonce'. If the nonce is found, then <see cref="HttpResponse.Cookies.Delete"/> is called.</remarks>
|
||||
private string ReadNonceCookie(string nonce)
|
||||
{
|
||||
if (nonce == null)
|
||||
|
|
@ -697,11 +696,11 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect
|
|||
|
||||
foreach (var nonceKey in Request.Cookies.Keys)
|
||||
{
|
||||
if (nonceKey.StartsWith(OpenIdConnectAuthenticationDefaults.CookieNoncePrefix))
|
||||
if (nonceKey.StartsWith(OpenIdConnectDefaults.CookieNoncePrefix))
|
||||
{
|
||||
try
|
||||
{
|
||||
var nonceDecodedValue = Options.StringDataFormat.Unprotect(nonceKey.Substring(OpenIdConnectAuthenticationDefaults.CookieNoncePrefix.Length, nonceKey.Length - OpenIdConnectAuthenticationDefaults.CookieNoncePrefix.Length));
|
||||
var nonceDecodedValue = Options.StringDataFormat.Unprotect(nonceKey.Substring(OpenIdConnectDefaults.CookieNoncePrefix.Length, nonceKey.Length - OpenIdConnectDefaults.CookieNoncePrefix.Length));
|
||||
if (nonceDecodedValue == nonce)
|
||||
{
|
||||
var cookieOptions = new CookieOptions
|
||||
|
|
@ -726,7 +725,7 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect
|
|||
|
||||
private void GenerateCorrelationId([NotNull] AuthenticationProperties properties)
|
||||
{
|
||||
var correlationKey = OpenIdConnectAuthenticationDefaults.CookieStatePrefix;
|
||||
var correlationKey = OpenIdConnectDefaults.CookieStatePrefix;
|
||||
|
||||
var nonceBytes = new byte[32];
|
||||
CryptoRandom.GetBytes(nonceBytes);
|
||||
|
|
@ -746,7 +745,7 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect
|
|||
|
||||
private bool ValidateCorrelationId([NotNull] AuthenticationProperties properties)
|
||||
{
|
||||
var correlationKey = OpenIdConnectAuthenticationDefaults.CookieStatePrefix;
|
||||
var correlationKey = OpenIdConnectDefaults.CookieStatePrefix;
|
||||
|
||||
string correlationId;
|
||||
if (!properties.Items.TryGetValue(
|
||||
|
|
@ -788,12 +787,12 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect
|
|||
{
|
||||
// assume a well formed query string: <a=b&>OpenIdConnectAuthenticationDefaults.AuthenticationPropertiesKey=kasjd;fljasldkjflksdj<&c=d>
|
||||
var startIndex = 0;
|
||||
if (string.IsNullOrEmpty(state) || (startIndex = state.IndexOf(OpenIdConnectAuthenticationDefaults.AuthenticationPropertiesKey, StringComparison.Ordinal)) == -1)
|
||||
if (string.IsNullOrEmpty(state) || (startIndex = state.IndexOf(OpenIdConnectDefaults.AuthenticationPropertiesKey, StringComparison.Ordinal)) == -1)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var authenticationIndex = startIndex + OpenIdConnectAuthenticationDefaults.AuthenticationPropertiesKey.Length;
|
||||
var authenticationIndex = startIndex + OpenIdConnectDefaults.AuthenticationPropertiesKey.Length;
|
||||
if (authenticationIndex == -1 || authenticationIndex == state.Length || state[authenticationIndex] != '=')
|
||||
{
|
||||
return null;
|
||||
|
|
@ -837,8 +836,8 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect
|
|||
|
||||
private async Task<AuthorizationCodeReceivedContext> RunAuthorizationCodeReceivedEventAsync(OpenIdConnectMessage message, AuthenticationProperties properties, AuthenticationTicket ticket, JwtSecurityToken jwt)
|
||||
{
|
||||
var redirectUri = properties.Items.ContainsKey(OpenIdConnectAuthenticationDefaults.RedirectUriForCodePropertiesKey) ?
|
||||
properties.Items[OpenIdConnectAuthenticationDefaults.RedirectUriForCodePropertiesKey] : Options.RedirectUri;
|
||||
var redirectUri = properties.Items.ContainsKey(OpenIdConnectDefaults.RedirectUriForCodePropertiesKey) ?
|
||||
properties.Items[OpenIdConnectDefaults.RedirectUriForCodePropertiesKey] : Options.RedirectUri;
|
||||
|
||||
Logger.LogDebug(Resources.OIDCH_0014_AuthorizationCodeReceived, message.Code);
|
||||
|
||||
|
|
@ -22,10 +22,10 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect
|
|||
/// <summary>
|
||||
/// ASP.NET middleware for obtaining identities using OpenIdConnect protocol.
|
||||
/// </summary>
|
||||
public class OpenIdConnectAuthenticationMiddleware : AuthenticationMiddleware<OpenIdConnectAuthenticationOptions>
|
||||
public class OpenIdConnectMiddleware : AuthenticationMiddleware<OpenIdConnectOptions>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a <see cref="OpenIdConnectAuthenticationMiddleware"/>
|
||||
/// Initializes a <see cref="OpenIdConnectMiddleware"/>
|
||||
/// </summary>
|
||||
/// <param name="next">The next middleware in the ASP.NET pipeline to invoke.</param>
|
||||
/// <param name="dataProtectionProvider"> provider for creating a data protector.</param>
|
||||
|
|
@ -33,20 +33,20 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect
|
|||
/// <param name="encoder"></param>
|
||||
/// <param name="services"></param>
|
||||
/// <param name="sharedOptions"></param>
|
||||
/// <param name="options">a <see cref="IOptions{OpenIdConnectAuthenticationOptions}"/> instance that will supply <see cref="OpenIdConnectAuthenticationOptions"/>
|
||||
/// <param name="options">a <see cref="IOptions{OpenIdConnectOptions}"/> instance that will supply <see cref="OpenIdConnectOptions"/>
|
||||
/// if configureOptions is null.</param>
|
||||
/// <param name="configureOptions">a <see cref="ConfigureOptions{OpenIdConnectAuthenticationOptions}"/> instance that will be passed to an instance of <see cref="OpenIdConnectAuthenticationOptions"/>
|
||||
/// that is retrieved by calling <see cref="IOptions{OpenIdConnectAuthenticationOptions}.GetNamedOptions(string)"/> where string == <see cref="ConfigureOptions{OpenIdConnectAuthenticationOptions}.Name"/> provides runtime configuration.</param>
|
||||
/// <param name="configureOptions">a <see cref="ConfigureOptions{OpenIdConnectOptions}"/> instance that will be passed to an instance of <see cref="OpenIdConnectOptions"/>
|
||||
/// that is retrieved by calling <see cref="IOptions{OpenIdConnectOptions}.GetNamedOptions(string)"/> where string == <see cref="ConfigureOptions{OpenIdConnectOptions}.Name"/> provides runtime configuration.</param>
|
||||
[SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Justification = "Managed by caller")]
|
||||
public OpenIdConnectAuthenticationMiddleware(
|
||||
public OpenIdConnectMiddleware(
|
||||
[NotNull] RequestDelegate next,
|
||||
[NotNull] IDataProtectionProvider dataProtectionProvider,
|
||||
[NotNull] ILoggerFactory loggerFactory,
|
||||
[NotNull] IUrlEncoder encoder,
|
||||
[NotNull] IServiceProvider services,
|
||||
[NotNull] IOptions<SharedAuthenticationOptions> sharedOptions,
|
||||
[NotNull] IOptions<OpenIdConnectAuthenticationOptions> options,
|
||||
ConfigureOptions<OpenIdConnectAuthenticationOptions> configureOptions = null)
|
||||
[NotNull] IOptions<OpenIdConnectOptions> options,
|
||||
ConfigureOptions<OpenIdConnectOptions> configureOptions = null)
|
||||
: base(next, options, loggerFactory, encoder, configureOptions)
|
||||
{
|
||||
if (string.IsNullOrEmpty(Options.SignInScheme) && !string.IsNullOrEmpty(sharedOptions.Value.SignInScheme))
|
||||
|
|
@ -62,7 +62,7 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect
|
|||
if (Options.StateDataFormat == null)
|
||||
{
|
||||
var dataProtector = dataProtectionProvider.CreateProtector(
|
||||
typeof(OpenIdConnectAuthenticationMiddleware).FullName,
|
||||
typeof(OpenIdConnectMiddleware).FullName,
|
||||
typeof(string).FullName,
|
||||
Options.AuthenticationScheme,
|
||||
"v1");
|
||||
|
|
@ -73,7 +73,7 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect
|
|||
if (Options.StringDataFormat == null)
|
||||
{
|
||||
var dataProtector = dataProtectionProvider.CreateProtector(
|
||||
typeof(OpenIdConnectAuthenticationMiddleware).FullName,
|
||||
typeof(OpenIdConnectMiddleware).FullName,
|
||||
typeof(string).FullName,
|
||||
Options.AuthenticationScheme,
|
||||
"v1");
|
||||
|
|
@ -94,7 +94,7 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect
|
|||
|
||||
if (Options.Events == null)
|
||||
{
|
||||
Options.Events = new OpenIdConnectAuthenticationEvents();
|
||||
Options.Events = new OpenIdConnectEvents();
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(Options.TokenValidationParameters.ValidAudience) && !string.IsNullOrEmpty(Options.ClientId))
|
||||
|
|
@ -143,10 +143,10 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect
|
|||
/// <summary>
|
||||
/// Provides the <see cref="AuthenticationHandler"/> object for processing authentication-related requests.
|
||||
/// </summary>
|
||||
/// <returns>An <see cref="AuthenticationHandler"/> configured with the <see cref="OpenIdConnectAuthenticationOptions"/> supplied to the constructor.</returns>
|
||||
protected override AuthenticationHandler<OpenIdConnectAuthenticationOptions> CreateHandler()
|
||||
/// <returns>An <see cref="AuthenticationHandler"/> configured with the <see cref="OpenIdConnectOptions"/> supplied to the constructor.</returns>
|
||||
protected override AuthenticationHandler<OpenIdConnectOptions> CreateHandler()
|
||||
{
|
||||
return new OpenIdConnectAuthenticationHandler(Backchannel);
|
||||
return new OpenIdConnectHandler(Backchannel);
|
||||
}
|
||||
|
||||
private class StringSerializer : IDataSerializer<string>
|
||||
|
|
@ -17,26 +17,26 @@ using Microsoft.IdentityModel.Protocols.OpenIdConnect;
|
|||
namespace Microsoft.AspNet.Authentication.OpenIdConnect
|
||||
{
|
||||
/// <summary>
|
||||
/// Configuration options for <see cref="OpenIdConnectAuthenticationOptions"/>
|
||||
/// Configuration options for <see cref="OpenIdConnectOptions"/>
|
||||
/// </summary>
|
||||
public class OpenIdConnectAuthenticationOptions : AuthenticationOptions
|
||||
public class OpenIdConnectOptions : AuthenticationOptions
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new <see cref="OpenIdConnectAuthenticationOptions"/>
|
||||
/// Initializes a new <see cref="OpenIdConnectOptions"/>
|
||||
/// </summary>
|
||||
public OpenIdConnectAuthenticationOptions()
|
||||
: this(OpenIdConnectAuthenticationDefaults.AuthenticationScheme)
|
||||
public OpenIdConnectOptions()
|
||||
: this(OpenIdConnectDefaults.AuthenticationScheme)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new <see cref="OpenIdConnectAuthenticationOptions"/>
|
||||
/// Initializes a new <see cref="OpenIdConnectOptions"/>
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Defaults:
|
||||
/// <para>AddNonceToRequest: true.</para>
|
||||
/// <para>BackchannelTimeout: 1 minute.</para>
|
||||
/// <para>Caption: <see cref="OpenIdConnectAuthenticationDefaults.Caption"/>.</para>
|
||||
/// <para>Caption: <see cref="OpenIdConnectDefaults.Caption"/>.</para>
|
||||
/// <para>ProtocolValidator: new <see cref="OpenIdConnectProtocolValidator"/>.</para>
|
||||
/// <para>RefreshOnIssuerKeyNotFound: true</para>
|
||||
/// <para>ResponseType: <see cref="OpenIdConnectResponseTypes.CodeIdToken"/></para>
|
||||
|
|
@ -45,11 +45,11 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect
|
|||
/// <para>UseTokenLifetime: true.</para>
|
||||
/// </remarks>
|
||||
/// <param name="authenticationScheme"> will be used to when creating the <see cref="System.Security.Claims.ClaimsIdentity"/> for the AuthenticationScheme property.</param>
|
||||
[SuppressMessage("Microsoft.Globalization", "CA1303:Do not pass literals as localized parameters", MessageId = "Microsoft.Owin.Security.OpenIdConnect.OpenIdConnectAuthenticationOptions.set_Caption(System.String)", Justification = "Not a LOC field")]
|
||||
public OpenIdConnectAuthenticationOptions(string authenticationScheme)
|
||||
[SuppressMessage("Microsoft.Globalization", "CA1303:Do not pass literals as localized parameters", MessageId = "Microsoft.Owin.Security.OpenIdConnect.OpenIdConnectOptions.set_Caption(System.String)", Justification = "Not a LOC field")]
|
||||
public OpenIdConnectOptions(string authenticationScheme)
|
||||
{
|
||||
AuthenticationScheme = authenticationScheme;
|
||||
Caption = OpenIdConnectAuthenticationDefaults.Caption;
|
||||
Caption = OpenIdConnectDefaults.Caption;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -91,7 +91,7 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect
|
|||
/// An optional constrained path on which to process the authentication callback.
|
||||
/// If not provided and RedirectUri is available, this value will be generated from RedirectUri.
|
||||
/// </summary>
|
||||
/// <remarks>If you set this value, then the <see cref="OpenIdConnectAuthenticationHandler"/> will only listen for posts at this address.
|
||||
/// <remarks>If you set this value, then the <see cref="OpenIdConnectHandler"/> will only listen for posts at this address.
|
||||
/// If the IdentityProvider does not post to this address, you may end up in a 401 -> IdentityProvider -> Client -> 401 -> ...</remarks>
|
||||
public PathString CallbackPath { get; set; }
|
||||
|
||||
|
|
@ -147,9 +147,9 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect
|
|||
public bool CacheNonces { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the <see cref="IOpenIdConnectAuthenticationEvents"/> to notify when processing OpenIdConnect messages.
|
||||
/// Gets or sets the <see cref="IOpenIdConnectEvents"/> to notify when processing OpenIdConnect messages.
|
||||
/// </summary>
|
||||
public IOpenIdConnectAuthenticationEvents Events { get; set; } = new OpenIdConnectAuthenticationEvents();
|
||||
public IOpenIdConnectEvents Events { get; set; } = new OpenIdConnectEvents();
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the <see cref="OpenIdConnectProtocolValidator"/> that is used to ensure that the 'id_token' received
|
||||
|
|
@ -185,7 +185,7 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect
|
|||
/// <summary>
|
||||
/// Gets or sets the method used to redirect the user agent to the identity provider.
|
||||
/// </summary>
|
||||
public OpenIdConnectAuthenticationMethod AuthenticationMethod { get; set; }
|
||||
public OpenIdConnectRedirectBehavior AuthenticationMethod { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the 'resource'.
|
||||
|
|
@ -4,7 +4,7 @@
|
|||
/// Lists the different authentication methods used to
|
||||
/// redirect the user agent to the identity provider.
|
||||
/// </summary>
|
||||
public enum OpenIdConnectAuthenticationMethod
|
||||
public enum OpenIdConnectRedirectBehavior
|
||||
{
|
||||
/// <summary>
|
||||
/// Emits a 302 response to redirect the user agent to
|
||||
|
|
@ -13,14 +13,14 @@ namespace Microsoft.Framework.DependencyInjection
|
|||
/// </summary>
|
||||
public static class OpenIdConnectServiceCollectionExtensions
|
||||
{
|
||||
public static IServiceCollection AddOpenIdConnectAuthentication([NotNull] this IServiceCollection services, [NotNull] Action<OpenIdConnectAuthenticationOptions> configure)
|
||||
public static IServiceCollection AddOpenIdConnectAuthentication([NotNull] this IServiceCollection services, [NotNull] Action<OpenIdConnectOptions> configure)
|
||||
{
|
||||
return services.Configure(configure);
|
||||
}
|
||||
|
||||
public static IServiceCollection AddOpenIdConnectAuthentication([NotNull] this IServiceCollection services, [NotNull] IConfiguration config)
|
||||
{
|
||||
return services.Configure<OpenIdConnectAuthenticationOptions>(config);
|
||||
return services.Configure<OpenIdConnectOptions>(config);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,9 +6,9 @@ using System.Threading.Tasks;
|
|||
namespace Microsoft.AspNet.Authentication.Twitter
|
||||
{
|
||||
/// <summary>
|
||||
/// Specifies callback methods which the <see cref="TwitterAuthenticationMiddleware"></see> invokes to enable developer control over the authentication process. />
|
||||
/// Specifies callback methods which the <see cref="TwitterMiddleware"></see> invokes to enable developer control over the authentication process. />
|
||||
/// </summary>
|
||||
public interface ITwitterAuthenticationEvents
|
||||
public interface ITwitterEvents
|
||||
{
|
||||
/// <summary>
|
||||
/// Invoked whenever Twitter succesfully authenticates a user
|
||||
|
|
@ -28,6 +28,6 @@ namespace Microsoft.AspNet.Authentication.Twitter
|
|||
/// Called when a Challenge causes a redirect to authorize endpoint in the Twitter middleware
|
||||
/// </summary>
|
||||
/// <param name="context">Contains redirect URI and <see cref="AuthenticationProperties"/> of the challenge </param>
|
||||
void ApplyRedirect(TwitterApplyRedirectContext context);
|
||||
Task ApplyRedirect(TwitterApplyRedirectContext context);
|
||||
}
|
||||
}
|
||||
|
|
@ -9,7 +9,7 @@ namespace Microsoft.AspNet.Authentication.Twitter
|
|||
/// <summary>
|
||||
/// The Context passed when a Challenge causes a redirect to authorize endpoint in the Twitter middleware.
|
||||
/// </summary>
|
||||
public class TwitterApplyRedirectContext : BaseContext<TwitterAuthenticationOptions>
|
||||
public class TwitterApplyRedirectContext : BaseContext<TwitterOptions>
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new context object.
|
||||
|
|
@ -18,7 +18,7 @@ namespace Microsoft.AspNet.Authentication.Twitter
|
|||
/// <param name="options">The Twitter middleware options.</param>
|
||||
/// <param name="properties">The authentication properties of the challenge.</param>
|
||||
/// <param name="redirectUri">The initial redirect URI.</param>
|
||||
public TwitterApplyRedirectContext(HttpContext context, TwitterAuthenticationOptions options,
|
||||
public TwitterApplyRedirectContext(HttpContext context, TwitterOptions options,
|
||||
AuthenticationProperties properties, string redirectUri)
|
||||
: base(context, options)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -7,9 +7,9 @@ using System.Threading.Tasks;
|
|||
namespace Microsoft.AspNet.Authentication.Twitter
|
||||
{
|
||||
/// <summary>
|
||||
/// Default <see cref="ITwitterAuthenticationEvents"/> implementation.
|
||||
/// Default <see cref="ITwitterEvents"/> implementation.
|
||||
/// </summary>
|
||||
public class TwitterAuthenticationEvents : ITwitterAuthenticationEvents
|
||||
public class TwitterEvents : ITwitterEvents
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the function that is invoked when the Authenticated method is invoked.
|
||||
|
|
@ -24,7 +24,11 @@ namespace Microsoft.AspNet.Authentication.Twitter
|
|||
/// <summary>
|
||||
/// Gets or sets the delegate that is invoked when the ApplyRedirect method is invoked.
|
||||
/// </summary>
|
||||
public Action<TwitterApplyRedirectContext> OnApplyRedirect { get; set; } = context => context.Response.Redirect(context.RedirectUri);
|
||||
public Func<TwitterApplyRedirectContext, Task> OnApplyRedirect { get; set; } = context =>
|
||||
{
|
||||
context.Response.Redirect(context.RedirectUri);
|
||||
return Task.FromResult(0);
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Invoked whenever Twitter successfully authenticates a user
|
||||
|
|
@ -44,6 +48,6 @@ namespace Microsoft.AspNet.Authentication.Twitter
|
|||
/// Called when a Challenge causes a redirect to authorize endpoint in the Twitter middleware
|
||||
/// </summary>
|
||||
/// <param name="context">Contains redirect URI and <see cref="AuthenticationProperties"/> of the challenge </param>
|
||||
public virtual void ApplyRedirect(TwitterApplyRedirectContext context) => OnApplyRedirect(context);
|
||||
public virtual Task ApplyRedirect(TwitterApplyRedirectContext context) => OnApplyRedirect(context);
|
||||
}
|
||||
}
|
||||
|
|
@ -9,14 +9,14 @@ using Microsoft.Framework.OptionsModel;
|
|||
namespace Microsoft.AspNet.Builder
|
||||
{
|
||||
/// <summary>
|
||||
/// Extension methods for using <see cref="TwitterAuthenticationMiddleware"/>
|
||||
/// Extension methods for using <see cref="TwitterMiddleware"/>
|
||||
/// </summary>
|
||||
public static class TwitterAppBuilderExtensions
|
||||
{
|
||||
public static IApplicationBuilder UseTwitterAuthentication([NotNull] this IApplicationBuilder app, Action<TwitterAuthenticationOptions> configureOptions = null)
|
||||
public static IApplicationBuilder UseTwitterAuthentication([NotNull] this IApplicationBuilder app, Action<TwitterOptions> configureOptions = null)
|
||||
{
|
||||
return app.UseMiddleware<TwitterAuthenticationMiddleware>(
|
||||
new ConfigureOptions<TwitterAuthenticationOptions>(configureOptions ?? (o => { })));
|
||||
return app.UseMiddleware<TwitterMiddleware>(
|
||||
new ConfigureOptions<TwitterOptions>(configureOptions ?? (o => { })));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
namespace Microsoft.AspNet.Authentication.Twitter
|
||||
{
|
||||
public static class TwitterAuthenticationDefaults
|
||||
public static class TwitterDefaults
|
||||
{
|
||||
public const string AuthenticationScheme = "Twitter";
|
||||
}
|
||||
|
|
@ -20,7 +20,7 @@ using Microsoft.Framework.Primitives;
|
|||
|
||||
namespace Microsoft.AspNet.Authentication.Twitter
|
||||
{
|
||||
internal class TwitterAuthenticationHandler : AuthenticationHandler<TwitterAuthenticationOptions>
|
||||
internal class TwitterHandler : AuthenticationHandler<TwitterOptions>
|
||||
{
|
||||
private static readonly DateTime Epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
|
||||
private const string StateCookie = "__TwitterState";
|
||||
|
|
@ -30,7 +30,7 @@ namespace Microsoft.AspNet.Authentication.Twitter
|
|||
|
||||
private readonly HttpClient _httpClient;
|
||||
|
||||
public TwitterAuthenticationHandler(HttpClient httpClient)
|
||||
public TwitterHandler(HttpClient httpClient)
|
||||
{
|
||||
_httpClient = httpClient;
|
||||
}
|
||||
|
|
@ -157,7 +157,7 @@ namespace Microsoft.AspNet.Authentication.Twitter
|
|||
var redirectContext = new TwitterApplyRedirectContext(
|
||||
Context, Options,
|
||||
properties, twitterAuthenticationEndpoint);
|
||||
Options.Events.ApplyRedirect(redirectContext);
|
||||
await Options.Events.ApplyRedirect(redirectContext);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
|
|
@ -18,12 +18,12 @@ namespace Microsoft.AspNet.Authentication.Twitter
|
|||
/// ASP.NET middleware for authenticating users using Twitter
|
||||
/// </summary>
|
||||
[SuppressMessage("Microsoft.Design", "CA1001:TypesThatOwnDisposableFieldsShouldBeDisposable", Justification = "Middleware are not disposable.")]
|
||||
public class TwitterAuthenticationMiddleware : AuthenticationMiddleware<TwitterAuthenticationOptions>
|
||||
public class TwitterMiddleware : AuthenticationMiddleware<TwitterOptions>
|
||||
{
|
||||
private readonly HttpClient _httpClient;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a <see cref="TwitterAuthenticationMiddleware"/>
|
||||
/// Initializes a <see cref="TwitterMiddleware"/>
|
||||
/// </summary>
|
||||
/// <param name="next">The next middleware in the HTTP pipeline to invoke</param>
|
||||
/// <param name="dataProtectionProvider"></param>
|
||||
|
|
@ -32,14 +32,14 @@ namespace Microsoft.AspNet.Authentication.Twitter
|
|||
/// <param name="sharedOptions"></param>
|
||||
/// <param name="options">Configuration options for the middleware</param>
|
||||
/// <param name="configureOptions"></param>
|
||||
public TwitterAuthenticationMiddleware(
|
||||
public TwitterMiddleware(
|
||||
[NotNull] RequestDelegate next,
|
||||
[NotNull] IDataProtectionProvider dataProtectionProvider,
|
||||
[NotNull] ILoggerFactory loggerFactory,
|
||||
[NotNull] IUrlEncoder encoder,
|
||||
[NotNull] IOptions<SharedAuthenticationOptions> sharedOptions,
|
||||
[NotNull] IOptions<TwitterAuthenticationOptions> options,
|
||||
ConfigureOptions<TwitterAuthenticationOptions> configureOptions = null)
|
||||
[NotNull] IOptions<TwitterOptions> options,
|
||||
ConfigureOptions<TwitterOptions> configureOptions = null)
|
||||
: base(next, options, loggerFactory, encoder, configureOptions)
|
||||
{
|
||||
if (string.IsNullOrEmpty(Options.ConsumerSecret))
|
||||
|
|
@ -53,12 +53,12 @@ namespace Microsoft.AspNet.Authentication.Twitter
|
|||
|
||||
if (Options.Events == null)
|
||||
{
|
||||
Options.Events = new TwitterAuthenticationEvents();
|
||||
Options.Events = new TwitterEvents();
|
||||
}
|
||||
if (Options.StateDataFormat == null)
|
||||
{
|
||||
var dataProtector = dataProtectionProvider.CreateProtector(
|
||||
typeof(TwitterAuthenticationMiddleware).FullName, Options.AuthenticationScheme, "v1");
|
||||
typeof(TwitterMiddleware).FullName, Options.AuthenticationScheme, "v1");
|
||||
Options.StateDataFormat = new SecureDataFormat<RequestToken>(
|
||||
Serializers.RequestToken,
|
||||
dataProtector,
|
||||
|
|
@ -85,10 +85,10 @@ namespace Microsoft.AspNet.Authentication.Twitter
|
|||
/// <summary>
|
||||
/// Provides the <see cref="AuthenticationHandler"/> object for processing authentication-related requests.
|
||||
/// </summary>
|
||||
/// <returns>An <see cref="AuthenticationHandler"/> configured with the <see cref="TwitterAuthenticationOptions"/> supplied to the constructor.</returns>
|
||||
protected override AuthenticationHandler<TwitterAuthenticationOptions> CreateHandler()
|
||||
/// <returns>An <see cref="AuthenticationHandler"/> configured with the <see cref="TwitterOptions"/> supplied to the constructor.</returns>
|
||||
protected override AuthenticationHandler<TwitterOptions> CreateHandler()
|
||||
{
|
||||
return new TwitterAuthenticationHandler(_httpClient);
|
||||
return new TwitterHandler(_httpClient);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -10,14 +10,14 @@ namespace Microsoft.AspNet.Authentication.Twitter
|
|||
/// <summary>
|
||||
/// Options for the Twitter authentication middleware.
|
||||
/// </summary>
|
||||
public class TwitterAuthenticationOptions : AuthenticationOptions
|
||||
public class TwitterOptions : AuthenticationOptions
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="TwitterAuthenticationOptions"/> class.
|
||||
/// Initializes a new instance of the <see cref="TwitterOptions"/> class.
|
||||
/// </summary>
|
||||
public TwitterAuthenticationOptions()
|
||||
public TwitterOptions()
|
||||
{
|
||||
AuthenticationScheme = TwitterAuthenticationDefaults.AuthenticationScheme;
|
||||
AuthenticationScheme = TwitterDefaults.AuthenticationScheme;
|
||||
Caption = AuthenticationScheme;
|
||||
CallbackPath = new PathString("/signin-twitter");
|
||||
BackchannelTimeout = TimeSpan.FromSeconds(60);
|
||||
|
|
@ -80,9 +80,9 @@ namespace Microsoft.AspNet.Authentication.Twitter
|
|||
public ISecureDataFormat<RequestToken> StateDataFormat { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the <see cref="ITwitterAuthenticationEvents"/> used to handle authentication events.
|
||||
/// Gets or sets the <see cref="ITwitterEvents"/> used to handle authentication events.
|
||||
/// </summary>
|
||||
public ITwitterAuthenticationEvents Events { get; set; }
|
||||
public ITwitterEvents Events { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Defines whether access tokens should be stored in the
|
||||
|
|
@ -9,18 +9,18 @@ using Microsoft.Framework.Internal;
|
|||
namespace Microsoft.Framework.DependencyInjection
|
||||
{
|
||||
/// <summary>
|
||||
/// Extension methods for using <see cref="TwitterAuthenticationMiddleware"/>
|
||||
/// Extension methods for using <see cref="TwitterMiddleware"/>
|
||||
/// </summary>
|
||||
public static class TwitterAuthenticationExtensions
|
||||
{
|
||||
public static IServiceCollection AddTwitterAuthentication([NotNull] this IServiceCollection services, [NotNull] Action<TwitterAuthenticationOptions> configure)
|
||||
public static IServiceCollection AddTwitterAuthentication([NotNull] this IServiceCollection services, [NotNull] Action<TwitterOptions> configure)
|
||||
{
|
||||
return services.Configure(configure);
|
||||
}
|
||||
|
||||
public static IServiceCollection AddTwitterAuthentication([NotNull] this IServiceCollection services, [NotNull] IConfiguration config)
|
||||
{
|
||||
return services.Configure<TwitterAuthenticationOptions>(config);
|
||||
return services.Configure<TwitterOptions>(config);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,11 +9,11 @@ namespace Microsoft.AspNet.Authentication
|
|||
/// <summary>
|
||||
/// Handler that applies ClaimsTransformation to authentication
|
||||
/// </summary>
|
||||
public class ClaimsTransformationAuthenticationHandler : IAuthenticationHandler
|
||||
public class ClaimsTransformationHandler : IAuthenticationHandler
|
||||
{
|
||||
private readonly IClaimsTransformer _transform;
|
||||
|
||||
public ClaimsTransformationAuthenticationHandler(IClaimsTransformer transform)
|
||||
public ClaimsTransformationHandler(IClaimsTransformer transform)
|
||||
{
|
||||
_transform = transform;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ namespace Microsoft.AspNet.Authentication
|
|||
|
||||
public async Task Invoke(HttpContext context)
|
||||
{
|
||||
var handler = new ClaimsTransformationAuthenticationHandler(Options.Transformer);
|
||||
var handler = new ClaimsTransformationHandler(Options.Transformer);
|
||||
handler.RegisterAuthenticationHandler(context.GetAuthentication());
|
||||
try {
|
||||
if (Options.Transformer != null)
|
||||
|
|
|
|||
|
|
@ -499,6 +499,7 @@ namespace Microsoft.AspNet.Authentication.Cookies
|
|||
OnResponseSignIn = context =>
|
||||
{
|
||||
context.Properties.ExpiresUtc = clock.UtcNow.Add(TimeSpan.FromMinutes(5));
|
||||
return Task.FromResult(0);
|
||||
}
|
||||
};
|
||||
}, SignInAsAlice);
|
||||
|
|
|
|||
|
|
@ -43,11 +43,12 @@ namespace Microsoft.AspNet.Authentication.Facebook
|
|||
{
|
||||
options.AppId = "Test App Id";
|
||||
options.AppSecret = "Test App Secret";
|
||||
options.Events = new OAuthAuthenticationEvents
|
||||
options.Events = new OAuthEvents
|
||||
{
|
||||
OnApplyRedirect = context =>
|
||||
{
|
||||
context.Response.Redirect(context.RedirectUri + "&custom=test");
|
||||
return Task.FromResult(0);
|
||||
}
|
||||
};
|
||||
});
|
||||
|
|
@ -197,7 +198,7 @@ namespace Microsoft.AspNet.Authentication.Facebook
|
|||
{
|
||||
Sender = req =>
|
||||
{
|
||||
if (req.RequestUri.GetLeftPart(UriPartial.Path) == FacebookAuthenticationDefaults.TokenEndpoint)
|
||||
if (req.RequestUri.GetLeftPart(UriPartial.Path) == FacebookDefaults.TokenEndpoint)
|
||||
{
|
||||
var res = new HttpResponseMessage(HttpStatusCode.OK);
|
||||
var tokenResponse = new Dictionary<string, string>
|
||||
|
|
|
|||
|
|
@ -198,12 +198,13 @@ namespace Microsoft.AspNet.Authentication.Google
|
|||
{
|
||||
options.ClientId = "Test Id";
|
||||
options.ClientSecret = "Test Secret";
|
||||
options.Events = new OAuthAuthenticationEvents
|
||||
options.Events = new OAuthEvents
|
||||
{
|
||||
OnApplyRedirect = context =>
|
||||
{
|
||||
context.Response.Redirect(context.RedirectUri + "&custom=test");
|
||||
}
|
||||
{
|
||||
context.Response.Redirect(context.RedirectUri + "&custom=test");
|
||||
return Task.FromResult(0);
|
||||
}
|
||||
};
|
||||
});
|
||||
var transaction = await server.SendAsync("https://example.com/challenge");
|
||||
|
|
@ -294,7 +295,7 @@ namespace Microsoft.AspNet.Authentication.Google
|
|||
var authCookie = transaction.AuthenticationCookieValue;
|
||||
transaction = await server.SendAsync("https://example.com/me", authCookie);
|
||||
transaction.Response.StatusCode.ShouldBe(HttpStatusCode.OK);
|
||||
var expectedIssuer = claimsIssuer ?? GoogleAuthenticationDefaults.AuthenticationScheme;
|
||||
var expectedIssuer = claimsIssuer ?? GoogleDefaults.AuthenticationScheme;
|
||||
transaction.FindClaimValue(ClaimTypes.Name, expectedIssuer).ShouldBe("Test Name");
|
||||
transaction.FindClaimValue(ClaimTypes.NameIdentifier, expectedIssuer).ShouldBe("Test User ID");
|
||||
transaction.FindClaimValue(ClaimTypes.GivenName, expectedIssuer).ShouldBe("Test Given Name");
|
||||
|
|
@ -414,7 +415,7 @@ namespace Microsoft.AspNet.Authentication.Google
|
|||
return null;
|
||||
}
|
||||
};
|
||||
options.Events = new OAuthAuthenticationEvents
|
||||
options.Events = new OAuthEvents
|
||||
{
|
||||
OnAuthenticated = context =>
|
||||
{
|
||||
|
|
@ -455,7 +456,7 @@ namespace Microsoft.AspNet.Authentication.Google
|
|||
options.ClientSecret = "Test Secret";
|
||||
options.StateDataFormat = stateFormat;
|
||||
options.AccessType = "offline";
|
||||
options.Events = new OAuthAuthenticationEvents()
|
||||
options.Events = new OAuthEvents()
|
||||
{
|
||||
OnAuthenticated = context =>
|
||||
{
|
||||
|
|
@ -463,11 +464,11 @@ namespace Microsoft.AspNet.Authentication.Google
|
|||
Assert.Equal(context.AccessToken, "Test Access Token");
|
||||
Assert.Equal(context.RefreshToken, "Test Refresh Token");
|
||||
Assert.Equal(context.ExpiresIn, TimeSpan.FromSeconds(3600));
|
||||
Assert.Equal(GoogleAuthenticationHelper.GetEmail(context.User), "Test email");
|
||||
Assert.Equal(GoogleAuthenticationHelper.GetId(context.User), "Test User ID");
|
||||
Assert.Equal(GoogleAuthenticationHelper.GetName(context.User), "Test Name");
|
||||
Assert.Equal(GoogleAuthenticationHelper.GetFamilyName(context.User), "Test Family Name");
|
||||
Assert.Equal(GoogleAuthenticationHelper.GetGivenName(context.User), "Test Given Name");
|
||||
Assert.Equal(GoogleHelper.GetEmail(context.User), "Test email");
|
||||
Assert.Equal(GoogleHelper.GetId(context.User), "Test User ID");
|
||||
Assert.Equal(GoogleHelper.GetName(context.User), "Test Name");
|
||||
Assert.Equal(GoogleHelper.GetFamilyName(context.User), "Test Family Name");
|
||||
Assert.Equal(GoogleHelper.GetGivenName(context.User), "Test Given Name");
|
||||
return Task.FromResult(0);
|
||||
}
|
||||
};
|
||||
|
|
@ -538,7 +539,7 @@ namespace Microsoft.AspNet.Authentication.Google
|
|||
return res;
|
||||
}
|
||||
|
||||
private static TestServer CreateServer(Action<GoogleAuthenticationOptions> configureOptions, Func<HttpContext, Task> testpath = null)
|
||||
private static TestServer CreateServer(Action<GoogleOptions> configureOptions, Func<HttpContext, Task> testpath = null)
|
||||
{
|
||||
return TestServer.Create(app =>
|
||||
{
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ namespace Microsoft.AspNet.Authentication.JwtBearer
|
|||
{
|
||||
options.AutomaticAuthentication = true;
|
||||
|
||||
options.Events = new JwtBearerAuthenticationEvents()
|
||||
options.Events = new JwtBearerEvents()
|
||||
{
|
||||
OnMessageReceived = context =>
|
||||
{
|
||||
|
|
@ -117,7 +117,7 @@ namespace Microsoft.AspNet.Authentication.JwtBearer
|
|||
{
|
||||
options.AutomaticAuthentication = true;
|
||||
|
||||
options.Events = new JwtBearerAuthenticationEvents()
|
||||
options.Events = new JwtBearerEvents()
|
||||
{
|
||||
OnSecurityTokenReceived = context =>
|
||||
{
|
||||
|
|
@ -151,7 +151,7 @@ namespace Microsoft.AspNet.Authentication.JwtBearer
|
|||
{
|
||||
options.AutomaticAuthentication = true;
|
||||
|
||||
options.Events = new JwtBearerAuthenticationEvents()
|
||||
options.Events = new JwtBearerEvents()
|
||||
{
|
||||
OnSecurityTokenValidated = context =>
|
||||
{
|
||||
|
|
@ -188,7 +188,7 @@ namespace Microsoft.AspNet.Authentication.JwtBearer
|
|||
{
|
||||
options.AutomaticAuthentication = true;
|
||||
|
||||
options.Events = new JwtBearerAuthenticationEvents()
|
||||
options.Events = new JwtBearerEvents()
|
||||
{
|
||||
OnMessageReceived = context =>
|
||||
{
|
||||
|
|
@ -225,7 +225,7 @@ namespace Microsoft.AspNet.Authentication.JwtBearer
|
|||
{
|
||||
var server = CreateServer(options =>
|
||||
{
|
||||
options.Events = new JwtBearerAuthenticationEvents()
|
||||
options.Events = new JwtBearerEvents()
|
||||
{
|
||||
OnSecurityTokenReceived = context =>
|
||||
{
|
||||
|
|
@ -256,7 +256,7 @@ namespace Microsoft.AspNet.Authentication.JwtBearer
|
|||
{
|
||||
var server = CreateServer(options =>
|
||||
{
|
||||
options.Events = new JwtBearerAuthenticationEvents()
|
||||
options.Events = new JwtBearerEvents()
|
||||
{
|
||||
OnSecurityTokenReceived = context =>
|
||||
{
|
||||
|
|
@ -324,7 +324,7 @@ namespace Microsoft.AspNet.Authentication.JwtBearer
|
|||
}
|
||||
}
|
||||
|
||||
private static TestServer CreateServer(Action<JwtBearerAuthenticationOptions> configureOptions, Func<HttpContext, bool> handler = null)
|
||||
private static TestServer CreateServer(Action<JwtBearerOptions> configureOptions, Func<HttpContext, bool> handler = null)
|
||||
{
|
||||
return TestServer.Create(app =>
|
||||
{
|
||||
|
|
@ -360,17 +360,17 @@ namespace Microsoft.AspNet.Authentication.JwtBearer
|
|||
else if (context.Request.Path == new PathString("/unauthorized"))
|
||||
{
|
||||
// Simulate Authorization failure
|
||||
var result = await context.Authentication.AuthenticateAsync(JwtBearerAuthenticationDefaults.AuthenticationScheme);
|
||||
await context.Authentication.ChallengeAsync(JwtBearerAuthenticationDefaults.AuthenticationScheme);
|
||||
var result = await context.Authentication.AuthenticateAsync(JwtBearerDefaults.AuthenticationScheme);
|
||||
await context.Authentication.ChallengeAsync(JwtBearerDefaults.AuthenticationScheme);
|
||||
}
|
||||
|
||||
else if (context.Request.Path == new PathString("/signIn"))
|
||||
{
|
||||
await Assert.ThrowsAsync<NotSupportedException>(() => context.Authentication.SignInAsync(JwtBearerAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal()));
|
||||
await Assert.ThrowsAsync<NotSupportedException>(() => context.Authentication.SignInAsync(JwtBearerDefaults.AuthenticationScheme, new ClaimsPrincipal()));
|
||||
}
|
||||
else if (context.Request.Path == new PathString("/signOut"))
|
||||
{
|
||||
await Assert.ThrowsAsync<NotSupportedException>(() => context.Authentication.SignOutAsync(JwtBearerAuthenticationDefaults.AuthenticationScheme));
|
||||
await Assert.ThrowsAsync<NotSupportedException>(() => context.Authentication.SignOutAsync(JwtBearerDefaults.AuthenticationScheme));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
|
|
@ -32,11 +32,12 @@ namespace Microsoft.AspNet.Authentication.Tests.MicrosoftAccount
|
|||
{
|
||||
options.ClientId = "Test Client Id";
|
||||
options.ClientSecret = "Test Client Secret";
|
||||
options.Events = new OAuthAuthenticationEvents
|
||||
options.Events = new OAuthEvents
|
||||
{
|
||||
OnApplyRedirect = context =>
|
||||
{
|
||||
context.Response.Redirect(context.RedirectUri + "&custom=test");
|
||||
return Task.FromResult(0);
|
||||
}
|
||||
};
|
||||
});
|
||||
|
|
@ -144,7 +145,7 @@ namespace Microsoft.AspNet.Authentication.Tests.MicrosoftAccount
|
|||
return null;
|
||||
}
|
||||
};
|
||||
options.Events = new OAuthAuthenticationEvents
|
||||
options.Events = new OAuthEvents
|
||||
{
|
||||
OnAuthenticated = context =>
|
||||
{
|
||||
|
|
@ -175,7 +176,7 @@ namespace Microsoft.AspNet.Authentication.Tests.MicrosoftAccount
|
|||
transaction.FindClaimValue("RefreshToken").ShouldBe("Test Refresh Token");
|
||||
}
|
||||
|
||||
private static TestServer CreateServer(Action<MicrosoftAccountAuthenticationOptions> configureOptions)
|
||||
private static TestServer CreateServer(Action<MicrosoftAccountOptions> configureOptions)
|
||||
{
|
||||
return TestServer.Create(app =>
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
// 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.Security.Claims;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Authentication.OpenIdConnect;
|
||||
|
|
@ -15,9 +14,9 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect
|
|||
/// <summary>
|
||||
/// Allows for custom processing of ApplyResponseChallenge, ApplyResponseGrant and AuthenticateCore
|
||||
/// </summary>
|
||||
public class OpenIdConnectAuthenticationHandlerForTestingAuthenticate : OpenIdConnectAuthenticationHandler
|
||||
public class OpenIdConnectHandlerForTestingAuthenticate : OpenIdConnectHandler
|
||||
{
|
||||
public OpenIdConnectAuthenticationHandlerForTestingAuthenticate()
|
||||
public OpenIdConnectHandlerForTestingAuthenticate()
|
||||
: base(null)
|
||||
{
|
||||
}
|
||||
|
|
@ -58,20 +58,20 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect
|
|||
}
|
||||
|
||||
[Theory, MemberData("AuthenticateCoreStateDataSet")]
|
||||
public async Task AuthenticateCoreState(Action<OpenIdConnectAuthenticationOptions> action, OpenIdConnectMessage message)
|
||||
public async Task AuthenticateCoreState(Action<OpenIdConnectOptions> action, OpenIdConnectMessage message)
|
||||
{
|
||||
var handler = new OpenIdConnectAuthenticationHandlerForTestingAuthenticate();
|
||||
var server = CreateServer(new ConfigureOptions<OpenIdConnectAuthenticationOptions>(action), UrlEncoder.Default, handler);
|
||||
var handler = new OpenIdConnectHandlerForTestingAuthenticate();
|
||||
var server = CreateServer(new ConfigureOptions<OpenIdConnectOptions>(action), UrlEncoder.Default, handler);
|
||||
await server.CreateClient().PostAsync("http://localhost", new FormUrlEncodedContent(message.Parameters.Where(pair => pair.Value != null)));
|
||||
}
|
||||
|
||||
public static TheoryData<Action<OpenIdConnectAuthenticationOptions>, OpenIdConnectMessage> AuthenticateCoreStateDataSet
|
||||
public static TheoryData<Action<OpenIdConnectOptions>, OpenIdConnectMessage> AuthenticateCoreStateDataSet
|
||||
{
|
||||
get
|
||||
{
|
||||
var formater = new AuthenticationPropertiesFormaterKeyValue();
|
||||
var properties = new AuthenticationProperties();
|
||||
var dataset = new TheoryData<Action<OpenIdConnectAuthenticationOptions>, OpenIdConnectMessage>();
|
||||
var dataset = new TheoryData<Action<OpenIdConnectOptions>, OpenIdConnectMessage>();
|
||||
|
||||
// expected user state is added to the message.Parameters.Items[ExpectedStateParameter]
|
||||
// Userstate == null
|
||||
|
|
@ -86,7 +86,7 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect
|
|||
properties.Items.Clear();
|
||||
var userstate = Guid.NewGuid().ToString();
|
||||
message.Code = Guid.NewGuid().ToString();
|
||||
properties.Items.Add(OpenIdConnectAuthenticationDefaults.UserstatePropertiesKey, userstate);
|
||||
properties.Items.Add(OpenIdConnectDefaults.UserstatePropertiesKey, userstate);
|
||||
message.State = UrlEncoder.Default.UrlEncode(formater.Protect(properties));
|
||||
message.Parameters.Add(ExpectedStateParameter, userstate);
|
||||
dataset.Add(SetStateOptions, message);
|
||||
|
|
@ -96,13 +96,13 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect
|
|||
|
||||
// Setup an event to check for expected state.
|
||||
// The state gets set by the runtime after the 'MessageReceivedContext'
|
||||
private static void SetStateOptions(OpenIdConnectAuthenticationOptions options)
|
||||
private static void SetStateOptions(OpenIdConnectOptions options)
|
||||
{
|
||||
options.AuthenticationScheme = "OpenIdConnectHandlerTest";
|
||||
options.ConfigurationManager = TestUtilities.DefaultOpenIdConnectConfigurationManager;
|
||||
options.ClientId = Guid.NewGuid().ToString();
|
||||
options.StateDataFormat = new AuthenticationPropertiesFormaterKeyValue();
|
||||
options.Events = new OpenIdConnectAuthenticationEvents()
|
||||
options.Events = new OpenIdConnectEvents()
|
||||
{
|
||||
OnAuthorizationCodeRedeemed = context =>
|
||||
{
|
||||
|
|
@ -121,7 +121,7 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect
|
|||
|
||||
#region Configure Options for AuthenticateCore variations
|
||||
|
||||
private static void DefaultOptions(OpenIdConnectAuthenticationOptions options)
|
||||
private static void DefaultOptions(OpenIdConnectOptions options)
|
||||
{
|
||||
options.AuthenticationScheme = "OpenIdConnectHandlerTest";
|
||||
options.SignInScheme = "OpenIdConnectHandlerTest";
|
||||
|
|
@ -130,12 +130,12 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect
|
|||
options.StateDataFormat = new AuthenticationPropertiesFormaterKeyValue();
|
||||
}
|
||||
|
||||
private static void AuthorizationCodeReceivedHandledOptions(OpenIdConnectAuthenticationOptions options)
|
||||
private static void AuthorizationCodeReceivedHandledOptions(OpenIdConnectOptions options)
|
||||
{
|
||||
DefaultOptions(options);
|
||||
options.SecurityTokenValidator = MockSecurityTokenValidator();
|
||||
options.ProtocolValidator = MockProtocolValidator();
|
||||
options.Events = new OpenIdConnectAuthenticationEvents()
|
||||
options.Events = new OpenIdConnectEvents()
|
||||
{
|
||||
OnAuthorizationCodeReceived = (context) =>
|
||||
{
|
||||
|
|
@ -145,12 +145,12 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect
|
|||
};
|
||||
}
|
||||
|
||||
private static void AuthorizationCodeReceivedSkippedOptions(OpenIdConnectAuthenticationOptions options)
|
||||
private static void AuthorizationCodeReceivedSkippedOptions(OpenIdConnectOptions options)
|
||||
{
|
||||
DefaultOptions(options);
|
||||
options.SecurityTokenValidator = MockSecurityTokenValidator();
|
||||
options.ProtocolValidator = MockProtocolValidator();
|
||||
options.Events = new OpenIdConnectAuthenticationEvents()
|
||||
options.Events = new OpenIdConnectEvents()
|
||||
{
|
||||
OnAuthorizationCodeReceived = (context) =>
|
||||
{
|
||||
|
|
@ -160,12 +160,12 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect
|
|||
};
|
||||
}
|
||||
|
||||
private static void AuthenticationErrorHandledOptions(OpenIdConnectAuthenticationOptions options)
|
||||
private static void AuthenticationErrorHandledOptions(OpenIdConnectOptions options)
|
||||
{
|
||||
DefaultOptions(options);
|
||||
options.SecurityTokenValidator = MockSecurityTokenValidator();
|
||||
options.ProtocolValidator = MockProtocolValidator();
|
||||
options.Events = new OpenIdConnectAuthenticationEvents()
|
||||
options.Events = new OpenIdConnectEvents()
|
||||
{
|
||||
OnAuthenticationFailed = (context) =>
|
||||
{
|
||||
|
|
@ -175,12 +175,12 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect
|
|||
};
|
||||
}
|
||||
|
||||
private static void AuthenticationErrorSkippedOptions(OpenIdConnectAuthenticationOptions options)
|
||||
private static void AuthenticationErrorSkippedOptions(OpenIdConnectOptions options)
|
||||
{
|
||||
DefaultOptions(options);
|
||||
options.SecurityTokenValidator = MockSecurityTokenValidator();
|
||||
options.ProtocolValidator = MockProtocolValidator();
|
||||
options.Events = new OpenIdConnectAuthenticationEvents()
|
||||
options.Events = new OpenIdConnectEvents()
|
||||
{
|
||||
OnAuthenticationFailed = (context) =>
|
||||
{
|
||||
|
|
@ -190,10 +190,10 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect
|
|||
};
|
||||
}
|
||||
|
||||
private static void MessageReceivedHandledOptions(OpenIdConnectAuthenticationOptions options)
|
||||
private static void MessageReceivedHandledOptions(OpenIdConnectOptions options)
|
||||
{
|
||||
DefaultOptions(options);
|
||||
options.Events = new OpenIdConnectAuthenticationEvents()
|
||||
options.Events = new OpenIdConnectEvents()
|
||||
{
|
||||
OnMessageReceived = (context) =>
|
||||
{
|
||||
|
|
@ -203,12 +203,12 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect
|
|||
};
|
||||
}
|
||||
|
||||
private static void CodeReceivedAndRedeemedHandledOptions(OpenIdConnectAuthenticationOptions options)
|
||||
private static void CodeReceivedAndRedeemedHandledOptions(OpenIdConnectOptions options)
|
||||
{
|
||||
DefaultOptions(options);
|
||||
options.ResponseType = OpenIdConnectResponseTypes.Code;
|
||||
options.StateDataFormat = new AuthenticationPropertiesFormaterKeyValue();
|
||||
options.Events = new OpenIdConnectAuthenticationEvents()
|
||||
options.Events = new OpenIdConnectEvents()
|
||||
{
|
||||
OnAuthorizationCodeRedeemed = (context) =>
|
||||
{
|
||||
|
|
@ -218,12 +218,12 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect
|
|||
};
|
||||
}
|
||||
|
||||
private static void CodeReceivedAndRedeemedSkippedOptions(OpenIdConnectAuthenticationOptions options)
|
||||
private static void CodeReceivedAndRedeemedSkippedOptions(OpenIdConnectOptions options)
|
||||
{
|
||||
DefaultOptions(options);
|
||||
options.ResponseType = OpenIdConnectResponseTypes.Code;
|
||||
options.StateDataFormat = new AuthenticationPropertiesFormaterKeyValue();
|
||||
options.Events = new OpenIdConnectAuthenticationEvents()
|
||||
options.Events = new OpenIdConnectEvents()
|
||||
{
|
||||
OnAuthorizationCodeRedeemed = (context) =>
|
||||
{
|
||||
|
|
@ -233,7 +233,7 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect
|
|||
};
|
||||
}
|
||||
|
||||
private static void GetUserInfoFromUIEndpoint(OpenIdConnectAuthenticationOptions options)
|
||||
private static void GetUserInfoFromUIEndpoint(OpenIdConnectOptions options)
|
||||
{
|
||||
DefaultOptions(options);
|
||||
options.ResponseType = OpenIdConnectResponseTypes.Code;
|
||||
|
|
@ -241,7 +241,7 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect
|
|||
options.StateDataFormat = new AuthenticationPropertiesFormaterKeyValue();
|
||||
options.GetClaimsFromUserInfoEndpoint = true;
|
||||
options.SecurityTokenValidator = MockSecurityTokenValidator();
|
||||
options.Events = new OpenIdConnectAuthenticationEvents()
|
||||
options.Events = new OpenIdConnectEvents()
|
||||
{
|
||||
OnSecurityTokenValidated = (context) =>
|
||||
{
|
||||
|
|
@ -252,10 +252,10 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect
|
|||
}
|
||||
};
|
||||
}
|
||||
private static void MessageReceivedSkippedOptions(OpenIdConnectAuthenticationOptions options)
|
||||
private static void MessageReceivedSkippedOptions(OpenIdConnectOptions options)
|
||||
{
|
||||
DefaultOptions(options);
|
||||
options.Events = new OpenIdConnectAuthenticationEvents()
|
||||
options.Events = new OpenIdConnectEvents()
|
||||
{
|
||||
OnMessageReceived = (context) =>
|
||||
{
|
||||
|
|
@ -265,15 +265,15 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect
|
|||
};
|
||||
}
|
||||
|
||||
private static void MessageWithErrorOptions(OpenIdConnectAuthenticationOptions options)
|
||||
private static void MessageWithErrorOptions(OpenIdConnectOptions options)
|
||||
{
|
||||
AuthenticationErrorHandledOptions(options);
|
||||
}
|
||||
|
||||
private static void SecurityTokenReceivedHandledOptions(OpenIdConnectAuthenticationOptions options)
|
||||
private static void SecurityTokenReceivedHandledOptions(OpenIdConnectOptions options)
|
||||
{
|
||||
DefaultOptions(options);
|
||||
options.Events = new OpenIdConnectAuthenticationEvents()
|
||||
options.Events = new OpenIdConnectEvents()
|
||||
{
|
||||
OnSecurityTokenReceived = (context) =>
|
||||
{
|
||||
|
|
@ -283,10 +283,10 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect
|
|||
};
|
||||
}
|
||||
|
||||
private static void SecurityTokenReceivedSkippedOptions(OpenIdConnectAuthenticationOptions options)
|
||||
private static void SecurityTokenReceivedSkippedOptions(OpenIdConnectOptions options)
|
||||
{
|
||||
DefaultOptions(options);
|
||||
options.Events = new OpenIdConnectAuthenticationEvents()
|
||||
options.Events = new OpenIdConnectEvents()
|
||||
{
|
||||
OnSecurityTokenReceived = (context) =>
|
||||
{
|
||||
|
|
@ -311,7 +311,7 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect
|
|||
return mockProtocolValidator.Object;
|
||||
}
|
||||
|
||||
private static void SecurityTokenValidatorCannotReadToken(OpenIdConnectAuthenticationOptions options)
|
||||
private static void SecurityTokenValidatorCannotReadToken(OpenIdConnectOptions options)
|
||||
{
|
||||
AuthenticationErrorHandledOptions(options);
|
||||
var mockValidator = new Mock<ISecurityTokenValidator>();
|
||||
|
|
@ -321,7 +321,7 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect
|
|||
options.SecurityTokenValidator = mockValidator.Object;
|
||||
}
|
||||
|
||||
private static void SecurityTokenValidatorThrows(OpenIdConnectAuthenticationOptions options)
|
||||
private static void SecurityTokenValidatorThrows(OpenIdConnectOptions options)
|
||||
{
|
||||
AuthenticationErrorHandledOptions(options);
|
||||
var mockValidator = new Mock<ISecurityTokenValidator>();
|
||||
|
|
@ -331,7 +331,7 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect
|
|||
options.SecurityTokenValidator = mockValidator.Object;
|
||||
}
|
||||
|
||||
private static void SecurityTokenValidatorValidatesAllTokens(OpenIdConnectAuthenticationOptions options)
|
||||
private static void SecurityTokenValidatorValidatesAllTokens(OpenIdConnectOptions options)
|
||||
{
|
||||
DefaultOptions(options);
|
||||
options.SecurityTokenValidator = MockSecurityTokenValidator();
|
||||
|
|
@ -339,10 +339,10 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect
|
|||
options.ProtocolValidator.RequireNonce = false;
|
||||
}
|
||||
|
||||
private static void SecurityTokenValidatedHandledOptions(OpenIdConnectAuthenticationOptions options)
|
||||
private static void SecurityTokenValidatedHandledOptions(OpenIdConnectOptions options)
|
||||
{
|
||||
SecurityTokenValidatorValidatesAllTokens(options);
|
||||
options.Events = new OpenIdConnectAuthenticationEvents()
|
||||
options.Events = new OpenIdConnectEvents()
|
||||
{
|
||||
OnSecurityTokenValidated = (context) =>
|
||||
{
|
||||
|
|
@ -352,10 +352,10 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect
|
|||
};
|
||||
}
|
||||
|
||||
private static void SecurityTokenValidatedSkippedOptions(OpenIdConnectAuthenticationOptions options)
|
||||
private static void SecurityTokenValidatedSkippedOptions(OpenIdConnectOptions options)
|
||||
{
|
||||
SecurityTokenValidatorValidatesAllTokens(options);
|
||||
options.Events = new OpenIdConnectAuthenticationEvents()
|
||||
options.Events = new OpenIdConnectEvents()
|
||||
{
|
||||
OnSecurityTokenValidated = (context) =>
|
||||
{
|
||||
|
|
@ -365,17 +365,17 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect
|
|||
};
|
||||
}
|
||||
|
||||
private static void StateNullOptions(OpenIdConnectAuthenticationOptions options)
|
||||
private static void StateNullOptions(OpenIdConnectOptions options)
|
||||
{
|
||||
DefaultOptions(options);
|
||||
}
|
||||
|
||||
private static void StateEmptyOptions(OpenIdConnectAuthenticationOptions options)
|
||||
private static void StateEmptyOptions(OpenIdConnectOptions options)
|
||||
{
|
||||
DefaultOptions(options);
|
||||
}
|
||||
|
||||
private static void StateInvalidOptions(OpenIdConnectAuthenticationOptions options)
|
||||
private static void StateInvalidOptions(OpenIdConnectOptions options)
|
||||
{
|
||||
DefaultOptions(options);
|
||||
}
|
||||
|
|
@ -384,12 +384,12 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect
|
|||
|
||||
private static Task EmptyTask() { return Task.FromResult(0); }
|
||||
|
||||
private static TestServer CreateServer(ConfigureOptions<OpenIdConnectAuthenticationOptions> options, IUrlEncoder encoder, OpenIdConnectAuthenticationHandler handler = null)
|
||||
private static TestServer CreateServer(ConfigureOptions<OpenIdConnectOptions> options, IUrlEncoder encoder, OpenIdConnectHandler handler = null)
|
||||
{
|
||||
return TestServer.Create(
|
||||
app =>
|
||||
{
|
||||
app.UseMiddleware<OpenIdConnectAuthenticationMiddlewareForTestingAuthenticate>(options, encoder, handler);
|
||||
app.UseMiddleware<OpenIdConnectMiddlewareForTestingAuthenticate>(options, encoder, handler);
|
||||
app.Use(async (context, next) =>
|
||||
{
|
||||
await next();
|
||||
|
|
@ -403,12 +403,12 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect
|
|||
);
|
||||
}
|
||||
|
||||
private static TestServer CreateServer(ConfigureOptions<OpenIdConnectAuthenticationOptions> configureOptions, IUrlEncoder encoder, ILoggerFactory loggerFactory, OpenIdConnectAuthenticationHandler handler = null)
|
||||
private static TestServer CreateServer(ConfigureOptions<OpenIdConnectOptions> configureOptions, IUrlEncoder encoder, ILoggerFactory loggerFactory, OpenIdConnectHandler handler = null)
|
||||
{
|
||||
return TestServer.Create(
|
||||
app =>
|
||||
{
|
||||
app.UseMiddleware<OpenIdConnectAuthenticationMiddlewareForTestingAuthenticate>(configureOptions, encoder, loggerFactory, handler);
|
||||
app.UseMiddleware<OpenIdConnectMiddlewareForTestingAuthenticate>(configureOptions, encoder, loggerFactory, handler);
|
||||
app.Use(async (context, next) =>
|
||||
{
|
||||
await next();
|
||||
|
|
|
|||
|
|
@ -13,23 +13,23 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect
|
|||
{
|
||||
|
||||
/// <summary>
|
||||
/// pass a <see cref="OpenIdConnectAuthenticationHandler"/> as the AuthenticationHandler
|
||||
/// pass a <see cref="OpenIdConnectHandler"/> as the AuthenticationHandler
|
||||
/// configured to handle certain messages.
|
||||
/// </summary>
|
||||
public class OpenIdConnectAuthenticationMiddlewareForTestingAuthenticate : OpenIdConnectAuthenticationMiddleware
|
||||
public class OpenIdConnectMiddlewareForTestingAuthenticate : OpenIdConnectMiddleware
|
||||
{
|
||||
OpenIdConnectAuthenticationHandler _handler;
|
||||
OpenIdConnectHandler _handler;
|
||||
|
||||
public OpenIdConnectAuthenticationMiddlewareForTestingAuthenticate(
|
||||
public OpenIdConnectMiddlewareForTestingAuthenticate(
|
||||
RequestDelegate next,
|
||||
IDataProtectionProvider dataProtectionProvider,
|
||||
ILoggerFactory loggerFactory,
|
||||
IUrlEncoder encoder,
|
||||
IServiceProvider services,
|
||||
IOptions<SharedAuthenticationOptions> sharedOptions,
|
||||
IOptions<OpenIdConnectAuthenticationOptions> options,
|
||||
ConfigureOptions<OpenIdConnectAuthenticationOptions> configureOptions = null,
|
||||
OpenIdConnectAuthenticationHandler handler = null
|
||||
IOptions<OpenIdConnectOptions> options,
|
||||
ConfigureOptions<OpenIdConnectOptions> configureOptions = null,
|
||||
OpenIdConnectHandler handler = null
|
||||
)
|
||||
: base(next, dataProtectionProvider, loggerFactory, encoder, services, sharedOptions, options, configureOptions)
|
||||
{
|
||||
|
|
@ -39,7 +39,7 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect
|
|||
Logger = customFactory.Logger;
|
||||
}
|
||||
|
||||
protected override AuthenticationHandler<OpenIdConnectAuthenticationOptions> CreateHandler()
|
||||
protected override AuthenticationHandler<OpenIdConnectOptions> CreateHandler()
|
||||
{
|
||||
return _handler ?? base.CreateHandler();
|
||||
}
|
||||
|
|
@ -48,7 +48,7 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect
|
|||
options.Authority = DefaultAuthority;
|
||||
options.ClientId = "Test Id";
|
||||
options.Configuration = TestUtilities.DefaultOpenIdConnectConfiguration;
|
||||
options.AuthenticationMethod = OpenIdConnectAuthenticationMethod.FormPost;
|
||||
options.AuthenticationMethod = OpenIdConnectRedirectBehavior.FormPost;
|
||||
});
|
||||
var transaction = await SendAsync(server, DefaultHost + Challenge);
|
||||
transaction.Response.StatusCode.ShouldBe(HttpStatusCode.OK);
|
||||
|
|
@ -61,7 +61,7 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect
|
|||
{
|
||||
var stateDataFormat = new AuthenticationPropertiesFormaterKeyValue();
|
||||
var queryValues = ExpectedQueryValues.Defaults(DefaultAuthority);
|
||||
queryValues.State = OpenIdConnectAuthenticationDefaults.AuthenticationPropertiesKey + "=" + stateDataFormat.Protect(new AuthenticationProperties());
|
||||
queryValues.State = OpenIdConnectDefaults.AuthenticationPropertiesKey + "=" + stateDataFormat.Protect(new AuthenticationProperties());
|
||||
var server = CreateServer(options =>
|
||||
{
|
||||
SetOptions(options, DefaultParameters(), queryValues);
|
||||
|
|
@ -84,11 +84,11 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect
|
|||
var transaction = await SendAsync(server, DefaultHost + Challenge);
|
||||
|
||||
var firstCookie = transaction.SetCookie.First();
|
||||
firstCookie.ShouldContain(OpenIdConnectAuthenticationDefaults.CookieNoncePrefix);
|
||||
firstCookie.ShouldContain(OpenIdConnectDefaults.CookieNoncePrefix);
|
||||
firstCookie.ShouldContain("Expires");
|
||||
|
||||
var secondCookie = transaction.SetCookie.Skip(1).First();
|
||||
secondCookie.ShouldContain(OpenIdConnectAuthenticationDefaults.CookieStatePrefix);
|
||||
secondCookie.ShouldContain(OpenIdConnectDefaults.CookieStatePrefix);
|
||||
secondCookie.ShouldContain("Expires");
|
||||
}
|
||||
|
||||
|
|
@ -131,13 +131,13 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect
|
|||
queryValues.CheckValues(transaction.Response.Headers.Location.AbsoluteUri, new string[] {});
|
||||
}
|
||||
|
||||
private static void SetProtocolMessageOptions(OpenIdConnectAuthenticationOptions options)
|
||||
private static void SetProtocolMessageOptions(OpenIdConnectOptions options)
|
||||
{
|
||||
var mockOpenIdConnectMessage = new Mock<OpenIdConnectMessage>();
|
||||
mockOpenIdConnectMessage.Setup(m => m.CreateAuthenticationRequestUrl()).Returns(ExpectedAuthorizeRequest);
|
||||
mockOpenIdConnectMessage.Setup(m => m.CreateLogoutRequestUrl()).Returns(ExpectedLogoutRequest);
|
||||
options.AutomaticAuthentication = true;
|
||||
options.Events = new OpenIdConnectAuthenticationEvents()
|
||||
options.Events = new OpenIdConnectEvents()
|
||||
{
|
||||
OnRedirectToIdentityProvider = (context) =>
|
||||
{
|
||||
|
|
@ -169,7 +169,7 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect
|
|||
{
|
||||
SetOptions(options, DefaultParameters(new string[] { OpenIdConnectParameterNames.State }), queryValues, stateDataFormat);
|
||||
options.AutomaticAuthentication = challenge.Equals(ChallengeWithOutContext);
|
||||
options.Events = new OpenIdConnectAuthenticationEvents()
|
||||
options.Events = new OpenIdConnectEvents()
|
||||
{
|
||||
OnRedirectToIdentityProvider = context =>
|
||||
{
|
||||
|
|
@ -187,9 +187,9 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect
|
|||
{
|
||||
if (userState != null)
|
||||
{
|
||||
properties.Items.Add(OpenIdConnectAuthenticationDefaults.UserstatePropertiesKey, userState);
|
||||
properties.Items.Add(OpenIdConnectDefaults.UserstatePropertiesKey, userState);
|
||||
}
|
||||
properties.Items.Add(OpenIdConnectAuthenticationDefaults.RedirectUriForCodePropertiesKey, queryValues.RedirectUri);
|
||||
properties.Items.Add(OpenIdConnectDefaults.RedirectUriForCodePropertiesKey, queryValues.RedirectUri);
|
||||
}
|
||||
|
||||
queryValues.State = stateDataFormat.Protect(properties);
|
||||
|
|
@ -220,7 +220,7 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect
|
|||
var server = CreateServer(options =>
|
||||
{
|
||||
SetOptions(options, DefaultParameters(), queryValues);
|
||||
options.Events = new OpenIdConnectAuthenticationEvents()
|
||||
options.Events = new OpenIdConnectEvents()
|
||||
{
|
||||
OnRedirectToIdentityProvider = context =>
|
||||
{
|
||||
|
|
@ -238,7 +238,7 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect
|
|||
queryValuesSetInEvent.CheckValues(transaction.Response.Headers.Location.AbsoluteUri, DefaultParameters());
|
||||
}
|
||||
|
||||
private void SetOptions(OpenIdConnectAuthenticationOptions options, List<string> parameters, ExpectedQueryValues queryValues, ISecureDataFormat<AuthenticationProperties> secureDataFormat = null)
|
||||
private void SetOptions(OpenIdConnectOptions options, List<string> parameters, ExpectedQueryValues queryValues, ISecureDataFormat<AuthenticationProperties> secureDataFormat = null)
|
||||
{
|
||||
foreach (var param in parameters)
|
||||
{
|
||||
|
|
@ -280,7 +280,7 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect
|
|||
return parameters;
|
||||
}
|
||||
|
||||
private static void DefaultChallengeOptions(OpenIdConnectAuthenticationOptions options)
|
||||
private static void DefaultChallengeOptions(OpenIdConnectOptions options)
|
||||
{
|
||||
options.AuthenticationScheme = "OpenIdConnectHandlerTest";
|
||||
options.AutomaticAuthentication = true;
|
||||
|
|
@ -339,13 +339,13 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect
|
|||
transaction.Response.Headers.Location.AbsoluteUri.ShouldContain(UrlEncoder.Default.UrlEncode("http://www.example.com/specific_redirect_uri"));
|
||||
}
|
||||
|
||||
private static TestServer CreateServer(Action<OpenIdConnectAuthenticationOptions> configureOptions, Func<HttpContext, Task> handler = null, AuthenticationProperties properties = null)
|
||||
private static TestServer CreateServer(Action<OpenIdConnectOptions> configureOptions, Func<HttpContext, Task> handler = null, AuthenticationProperties properties = null)
|
||||
{
|
||||
return TestServer.Create(app =>
|
||||
{
|
||||
app.UseCookieAuthentication(options =>
|
||||
{
|
||||
options.AuthenticationScheme = OpenIdConnectAuthenticationDefaults.AuthenticationScheme;
|
||||
options.AuthenticationScheme = OpenIdConnectDefaults.AuthenticationScheme;
|
||||
});
|
||||
app.UseOpenIdConnectAuthentication(configureOptions);
|
||||
app.Use(async (context, next) =>
|
||||
|
|
@ -355,11 +355,11 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect
|
|||
|
||||
if (req.Path == new PathString(Challenge))
|
||||
{
|
||||
await context.Authentication.ChallengeAsync(OpenIdConnectAuthenticationDefaults.AuthenticationScheme);
|
||||
await context.Authentication.ChallengeAsync(OpenIdConnectDefaults.AuthenticationScheme);
|
||||
}
|
||||
else if (req.Path == new PathString(ChallengeWithProperties))
|
||||
{
|
||||
await context.Authentication.ChallengeAsync(OpenIdConnectAuthenticationDefaults.AuthenticationScheme, properties);
|
||||
await context.Authentication.ChallengeAsync(OpenIdConnectDefaults.AuthenticationScheme, properties);
|
||||
}
|
||||
else if (req.Path == new PathString(ChallengeWithOutContext))
|
||||
{
|
||||
|
|
@ -368,16 +368,16 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect
|
|||
else if (req.Path == new PathString(Signin))
|
||||
{
|
||||
// REVIEW: this used to just be res.SignIn()
|
||||
await context.Authentication.SignInAsync(OpenIdConnectAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal());
|
||||
await context.Authentication.SignInAsync(OpenIdConnectDefaults.AuthenticationScheme, new ClaimsPrincipal());
|
||||
}
|
||||
else if (req.Path == new PathString(Signout))
|
||||
{
|
||||
await context.Authentication.SignOutAsync(OpenIdConnectAuthenticationDefaults.AuthenticationScheme);
|
||||
await context.Authentication.SignOutAsync(OpenIdConnectDefaults.AuthenticationScheme);
|
||||
}
|
||||
else if (req.Path == new PathString("/signout_with_specific_redirect_uri"))
|
||||
{
|
||||
await context.Authentication.SignOutAsync(
|
||||
OpenIdConnectAuthenticationDefaults.AuthenticationScheme,
|
||||
OpenIdConnectDefaults.AuthenticationScheme,
|
||||
new AuthenticationProperties() { RedirectUri = "http://www.example.com/specific_redirect_uri" });
|
||||
}
|
||||
else if (handler != null)
|
||||
|
|
|
|||
|
|
@ -24,11 +24,12 @@ namespace Microsoft.AspNet.Authentication.Twitter
|
|||
{
|
||||
options.ConsumerKey = "Test Consumer Key";
|
||||
options.ConsumerSecret = "Test Consumer Secret";
|
||||
options.Events = new TwitterAuthenticationEvents
|
||||
options.Events = new TwitterEvents
|
||||
{
|
||||
OnApplyRedirect = context =>
|
||||
{
|
||||
context.Response.Redirect(context.RedirectUri + "&custom=test");
|
||||
return Task.FromResult(0);
|
||||
}
|
||||
};
|
||||
options.BackchannelHttpHandler = new TestHttpMessageHandler
|
||||
|
|
@ -135,7 +136,7 @@ namespace Microsoft.AspNet.Authentication.Twitter
|
|||
location.ShouldContain("https://twitter.com/oauth/authenticate?oauth_token=");
|
||||
}
|
||||
|
||||
private static TestServer CreateServer(Action<TwitterAuthenticationOptions> configure, Func<HttpContext, bool> handler = null)
|
||||
private static TestServer CreateServer(Action<TwitterOptions> configure, Func<HttpContext, bool> handler = null)
|
||||
{
|
||||
return TestServer.Create(app =>
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue