diff --git a/samples/OpenIdConnectSample/Startup.cs b/samples/OpenIdConnectSample/Startup.cs index 4c8e2f684b..bd1f45d4c3 100644 --- a/samples/OpenIdConnectSample/Startup.cs +++ b/samples/OpenIdConnectSample/Startup.cs @@ -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"); diff --git a/samples/SocialSample/Startup.cs b/samples/SocialSample/Startup.cs index cfd60dd0f5..f47aea5bbf 100644 --- a/samples/SocialSample/Startup.cs +++ b/samples/SocialSample/Startup.cs @@ -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 => { diff --git a/src/Microsoft.AspNet.Authentication.Cookies/CookieAppBuilderExtensions.cs b/src/Microsoft.AspNet.Authentication.Cookies/CookieAppBuilderExtensions.cs index 5a79654253..e8b56f4bce 100644 --- a/src/Microsoft.AspNet.Authentication.Cookies/CookieAppBuilderExtensions.cs +++ b/src/Microsoft.AspNet.Authentication.Cookies/CookieAppBuilderExtensions.cs @@ -38,6 +38,5 @@ namespace Microsoft.AspNet.Builder return app.UseMiddleware(options, new ConfigureOptions(o => { })); } - } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Authentication.Cookies/CookieAuthenticationHandler.cs b/src/Microsoft.AspNet.Authentication.Cookies/CookieAuthenticationHandler.cs index 95c4bec019..24fe12fbe8 100644 --- a/src/Microsoft.AspNet.Authentication.Cookies/CookieAuthenticationHandler.cs +++ b/src/Microsoft.AspNet.Authentication.Cookies/CookieAuthenticationHandler.cs @@ -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 HandleForbiddenAsync(ChallengeContext context) + protected async override Task 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 HandleUnauthorizedAsync([NotNull] ChallengeContext context) + protected override async Task 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; } } } diff --git a/src/Microsoft.AspNet.Authentication.Cookies/Events/CookieAuthenticationEvents.cs b/src/Microsoft.AspNet.Authentication.Cookies/Events/CookieAuthenticationEvents.cs index 6c65bb857d..7a96ce99d0 100644 --- a/src/Microsoft.AspNet.Authentication.Cookies/Events/CookieAuthenticationEvents.cs +++ b/src/Microsoft.AspNet.Authentication.Cookies/Events/CookieAuthenticationEvents.cs @@ -21,27 +21,31 @@ namespace Microsoft.AspNet.Authentication.Cookies /// /// A delegate assigned to this property will be invoked when the related method is called /// - public Action OnResponseSignIn { get; set; } = context => { }; + public Func OnResponseSignIn { get; set; } = context => Task.FromResult(0); /// /// A delegate assigned to this property will be invoked when the related method is called /// - public Action OnResponseSignedIn { get; set; } = context => { }; + public Func OnResponseSignedIn { get; set; } = context => Task.FromResult(0); /// /// A delegate assigned to this property will be invoked when the related method is called /// - public Action OnResponseSignOut { get; set; } = context => { }; + public Func OnResponseSignOut { get; set; } = context => Task.FromResult(0); /// /// A delegate assigned to this property will be invoked when the related method is called /// - public Action OnApplyRedirect { get; set; } = context => context.Response.Redirect(context.RedirectUri); + public Func OnApplyRedirect { get; set; } = context => + { + context.Response.Redirect(context.RedirectUri); + return Task.FromResult(0); + }; /// /// A delegate assigned to this property will be invoked when the related method is called /// - public Action OnException { get; set; } = context => { }; + public Func OnException { get; set; } = context => Task.FromResult(0); /// /// 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 /// /// - public virtual void ResponseSignIn(CookieResponseSignInContext context) => OnResponseSignIn(context); + public virtual Task ResponseSignIn(CookieResponseSignInContext context) => OnResponseSignIn(context); /// /// Implements the interface method by invoking the related delegate method /// /// - public virtual void ResponseSignedIn(CookieResponseSignedInContext context) => OnResponseSignedIn(context); + public virtual Task ResponseSignedIn(CookieResponseSignedInContext context) => OnResponseSignedIn(context); /// /// Implements the interface method by invoking the related delegate method /// /// - public virtual void ResponseSignOut(CookieResponseSignOutContext context) => OnResponseSignOut(context); + public virtual Task ResponseSignOut(CookieResponseSignOutContext context) => OnResponseSignOut(context); /// /// Implements the interface method by invoking the related delegate method /// /// Contains information about the event - public virtual void ApplyRedirect(CookieApplyRedirectContext context) => OnApplyRedirect(context); + public virtual Task ApplyRedirect(CookieApplyRedirectContext context) => OnApplyRedirect(context); /// /// Implements the interface method by invoking the related delegate method /// /// Contains information about the event - public virtual void Exception(CookieExceptionContext context) => OnException(context); + public virtual Task Exception(CookieExceptionContext context) => OnException(context); } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Authentication.Cookies/Events/ICookieAuthenticationEvents.cs b/src/Microsoft.AspNet.Authentication.Cookies/Events/ICookieAuthenticationEvents.cs index b4caf0b556..fef97c6916 100644 --- a/src/Microsoft.AspNet.Authentication.Cookies/Events/ICookieAuthenticationEvents.cs +++ b/src/Microsoft.AspNet.Authentication.Cookies/Events/ICookieAuthenticationEvents.cs @@ -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. /// /// Contains information about the login session as well as the user . - void ResponseSignIn(CookieResponseSignInContext context); + Task ResponseSignIn(CookieResponseSignInContext context); /// /// Called when an endpoint has provided sign in information after it is converted into a cookie. /// /// Contains information about the login session as well as the user . - void ResponseSignedIn(CookieResponseSignedInContext context); + Task ResponseSignedIn(CookieResponseSignedInContext context); /// /// Called when a Challenge, SignIn, or SignOut causes a redirect in the cookie middleware /// /// Contains information about the event - void ApplyRedirect(CookieApplyRedirectContext context); + Task ApplyRedirect(CookieApplyRedirectContext context); /// /// Called during the sign-out flow to augment the cookie cleanup process. /// /// Contains information about the login session as well as information about the authentication cookie. - void ResponseSignOut(CookieResponseSignOutContext context); + Task ResponseSignOut(CookieResponseSignOutContext context); /// /// Called when an exception occurs during request or response processing. /// /// Contains information about the exception that occurred - void Exception(CookieExceptionContext context); + Task Exception(CookieExceptionContext context); } } diff --git a/src/Microsoft.AspNet.Authentication.Facebook/FacebookAppBuilderExtensions.cs b/src/Microsoft.AspNet.Authentication.Facebook/FacebookAppBuilderExtensions.cs index 9c825e6715..9d0dc44e1b 100644 --- a/src/Microsoft.AspNet.Authentication.Facebook/FacebookAppBuilderExtensions.cs +++ b/src/Microsoft.AspNet.Authentication.Facebook/FacebookAppBuilderExtensions.cs @@ -9,7 +9,7 @@ using Microsoft.Framework.OptionsModel; namespace Microsoft.AspNet.Builder { /// - /// Extension methods for using . + /// Extension methods for using . /// public static class FacebookAppBuilderExtensions { @@ -18,10 +18,10 @@ namespace Microsoft.AspNet.Builder /// /// The passed to the configure method. /// The updated . - public static IApplicationBuilder UseFacebookAuthentication([NotNull] this IApplicationBuilder app, Action configureOptions = null) + public static IApplicationBuilder UseFacebookAuthentication([NotNull] this IApplicationBuilder app, Action configureOptions = null) { - return app.UseMiddleware( - new ConfigureOptions(configureOptions ?? (o => { }))); + return app.UseMiddleware( + new ConfigureOptions(configureOptions ?? (o => { }))); } } } diff --git a/src/Microsoft.AspNet.Authentication.Facebook/FacebookAuthenticationDefaults.cs b/src/Microsoft.AspNet.Authentication.Facebook/FacebookDefaults.cs similarity index 91% rename from src/Microsoft.AspNet.Authentication.Facebook/FacebookAuthenticationDefaults.cs rename to src/Microsoft.AspNet.Authentication.Facebook/FacebookDefaults.cs index 54d48cbc51..765871274a 100644 --- a/src/Microsoft.AspNet.Authentication.Facebook/FacebookAuthenticationDefaults.cs +++ b/src/Microsoft.AspNet.Authentication.Facebook/FacebookDefaults.cs @@ -3,7 +3,7 @@ namespace Microsoft.AspNet.Authentication.Facebook { - public static class FacebookAuthenticationDefaults + public static class FacebookDefaults { public const string AuthenticationScheme = "Facebook"; diff --git a/src/Microsoft.AspNet.Authentication.Facebook/FacebookAuthenticationHandler.cs b/src/Microsoft.AspNet.Authentication.Facebook/FacebookHandler.cs similarity index 90% rename from src/Microsoft.AspNet.Authentication.Facebook/FacebookAuthenticationHandler.cs rename to src/Microsoft.AspNet.Authentication.Facebook/FacebookHandler.cs index 8f3d343b46..ee6824b451 100644 --- a/src/Microsoft.AspNet.Authentication.Facebook/FacebookAuthenticationHandler.cs +++ b/src/Microsoft.AspNet.Authentication.Facebook/FacebookHandler.cs @@ -17,9 +17,9 @@ using Newtonsoft.Json.Linq; namespace Microsoft.AspNet.Authentication.Facebook { - internal class FacebookAuthenticationHandler : OAuthAuthenticationHandler + internal class FacebookHandler : OAuthHandler { - 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)); diff --git a/src/Microsoft.AspNet.Authentication.Facebook/FacebookAuthenticationHelper.cs b/src/Microsoft.AspNet.Authentication.Facebook/FacebookHelper.cs similarity index 96% rename from src/Microsoft.AspNet.Authentication.Facebook/FacebookAuthenticationHelper.cs rename to src/Microsoft.AspNet.Authentication.Facebook/FacebookHelper.cs index 3f9f98114f..f3a99e6c49 100644 --- a/src/Microsoft.AspNet.Authentication.Facebook/FacebookAuthenticationHelper.cs +++ b/src/Microsoft.AspNet.Authentication.Facebook/FacebookHelper.cs @@ -10,7 +10,7 @@ namespace Microsoft.AspNet.Authentication.Facebook /// Contains static methods that allow to extract user's information from a /// instance retrieved from Facebook after a successful authentication process. /// - public static class FacebookAuthenticationHelper + public static class FacebookHelper { /// /// Gets the Facebook user ID. diff --git a/src/Microsoft.AspNet.Authentication.Facebook/FacebookAuthenticationMiddleware.cs b/src/Microsoft.AspNet.Authentication.Facebook/FacebookMiddleware.cs similarity index 77% rename from src/Microsoft.AspNet.Authentication.Facebook/FacebookAuthenticationMiddleware.cs rename to src/Microsoft.AspNet.Authentication.Facebook/FacebookMiddleware.cs index 3a5da62485..8e97d9d158 100644 --- a/src/Microsoft.AspNet.Authentication.Facebook/FacebookAuthenticationMiddleware.cs +++ b/src/Microsoft.AspNet.Authentication.Facebook/FacebookMiddleware.cs @@ -16,10 +16,10 @@ namespace Microsoft.AspNet.Authentication.Facebook /// /// An ASP.NET middleware for authenticating users using Facebook. /// - public class FacebookAuthenticationMiddleware : OAuthAuthenticationMiddleware + public class FacebookMiddleware : OAuthMiddleware { /// - /// Initializes a new . + /// Initializes a new . /// /// The next middleware in the HTTP pipeline to invoke. /// @@ -28,14 +28,14 @@ namespace Microsoft.AspNet.Authentication.Facebook /// /// Configuration options for the middleware. /// - public FacebookAuthenticationMiddleware( + public FacebookMiddleware( [NotNull] RequestDelegate next, [NotNull] IDataProtectionProvider dataProtectionProvider, [NotNull] ILoggerFactory loggerFactory, [NotNull] IUrlEncoder encoder, [NotNull] IOptions sharedOptions, - [NotNull] IOptions options, - ConfigureOptions configureOptions = null) + [NotNull] IOptions options, + ConfigureOptions configureOptions = null) : base(next, dataProtectionProvider, loggerFactory, encoder, sharedOptions, options, configureOptions) { if (string.IsNullOrEmpty(Options.AppId)) @@ -51,10 +51,10 @@ namespace Microsoft.AspNet.Authentication.Facebook /// /// Provides the object for processing authentication-related requests. /// - /// An configured with the supplied to the constructor. - protected override AuthenticationHandler CreateHandler() + /// An configured with the supplied to the constructor. + protected override AuthenticationHandler CreateHandler() { - return new FacebookAuthenticationHandler(Backchannel); + return new FacebookHandler(Backchannel); } } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Authentication.Facebook/FacebookAuthenticationOptions.cs b/src/Microsoft.AspNet.Authentication.Facebook/FacebookOptions.cs similarity index 68% rename from src/Microsoft.AspNet.Authentication.Facebook/FacebookAuthenticationOptions.cs rename to src/Microsoft.AspNet.Authentication.Facebook/FacebookOptions.cs index 4a5e1ce91d..12bde4675e 100644 --- a/src/Microsoft.AspNet.Authentication.Facebook/FacebookAuthenticationOptions.cs +++ b/src/Microsoft.AspNet.Authentication.Facebook/FacebookOptions.cs @@ -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 { /// - /// Configuration options for . + /// Configuration options for . /// - public class FacebookAuthenticationOptions : OAuthAuthenticationOptions + public class FacebookOptions : OAuthOptions { /// - /// Initializes a new . + /// Initializes a new . /// - 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; } diff --git a/src/Microsoft.AspNet.Authentication.Facebook/FacebookServiceCollectionExtensions.cs b/src/Microsoft.AspNet.Authentication.Facebook/FacebookServiceCollectionExtensions.cs index 3666f9ecf5..ccffd7de44 100644 --- a/src/Microsoft.AspNet.Authentication.Facebook/FacebookServiceCollectionExtensions.cs +++ b/src/Microsoft.AspNet.Authentication.Facebook/FacebookServiceCollectionExtensions.cs @@ -9,18 +9,18 @@ using Microsoft.Framework.Internal; namespace Microsoft.Framework.DependencyInjection { /// - /// Extension methods for using . + /// Extension methods for using . /// public static class FacebookServiceCollectionExtensions { - public static IServiceCollection AddFacebookAuthentication([NotNull] this IServiceCollection services, [NotNull] Action configure) + public static IServiceCollection AddFacebookAuthentication([NotNull] this IServiceCollection services, [NotNull] Action configure) { return services.Configure(configure); } public static IServiceCollection AddFacebookAuthentication([NotNull] this IServiceCollection services, [NotNull] IConfiguration config) { - return services.Configure(config); + return services.Configure(config); } } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Authentication.Google/GoogleAppBuilderExtensions.cs b/src/Microsoft.AspNet.Authentication.Google/GoogleAppBuilderExtensions.cs index 848e83df70..55e3ba23a0 100644 --- a/src/Microsoft.AspNet.Authentication.Google/GoogleAppBuilderExtensions.cs +++ b/src/Microsoft.AspNet.Authentication.Google/GoogleAppBuilderExtensions.cs @@ -9,7 +9,7 @@ using Microsoft.Framework.OptionsModel; namespace Microsoft.AspNet.Builder { /// - /// Extension methods for using . + /// Extension methods for using . /// public static class GoogleAppBuilderExtensions { @@ -20,10 +20,10 @@ namespace Microsoft.AspNet.Builder /// Used to configure Middleware options. /// Name of the options instance to be used /// The updated . - public static IApplicationBuilder UseGoogleAuthentication([NotNull] this IApplicationBuilder app, Action configureOptions = null, string optionsName = "") + public static IApplicationBuilder UseGoogleAuthentication([NotNull] this IApplicationBuilder app, Action configureOptions = null, string optionsName = "") { - return app.UseMiddleware( - new ConfigureOptions(configureOptions ?? (o => { }))); + return app.UseMiddleware( + new ConfigureOptions(configureOptions ?? (o => { }))); } } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Authentication.Google/GoogleAuthenticationDefaults.cs b/src/Microsoft.AspNet.Authentication.Google/GoogleDefaults.cs similarity index 91% rename from src/Microsoft.AspNet.Authentication.Google/GoogleAuthenticationDefaults.cs rename to src/Microsoft.AspNet.Authentication.Google/GoogleDefaults.cs index 88aa4f1f16..4085778d35 100644 --- a/src/Microsoft.AspNet.Authentication.Google/GoogleAuthenticationDefaults.cs +++ b/src/Microsoft.AspNet.Authentication.Google/GoogleDefaults.cs @@ -3,7 +3,7 @@ namespace Microsoft.AspNet.Authentication.Google { - public static class GoogleAuthenticationDefaults + public static class GoogleDefaults { public const string AuthenticationScheme = "Google"; diff --git a/src/Microsoft.AspNet.Authentication.Google/GoogleAuthenticationHandler.cs b/src/Microsoft.AspNet.Authentication.Google/GoogleHandler.cs similarity index 88% rename from src/Microsoft.AspNet.Authentication.Google/GoogleAuthenticationHandler.cs rename to src/Microsoft.AspNet.Authentication.Google/GoogleHandler.cs index 7d55c5e676..e688dc8562 100644 --- a/src/Microsoft.AspNet.Authentication.Google/GoogleAuthenticationHandler.cs +++ b/src/Microsoft.AspNet.Authentication.Google/GoogleHandler.cs @@ -14,9 +14,9 @@ using Newtonsoft.Json.Linq; namespace Microsoft.AspNet.Authentication.Google { - internal class GoogleAuthenticationHandler : OAuthAuthenticationHandler + internal class GoogleHandler : OAuthHandler { - 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)); diff --git a/src/Microsoft.AspNet.Authentication.Google/GoogleAuthenticationHelper.cs b/src/Microsoft.AspNet.Authentication.Google/GoogleHelper.cs similarity index 98% rename from src/Microsoft.AspNet.Authentication.Google/GoogleAuthenticationHelper.cs rename to src/Microsoft.AspNet.Authentication.Google/GoogleHelper.cs index 611bfffa7b..e8618f3e31 100644 --- a/src/Microsoft.AspNet.Authentication.Google/GoogleAuthenticationHelper.cs +++ b/src/Microsoft.AspNet.Authentication.Google/GoogleHelper.cs @@ -10,7 +10,7 @@ namespace Microsoft.AspNet.Authentication.Google /// Contains static methods that allow to extract user's information from a /// instance retrieved from Google after a successful authentication process. /// - public static class GoogleAuthenticationHelper + public static class GoogleHelper { /// /// Gets the Google user ID. diff --git a/src/Microsoft.AspNet.Authentication.Google/GoogleAuthenticationMiddleware.cs b/src/Microsoft.AspNet.Authentication.Google/GoogleMiddleware.cs similarity index 79% rename from src/Microsoft.AspNet.Authentication.Google/GoogleAuthenticationMiddleware.cs rename to src/Microsoft.AspNet.Authentication.Google/GoogleMiddleware.cs index b4d6cee923..5ceb214494 100644 --- a/src/Microsoft.AspNet.Authentication.Google/GoogleAuthenticationMiddleware.cs +++ b/src/Microsoft.AspNet.Authentication.Google/GoogleMiddleware.cs @@ -16,10 +16,10 @@ namespace Microsoft.AspNet.Authentication.Google /// An ASP.NET middleware for authenticating users using Google OAuth 2.0. /// [SuppressMessage("Microsoft.Design", "CA1001:TypesThatOwnDisposableFieldsShouldBeDisposable", Justification = "Middleware are not disposable.")] - public class GoogleAuthenticationMiddleware : OAuthAuthenticationMiddleware + public class GoogleMiddleware : OAuthMiddleware { /// - /// Initializes a new . + /// Initializes a new . /// /// The next middleware in the HTTP pipeline to invoke. /// @@ -28,14 +28,14 @@ namespace Microsoft.AspNet.Authentication.Google /// /// Configuration options for the middleware. /// - public GoogleAuthenticationMiddleware( + public GoogleMiddleware( [NotNull] RequestDelegate next, [NotNull] IDataProtectionProvider dataProtectionProvider, [NotNull] ILoggerFactory loggerFactory, [NotNull] IUrlEncoder encoder, [NotNull] IOptions sharedOptions, - [NotNull] IOptions options, - ConfigureOptions configureOptions = null) + [NotNull] IOptions options, + ConfigureOptions configureOptions = null) : base(next, dataProtectionProvider, loggerFactory, encoder, sharedOptions, options, configureOptions) { if (Options.Scope.Count == 0) @@ -52,10 +52,10 @@ namespace Microsoft.AspNet.Authentication.Google /// /// Provides the object for processing authentication-related requests. /// - /// An configured with the supplied to the constructor. - protected override AuthenticationHandler CreateHandler() + /// An configured with the supplied to the constructor. + protected override AuthenticationHandler CreateHandler() { - return new GoogleAuthenticationHandler(Backchannel); + return new GoogleHandler(Backchannel); } } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Authentication.Google/GoogleAuthenticationOptions.cs b/src/Microsoft.AspNet.Authentication.Google/GoogleOptions.cs similarity index 53% rename from src/Microsoft.AspNet.Authentication.Google/GoogleAuthenticationOptions.cs rename to src/Microsoft.AspNet.Authentication.Google/GoogleOptions.cs index f0c5d0f220..48f0c736b3 100644 --- a/src/Microsoft.AspNet.Authentication.Google/GoogleAuthenticationOptions.cs +++ b/src/Microsoft.AspNet.Authentication.Google/GoogleOptions.cs @@ -7,21 +7,21 @@ using Microsoft.AspNet.Http; namespace Microsoft.AspNet.Authentication.Google { /// - /// Configuration options for . + /// Configuration options for . /// - public class GoogleAuthenticationOptions : OAuthAuthenticationOptions + public class GoogleOptions : OAuthOptions { /// - /// Initializes a new . + /// Initializes a new . /// - 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; } diff --git a/src/Microsoft.AspNet.Authentication.Google/GoogleServiceCollectionExtensions.cs b/src/Microsoft.AspNet.Authentication.Google/GoogleServiceCollectionExtensions.cs index 6b47398490..0c329dc5cb 100644 --- a/src/Microsoft.AspNet.Authentication.Google/GoogleServiceCollectionExtensions.cs +++ b/src/Microsoft.AspNet.Authentication.Google/GoogleServiceCollectionExtensions.cs @@ -9,18 +9,18 @@ using Microsoft.Framework.Internal; namespace Microsoft.Framework.DependencyInjection { /// - /// Extension methods for using . + /// Extension methods for using . /// public static class GoogleServiceCollectionExtensions { - public static IServiceCollection AddGoogleAuthentication([NotNull] this IServiceCollection services, [NotNull] Action configure) + public static IServiceCollection AddGoogleAuthentication([NotNull] this IServiceCollection services, [NotNull] Action configure) { return services.Configure(configure); } public static IServiceCollection AddGoogleAuthentication([NotNull] this IServiceCollection services, [NotNull] IConfiguration config) { - return services.Configure(config); + return services.Configure(config); } } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Authentication.JwtBearer/Events/AuthenticationChallengeContext.cs b/src/Microsoft.AspNet.Authentication.JwtBearer/Events/AuthenticationChallengeContext.cs index 702ccc4527..44f44d5b3e 100644 --- a/src/Microsoft.AspNet.Authentication.JwtBearer/Events/AuthenticationChallengeContext.cs +++ b/src/Microsoft.AspNet.Authentication.JwtBearer/Events/AuthenticationChallengeContext.cs @@ -5,9 +5,9 @@ using Microsoft.AspNet.Http; namespace Microsoft.AspNet.Authentication.JwtBearer { - public class AuthenticationChallengeContext : BaseControlContext + public class AuthenticationChallengeContext : BaseControlContext { - public AuthenticationChallengeContext(HttpContext context, JwtBearerAuthenticationOptions options) + public AuthenticationChallengeContext(HttpContext context, JwtBearerOptions options) : base(context, options) { } diff --git a/src/Microsoft.AspNet.Authentication.JwtBearer/Events/AuthenticationFailedContext.cs b/src/Microsoft.AspNet.Authentication.JwtBearer/Events/AuthenticationFailedContext.cs index f4301c4c6f..2ac80c4f73 100644 --- a/src/Microsoft.AspNet.Authentication.JwtBearer/Events/AuthenticationFailedContext.cs +++ b/src/Microsoft.AspNet.Authentication.JwtBearer/Events/AuthenticationFailedContext.cs @@ -6,9 +6,9 @@ using Microsoft.AspNet.Http; namespace Microsoft.AspNet.Authentication.JwtBearer { - public class AuthenticationFailedContext : BaseControlContext + public class AuthenticationFailedContext : BaseControlContext { - public AuthenticationFailedContext(HttpContext context, JwtBearerAuthenticationOptions options) + public AuthenticationFailedContext(HttpContext context, JwtBearerOptions options) : base(context, options) { } diff --git a/src/Microsoft.AspNet.Authentication.JwtBearer/Events/IJwtBearerAuthenticationEvents.cs b/src/Microsoft.AspNet.Authentication.JwtBearer/Events/IJwtBearerEvents.cs similarity index 94% rename from src/Microsoft.AspNet.Authentication.JwtBearer/Events/IJwtBearerAuthenticationEvents.cs rename to src/Microsoft.AspNet.Authentication.JwtBearer/Events/IJwtBearerEvents.cs index cd1a6fc087..0ec2a9c247 100644 --- a/src/Microsoft.AspNet.Authentication.JwtBearer/Events/IJwtBearerAuthenticationEvents.cs +++ b/src/Microsoft.AspNet.Authentication.JwtBearer/Events/IJwtBearerEvents.cs @@ -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; /// /// Specifies events which the invokes to enable developer control over the authentication process. /> @@ -13,7 +11,7 @@ namespace Microsoft.AspNet.Authentication.JwtBearer /// /// Jwt bearer token middleware events. /// - public interface IJwtBearerAuthenticationEvents + public interface IJwtBearerEvents { /// /// Invoked if exceptions are thrown during request processing. The exceptions will be re-thrown after this event unless suppressed. diff --git a/src/Microsoft.AspNet.Authentication.JwtBearer/Events/JwtBearerAuthenticationEvents.cs b/src/Microsoft.AspNet.Authentication.JwtBearer/Events/JwtBearerEvents.cs similarity index 97% rename from src/Microsoft.AspNet.Authentication.JwtBearer/Events/JwtBearerAuthenticationEvents.cs rename to src/Microsoft.AspNet.Authentication.JwtBearer/Events/JwtBearerEvents.cs index 4b06937a70..a6976228cd 100644 --- a/src/Microsoft.AspNet.Authentication.JwtBearer/Events/JwtBearerAuthenticationEvents.cs +++ b/src/Microsoft.AspNet.Authentication.JwtBearer/Events/JwtBearerEvents.cs @@ -13,7 +13,7 @@ namespace Microsoft.AspNet.Authentication.JwtBearer /// /// Jwt bearer token middleware events. /// - public class JwtBearerAuthenticationEvents : IJwtBearerAuthenticationEvents + public class JwtBearerEvents : IJwtBearerEvents { /// /// Invoked if exceptions are thrown during request processing. The exceptions will be re-thrown after this event unless suppressed. diff --git a/src/Microsoft.AspNet.Authentication.JwtBearer/Events/MessageReceivedContext.cs b/src/Microsoft.AspNet.Authentication.JwtBearer/Events/MessageReceivedContext.cs index e9e8955786..cd940ef679 100644 --- a/src/Microsoft.AspNet.Authentication.JwtBearer/Events/MessageReceivedContext.cs +++ b/src/Microsoft.AspNet.Authentication.JwtBearer/Events/MessageReceivedContext.cs @@ -5,9 +5,9 @@ using Microsoft.AspNet.Http; namespace Microsoft.AspNet.Authentication.JwtBearer { - public class MessageReceivedContext : BaseControlContext + public class MessageReceivedContext : BaseControlContext { - public MessageReceivedContext(HttpContext context, JwtBearerAuthenticationOptions options) + public MessageReceivedContext(HttpContext context, JwtBearerOptions options) : base(context, options) { } diff --git a/src/Microsoft.AspNet.Authentication.JwtBearer/Events/SecurityTokenReceivedContext.cs b/src/Microsoft.AspNet.Authentication.JwtBearer/Events/SecurityTokenReceivedContext.cs index 672021ca6b..5aedda1d84 100644 --- a/src/Microsoft.AspNet.Authentication.JwtBearer/Events/SecurityTokenReceivedContext.cs +++ b/src/Microsoft.AspNet.Authentication.JwtBearer/Events/SecurityTokenReceivedContext.cs @@ -5,9 +5,9 @@ using Microsoft.AspNet.Http; namespace Microsoft.AspNet.Authentication.JwtBearer { - public class SecurityTokenReceivedContext : BaseControlContext + public class SecurityTokenReceivedContext : BaseControlContext { - public SecurityTokenReceivedContext(HttpContext context, JwtBearerAuthenticationOptions options) + public SecurityTokenReceivedContext(HttpContext context, JwtBearerOptions options) : base(context, options) { } diff --git a/src/Microsoft.AspNet.Authentication.JwtBearer/Events/SecurityTokenValidatedContext.cs b/src/Microsoft.AspNet.Authentication.JwtBearer/Events/SecurityTokenValidatedContext.cs index 383284e4ae..488e8e6b02 100644 --- a/src/Microsoft.AspNet.Authentication.JwtBearer/Events/SecurityTokenValidatedContext.cs +++ b/src/Microsoft.AspNet.Authentication.JwtBearer/Events/SecurityTokenValidatedContext.cs @@ -5,9 +5,9 @@ using Microsoft.AspNet.Http; namespace Microsoft.AspNet.Authentication.JwtBearer { - public class SecurityTokenValidatedContext : BaseControlContext + public class SecurityTokenValidatedContext : BaseControlContext { - public SecurityTokenValidatedContext(HttpContext context, JwtBearerAuthenticationOptions options) + public SecurityTokenValidatedContext(HttpContext context, JwtBearerOptions options) : base(context, options) { } diff --git a/src/Microsoft.AspNet.Authentication.JwtBearer/JwtBearerAppBuilderExtensions.cs b/src/Microsoft.AspNet.Authentication.JwtBearer/JwtBearerAppBuilderExtensions.cs index 6b73167d89..bdc91c71d2 100644 --- a/src/Microsoft.AspNet.Authentication.JwtBearer/JwtBearerAppBuilderExtensions.cs +++ b/src/Microsoft.AspNet.Authentication.JwtBearer/JwtBearerAppBuilderExtensions.cs @@ -24,10 +24,10 @@ namespace Microsoft.AspNet.Builder /// The application builder /// Options which control the processing of the bearer header. /// The application builder - public static IApplicationBuilder UseJwtBearerAuthentication([NotNull] this IApplicationBuilder app, Action configureOptions = null, string optionsName = "") + public static IApplicationBuilder UseJwtBearerAuthentication([NotNull] this IApplicationBuilder app, Action configureOptions = null, string optionsName = "") { - return app.UseMiddleware( - new ConfigureOptions(configureOptions ?? (o => { }))); + return app.UseMiddleware( + new ConfigureOptions(configureOptions ?? (o => { }))); } } } diff --git a/src/Microsoft.AspNet.Authentication.JwtBearer/JwtBearerAuthenticationDefaults.cs b/src/Microsoft.AspNet.Authentication.JwtBearer/JwtBearerDefaults.cs similarity index 91% rename from src/Microsoft.AspNet.Authentication.JwtBearer/JwtBearerAuthenticationDefaults.cs rename to src/Microsoft.AspNet.Authentication.JwtBearer/JwtBearerDefaults.cs index d6cb381976..c39bf6cb9e 100644 --- a/src/Microsoft.AspNet.Authentication.JwtBearer/JwtBearerAuthenticationDefaults.cs +++ b/src/Microsoft.AspNet.Authentication.JwtBearer/JwtBearerDefaults.cs @@ -6,7 +6,7 @@ namespace Microsoft.AspNet.Authentication.JwtBearer /// /// Default values used by authorization server and bearer authentication. /// - public static class JwtBearerAuthenticationDefaults + public static class JwtBearerDefaults { /// /// Default value for AuthenticationScheme property in the JwtBearerAuthenticationOptions and diff --git a/src/Microsoft.AspNet.Authentication.JwtBearer/JwtBearerAuthenticationHandler.cs b/src/Microsoft.AspNet.Authentication.JwtBearer/JwtBearerHandler.cs similarity index 98% rename from src/Microsoft.AspNet.Authentication.JwtBearer/JwtBearerAuthenticationHandler.cs rename to src/Microsoft.AspNet.Authentication.JwtBearer/JwtBearerHandler.cs index b2e6cfbd8c..0f420f7fc4 100644 --- a/src/Microsoft.AspNet.Authentication.JwtBearer/JwtBearerAuthenticationHandler.cs +++ b/src/Microsoft.AspNet.Authentication.JwtBearer/JwtBearerHandler.cs @@ -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 + public class JwtBearerHandler : AuthenticationHandler { private OpenIdConnectConfiguration _configuration; diff --git a/src/Microsoft.AspNet.Authentication.JwtBearer/JwtBearerAuthenticationMiddleware.cs b/src/Microsoft.AspNet.Authentication.JwtBearer/JwtBearerMiddleware.cs similarity index 86% rename from src/Microsoft.AspNet.Authentication.JwtBearer/JwtBearerAuthenticationMiddleware.cs rename to src/Microsoft.AspNet.Authentication.JwtBearer/JwtBearerMiddleware.cs index 1127f12889..7884a675b8 100644 --- a/src/Microsoft.AspNet.Authentication.JwtBearer/JwtBearerAuthenticationMiddleware.cs +++ b/src/Microsoft.AspNet.Authentication.JwtBearer/JwtBearerMiddleware.cs @@ -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. /// - public class JwtBearerAuthenticationMiddleware : AuthenticationMiddleware + public class JwtBearerMiddleware : AuthenticationMiddleware { /// /// 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. /// - public JwtBearerAuthenticationMiddleware( + public JwtBearerMiddleware( [NotNull] RequestDelegate next, [NotNull] ILoggerFactory loggerFactory, [NotNull] IUrlEncoder encoder, - [NotNull] IOptions options, - ConfigureOptions configureOptions) + [NotNull] IOptions options, + ConfigureOptions 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. /// /// A new instance of the request handler - protected override AuthenticationHandler CreateHandler() + protected override AuthenticationHandler CreateHandler() { - return new JwtBearerAuthenticationHandler(); + return new JwtBearerHandler(); } } } diff --git a/src/Microsoft.AspNet.Authentication.JwtBearer/JwtBearerAuthenticationOptions.cs b/src/Microsoft.AspNet.Authentication.JwtBearer/JwtBearerOptions.cs similarity index 91% rename from src/Microsoft.AspNet.Authentication.JwtBearer/JwtBearerAuthenticationOptions.cs rename to src/Microsoft.AspNet.Authentication.JwtBearer/JwtBearerOptions.cs index 6e778907bf..a6df42ec6b 100644 --- a/src/Microsoft.AspNet.Authentication.JwtBearer/JwtBearerAuthenticationOptions.cs +++ b/src/Microsoft.AspNet.Authentication.JwtBearer/JwtBearerOptions.cs @@ -14,14 +14,14 @@ namespace Microsoft.AspNet.Authentication.JwtBearer /// /// Options class provides information needed to control Bearer Authentication middleware behavior /// - public class JwtBearerAuthenticationOptions : AuthenticationOptions + public class JwtBearerOptions : AuthenticationOptions { /// /// Creates an instance of bearer authentication options with default values. /// - public JwtBearerAuthenticationOptions() : base() + public JwtBearerOptions() : base() { - AuthenticationScheme = JwtBearerAuthenticationDefaults.AuthenticationScheme; + AuthenticationScheme = JwtBearerDefaults.AuthenticationScheme; } /// @@ -45,14 +45,14 @@ namespace Microsoft.AspNet.Authentication.JwtBearer /// /// Gets or sets the challenge to put in the "WWW-Authenticate" header. /// - public string Challenge { get; set; } = JwtBearerAuthenticationDefaults.AuthenticationScheme; + public string Challenge { get; set; } = JwtBearerDefaults.AuthenticationScheme; /// /// 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. /// - public IJwtBearerAuthenticationEvents Events { get; set; } = new JwtBearerAuthenticationEvents(); + public IJwtBearerEvents Events { get; set; } = new JwtBearerEvents(); /// /// The HttpMessageHandler used to retrieve metadata. diff --git a/src/Microsoft.AspNet.Authentication.JwtBearer/JwtBearerServiceCollectionExtensions.cs b/src/Microsoft.AspNet.Authentication.JwtBearer/JwtBearerServiceCollectionExtensions.cs index db7633bfe2..30a99c277b 100644 --- a/src/Microsoft.AspNet.Authentication.JwtBearer/JwtBearerServiceCollectionExtensions.cs +++ b/src/Microsoft.AspNet.Authentication.JwtBearer/JwtBearerServiceCollectionExtensions.cs @@ -13,14 +13,14 @@ namespace Microsoft.Framework.DependencyInjection /// public static class JwtBearerServiceCollectionExtensions { - public static IServiceCollection ConfigureJwtBearerAuthentication([NotNull] this IServiceCollection services, [NotNull] Action configure) + public static IServiceCollection AddJwtBearerAuthentication([NotNull] this IServiceCollection services, [NotNull] Action 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(config); } } } diff --git a/src/Microsoft.AspNet.Authentication.MicrosoftAccount/MicrosoftAccountAppBuilderExtensions.cs b/src/Microsoft.AspNet.Authentication.MicrosoftAccount/MicrosoftAccountAppBuilderExtensions.cs index 0bb6dc905e..86c4ae040e 100644 --- a/src/Microsoft.AspNet.Authentication.MicrosoftAccount/MicrosoftAccountAppBuilderExtensions.cs +++ b/src/Microsoft.AspNet.Authentication.MicrosoftAccount/MicrosoftAccountAppBuilderExtensions.cs @@ -9,14 +9,14 @@ using Microsoft.Framework.OptionsModel; namespace Microsoft.AspNet.Builder { /// - /// Extension methods for using + /// Extension methods for using /// public static class MicrosoftAccountAuthenticationExtensions { - public static IApplicationBuilder UseMicrosoftAccountAuthentication([NotNull] this IApplicationBuilder app, Action configureOptions = null) + public static IApplicationBuilder UseMicrosoftAccountAuthentication([NotNull] this IApplicationBuilder app, Action configureOptions = null) { - return app.UseMiddleware( - new ConfigureOptions(configureOptions ?? (o => { }))); + return app.UseMiddleware( + new ConfigureOptions(configureOptions ?? (o => { }))); } } } diff --git a/src/Microsoft.AspNet.Authentication.MicrosoftAccount/MicrosoftAccountAuthenticationOptions.cs b/src/Microsoft.AspNet.Authentication.MicrosoftAccount/MicrosoftAccountAuthenticationOptions.cs deleted file mode 100644 index 04d2bfa331..0000000000 --- a/src/Microsoft.AspNet.Authentication.MicrosoftAccount/MicrosoftAccountAuthenticationOptions.cs +++ /dev/null @@ -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 -{ - /// - /// Configuration options for . - /// - public class MicrosoftAccountAuthenticationOptions : OAuthAuthenticationOptions - { - /// - /// Initializes a new . - /// - public MicrosoftAccountAuthenticationOptions() - { - AuthenticationScheme = MicrosoftAccountAuthenticationDefaults.AuthenticationScheme; - Caption = AuthenticationScheme; - CallbackPath = new PathString("/signin-microsoft"); - AuthorizationEndpoint = MicrosoftAccountAuthenticationDefaults.AuthorizationEndpoint; - TokenEndpoint = MicrosoftAccountAuthenticationDefaults.TokenEndpoint; - UserInformationEndpoint = MicrosoftAccountAuthenticationDefaults.UserInformationEndpoint; - SaveTokensAsClaims = false; - } - } -} diff --git a/src/Microsoft.AspNet.Authentication.MicrosoftAccount/MicrosoftAccountAuthenticationDefaults.cs b/src/Microsoft.AspNet.Authentication.MicrosoftAccount/MicrosoftAccountDefaults.cs similarity index 90% rename from src/Microsoft.AspNet.Authentication.MicrosoftAccount/MicrosoftAccountAuthenticationDefaults.cs rename to src/Microsoft.AspNet.Authentication.MicrosoftAccount/MicrosoftAccountDefaults.cs index d42368cdc7..4cfd9dda03 100644 --- a/src/Microsoft.AspNet.Authentication.MicrosoftAccount/MicrosoftAccountAuthenticationDefaults.cs +++ b/src/Microsoft.AspNet.Authentication.MicrosoftAccount/MicrosoftAccountDefaults.cs @@ -3,7 +3,7 @@ namespace Microsoft.AspNet.Authentication.MicrosoftAccount { - public static class MicrosoftAccountAuthenticationDefaults + public static class MicrosoftAccountDefaults { public const string AuthenticationScheme = "Microsoft"; diff --git a/src/Microsoft.AspNet.Authentication.MicrosoftAccount/MicrosoftAccountAuthenticationHandler.cs b/src/Microsoft.AspNet.Authentication.MicrosoftAccount/MicrosoftAccountHandler.cs similarity index 84% rename from src/Microsoft.AspNet.Authentication.MicrosoftAccount/MicrosoftAccountAuthenticationHandler.cs rename to src/Microsoft.AspNet.Authentication.MicrosoftAccount/MicrosoftAccountHandler.cs index 4cec337008..adac9be9dc 100644 --- a/src/Microsoft.AspNet.Authentication.MicrosoftAccount/MicrosoftAccountAuthenticationHandler.cs +++ b/src/Microsoft.AspNet.Authentication.MicrosoftAccount/MicrosoftAccountHandler.cs @@ -11,9 +11,9 @@ using Newtonsoft.Json.Linq; namespace Microsoft.AspNet.Authentication.MicrosoftAccount { - internal class MicrosoftAccountAuthenticationHandler : OAuthAuthenticationHandler + internal class MicrosoftAccountHandler : OAuthHandler { - 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)); diff --git a/src/Microsoft.AspNet.Authentication.MicrosoftAccount/MicrosoftAccountAuthenticationHelper.cs b/src/Microsoft.AspNet.Authentication.MicrosoftAccount/MicrosoftAccountHelper.cs similarity index 96% rename from src/Microsoft.AspNet.Authentication.MicrosoftAccount/MicrosoftAccountAuthenticationHelper.cs rename to src/Microsoft.AspNet.Authentication.MicrosoftAccount/MicrosoftAccountHelper.cs index e2629cdf38..8de7ad6138 100644 --- a/src/Microsoft.AspNet.Authentication.MicrosoftAccount/MicrosoftAccountAuthenticationHelper.cs +++ b/src/Microsoft.AspNet.Authentication.MicrosoftAccount/MicrosoftAccountHelper.cs @@ -10,7 +10,7 @@ namespace Microsoft.AspNet.Authentication.MicrosoftAccount /// Contains static methods that allow to extract user's information from a /// instance retrieved from Google after a successful authentication process. /// - public static class MicrosoftAccountAuthenticationHelper + public static class MicrosoftAccountHelper { /// /// Gets the Microsoft Account user ID. diff --git a/src/Microsoft.AspNet.Authentication.MicrosoftAccount/MicrosoftAccountAuthenticationMiddleware.cs b/src/Microsoft.AspNet.Authentication.MicrosoftAccount/MicrosoftAccountMiddleware.cs similarity index 76% rename from src/Microsoft.AspNet.Authentication.MicrosoftAccount/MicrosoftAccountAuthenticationMiddleware.cs rename to src/Microsoft.AspNet.Authentication.MicrosoftAccount/MicrosoftAccountMiddleware.cs index 86da69893a..7e5830922e 100644 --- a/src/Microsoft.AspNet.Authentication.MicrosoftAccount/MicrosoftAccountAuthenticationMiddleware.cs +++ b/src/Microsoft.AspNet.Authentication.MicrosoftAccount/MicrosoftAccountMiddleware.cs @@ -14,10 +14,10 @@ namespace Microsoft.AspNet.Authentication.MicrosoftAccount /// /// An ASP.NET middleware for authenticating users using the Microsoft Account service. /// - public class MicrosoftAccountAuthenticationMiddleware : OAuthAuthenticationMiddleware + public class MicrosoftAccountMiddleware : OAuthMiddleware { /// - /// Initializes a new . + /// Initializes a new . /// /// The next middleware in the HTTP pipeline to invoke. /// @@ -26,14 +26,14 @@ namespace Microsoft.AspNet.Authentication.MicrosoftAccount /// /// Configuration options for the middleware. /// - public MicrosoftAccountAuthenticationMiddleware( + public MicrosoftAccountMiddleware( [NotNull] RequestDelegate next, [NotNull] IDataProtectionProvider dataProtectionProvider, [NotNull] ILoggerFactory loggerFactory, [NotNull] IUrlEncoder encoder, [NotNull] IOptions sharedOptions, - [NotNull] IOptions options, - ConfigureOptions configureOptions = null) + [NotNull] IOptions options, + ConfigureOptions configureOptions = null) : base(next, dataProtectionProvider, loggerFactory, encoder, sharedOptions, options, configureOptions) { if (Options.Scope.Count == 0) @@ -47,10 +47,10 @@ namespace Microsoft.AspNet.Authentication.MicrosoftAccount /// /// Provides the object for processing authentication-related requests. /// - /// An configured with the supplied to the constructor. - protected override AuthenticationHandler CreateHandler() + /// An configured with the supplied to the constructor. + protected override AuthenticationHandler CreateHandler() { - return new MicrosoftAccountAuthenticationHandler(Backchannel); + return new MicrosoftAccountHandler(Backchannel); } } } diff --git a/src/Microsoft.AspNet.Authentication.MicrosoftAccount/MicrosoftAccountOptions.cs b/src/Microsoft.AspNet.Authentication.MicrosoftAccount/MicrosoftAccountOptions.cs new file mode 100644 index 0000000000..d817cd3ee8 --- /dev/null +++ b/src/Microsoft.AspNet.Authentication.MicrosoftAccount/MicrosoftAccountOptions.cs @@ -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 +{ + /// + /// Configuration options for . + /// + public class MicrosoftAccountOptions : OAuthOptions + { + /// + /// Initializes a new . + /// + public MicrosoftAccountOptions() + { + AuthenticationScheme = MicrosoftAccountDefaults.AuthenticationScheme; + Caption = AuthenticationScheme; + CallbackPath = new PathString("/signin-microsoft"); + AuthorizationEndpoint = MicrosoftAccountDefaults.AuthorizationEndpoint; + TokenEndpoint = MicrosoftAccountDefaults.TokenEndpoint; + UserInformationEndpoint = MicrosoftAccountDefaults.UserInformationEndpoint; + SaveTokensAsClaims = false; + } + } +} diff --git a/src/Microsoft.AspNet.Authentication.MicrosoftAccount/MicrosoftAccountServiceCollectionExtensions.cs b/src/Microsoft.AspNet.Authentication.MicrosoftAccount/MicrosoftAccountServiceCollectionExtensions.cs index fb7d6ce3f1..83e52461c7 100644 --- a/src/Microsoft.AspNet.Authentication.MicrosoftAccount/MicrosoftAccountServiceCollectionExtensions.cs +++ b/src/Microsoft.AspNet.Authentication.MicrosoftAccount/MicrosoftAccountServiceCollectionExtensions.cs @@ -9,18 +9,18 @@ using Microsoft.Framework.Internal; namespace Microsoft.Framework.DependencyInjection { /// - /// Extension methods for using + /// Extension methods for using /// public static class MicrosoftAccountServiceCollectionExtensions { - public static IServiceCollection AddMicrosoftAccountAuthentication([NotNull] this IServiceCollection services, [NotNull] Action configure) + public static IServiceCollection AddMicrosoftAccountAuthentication([NotNull] this IServiceCollection services, [NotNull] Action configure) { return services.Configure(configure); } public static IServiceCollection AddMicrosoftAccountAuthentication([NotNull] this IServiceCollection services, [NotNull] IConfiguration config) { - return services.Configure(config); + return services.Configure(config); } } } diff --git a/src/Microsoft.AspNet.Authentication.OAuth/Events/IOAuthAuthenticationEvents.cs b/src/Microsoft.AspNet.Authentication.OAuth/Events/IOAuthEvents.cs similarity index 84% rename from src/Microsoft.AspNet.Authentication.OAuth/Events/IOAuthAuthenticationEvents.cs rename to src/Microsoft.AspNet.Authentication.OAuth/Events/IOAuthEvents.cs index 897b889206..d5acd3bbca 100644 --- a/src/Microsoft.AspNet.Authentication.OAuth/Events/IOAuthAuthenticationEvents.cs +++ b/src/Microsoft.AspNet.Authentication.OAuth/Events/IOAuthEvents.cs @@ -6,9 +6,9 @@ using System.Threading.Tasks; namespace Microsoft.AspNet.Authentication.OAuth { /// - /// Specifies callback methods which the invokes to enable developer control over the authentication process. + /// Specifies callback methods which the invokes to enable developer control over the authentication process. /// - public interface IOAuthAuthenticationEvents + public interface IOAuthEvents { /// /// 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. /// /// Contains redirect URI and of the challenge. - void ApplyRedirect(OAuthApplyRedirectContext context); + Task ApplyRedirect(OAuthApplyRedirectContext context); } } diff --git a/src/Microsoft.AspNet.Authentication.OAuth/Events/OAuthApplyRedirectContext.cs b/src/Microsoft.AspNet.Authentication.OAuth/Events/OAuthApplyRedirectContext.cs index 86ec2d62a9..83629708f8 100644 --- a/src/Microsoft.AspNet.Authentication.OAuth/Events/OAuthApplyRedirectContext.cs +++ b/src/Microsoft.AspNet.Authentication.OAuth/Events/OAuthApplyRedirectContext.cs @@ -9,7 +9,7 @@ namespace Microsoft.AspNet.Authentication.OAuth /// /// Context passed when a Challenge causes a redirect to authorize endpoint in the Microsoft account middleware. /// - public class OAuthApplyRedirectContext : BaseContext + public class OAuthApplyRedirectContext : BaseContext { /// /// Creates a new context object. @@ -17,7 +17,7 @@ namespace Microsoft.AspNet.Authentication.OAuth /// The HTTP request context. /// The authentication properties of the challenge. /// The initial redirect URI. - 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; diff --git a/src/Microsoft.AspNet.Authentication.OAuth/Events/OAuthAuthenticatedContext.cs b/src/Microsoft.AspNet.Authentication.OAuth/Events/OAuthAuthenticatedContext.cs index 5e5574f825..3aa4f8b6a8 100644 --- a/src/Microsoft.AspNet.Authentication.OAuth/Events/OAuthAuthenticatedContext.cs +++ b/src/Microsoft.AspNet.Authentication.OAuth/Events/OAuthAuthenticatedContext.cs @@ -15,7 +15,7 @@ namespace Microsoft.AspNet.Authentication.OAuth /// /// Contains information about the login session as well as the user . /// - public class OAuthAuthenticatedContext : BaseContext + public class OAuthAuthenticatedContext : BaseContext { /// /// Initializes a new . @@ -26,7 +26,7 @@ namespace Microsoft.AspNet.Authentication.OAuth /// The tokens returned from the token endpoint. 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 /// The JSON-serialized user. public OAuthAuthenticatedContext( [NotNull] HttpContext context, - [NotNull] OAuthAuthenticationOptions options, + [NotNull] OAuthOptions options, [NotNull] HttpClient backchannel, [NotNull] OAuthTokenResponse tokens, [NotNull] JObject user) diff --git a/src/Microsoft.AspNet.Authentication.OAuth/Events/OAuthAuthenticationEvents.cs b/src/Microsoft.AspNet.Authentication.OAuth/Events/OAuthEvents.cs similarity index 85% rename from src/Microsoft.AspNet.Authentication.OAuth/Events/OAuthAuthenticationEvents.cs rename to src/Microsoft.AspNet.Authentication.OAuth/Events/OAuthEvents.cs index e2002bc8b4..9f8e064ae4 100644 --- a/src/Microsoft.AspNet.Authentication.OAuth/Events/OAuthAuthenticationEvents.cs +++ b/src/Microsoft.AspNet.Authentication.OAuth/Events/OAuthEvents.cs @@ -7,9 +7,9 @@ using System.Threading.Tasks; namespace Microsoft.AspNet.Authentication.OAuth { /// - /// Default implementation. + /// Default implementation. /// - public class OAuthAuthenticationEvents : IOAuthAuthenticationEvents + public class OAuthEvents : IOAuthEvents { /// /// Gets or sets the function that is invoked when the Authenticated method is invoked. @@ -24,7 +24,11 @@ namespace Microsoft.AspNet.Authentication.OAuth /// /// Gets or sets the delegate that is invoked when the ApplyRedirect method is invoked. /// - public Action OnApplyRedirect { get; set; } = context => context.Response.Redirect(context.RedirectUri); + public Func OnApplyRedirect { get; set; } = context => + { + context.Response.Redirect(context.RedirectUri); + return Task.FromResult(0); + }; /// /// 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. /// /// Contains redirect URI and of the challenge. - public virtual void ApplyRedirect(OAuthApplyRedirectContext context) => OnApplyRedirect(context); + public virtual Task ApplyRedirect(OAuthApplyRedirectContext context) => OnApplyRedirect(context); } } diff --git a/src/Microsoft.AspNet.Authentication.OAuth/OAuthAuthenticationExtensions.cs b/src/Microsoft.AspNet.Authentication.OAuth/OAuthExtensions.cs similarity index 72% rename from src/Microsoft.AspNet.Authentication.OAuth/OAuthAuthenticationExtensions.cs rename to src/Microsoft.AspNet.Authentication.OAuth/OAuthExtensions.cs index 6c86be4c82..08dc3d52d3 100644 --- a/src/Microsoft.AspNet.Authentication.OAuth/OAuthAuthenticationExtensions.cs +++ b/src/Microsoft.AspNet.Authentication.OAuth/OAuthExtensions.cs @@ -9,9 +9,9 @@ using Microsoft.Framework.OptionsModel; namespace Microsoft.AspNet.Builder { /// - /// Extension methods for using + /// Extension methods for using /// - public static class OAuthAuthenticationExtensions + public static class OAuthExtensions { /// /// Authenticate users using OAuth. @@ -19,11 +19,11 @@ namespace Microsoft.AspNet.Builder /// The passed to the configure method. /// The middleware configuration options. /// The updated . - public static IApplicationBuilder UseOAuthAuthentication([NotNull] this IApplicationBuilder app, [NotNull] IOptions options) + public static IApplicationBuilder UseOAuthAuthentication([NotNull] this IApplicationBuilder app, [NotNull] IOptions options) { - return app.UseMiddleware>( + return app.UseMiddleware>( options, - new ConfigureOptions(o => { })); + new ConfigureOptions(o => { })); } } } diff --git a/src/Microsoft.AspNet.Authentication.OAuth/OAuthAuthenticationHandler.cs b/src/Microsoft.AspNet.Authentication.OAuth/OAuthHandler.cs similarity index 96% rename from src/Microsoft.AspNet.Authentication.OAuth/OAuthAuthenticationHandler.cs rename to src/Microsoft.AspNet.Authentication.OAuth/OAuthHandler.cs index a913531e28..7a9e636916 100644 --- a/src/Microsoft.AspNet.Authentication.OAuth/OAuthAuthenticationHandler.cs +++ b/src/Microsoft.AspNet.Authentication.OAuth/OAuthHandler.cs @@ -20,11 +20,11 @@ using Newtonsoft.Json.Linq; namespace Microsoft.AspNet.Authentication.OAuth { - public class OAuthAuthenticationHandler : AuthenticationHandler where TOptions : OAuthAuthenticationOptions + public class OAuthHandler : AuthenticationHandler 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 HandleUnauthorizedAsync([NotNull] ChallengeContext context) + protected override async Task 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) diff --git a/src/Microsoft.AspNet.Authentication.OAuth/OAuthAuthenticationMiddleware.cs b/src/Microsoft.AspNet.Authentication.OAuth/OAuthMiddleware.cs similarity index 90% rename from src/Microsoft.AspNet.Authentication.OAuth/OAuthAuthenticationMiddleware.cs rename to src/Microsoft.AspNet.Authentication.OAuth/OAuthMiddleware.cs index b38637b8aa..9822963cc5 100644 --- a/src/Microsoft.AspNet.Authentication.OAuth/OAuthAuthenticationMiddleware.cs +++ b/src/Microsoft.AspNet.Authentication.OAuth/OAuthMiddleware.cs @@ -18,7 +18,7 @@ namespace Microsoft.AspNet.Authentication.OAuth /// An ASP.NET middleware for authenticating users using OAuth services. /// [SuppressMessage("Microsoft.Design", "CA1001:TypesThatOwnDisposableFieldsShouldBeDisposable", Justification = "Middleware are not disposable.")] - public class OAuthAuthenticationMiddleware : AuthenticationMiddleware where TOptions : OAuthAuthenticationOptions, new() + public class OAuthMiddleware : AuthenticationMiddleware where TOptions : OAuthOptions, new() { /// /// Initializes a new . @@ -27,7 +27,7 @@ namespace Microsoft.AspNet.Authentication.OAuth /// /// /// Configuration options for the middleware. - 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 /// /// Provides the object for processing authentication-related requests. /// - /// An configured with the supplied to the constructor. + /// An configured with the supplied to the constructor. protected override AuthenticationHandler CreateHandler() { - return new OAuthAuthenticationHandler(Backchannel); + return new OAuthHandler(Backchannel); } } } diff --git a/src/Microsoft.AspNet.Authentication.OAuth/OAuthAuthenticationOptions.cs b/src/Microsoft.AspNet.Authentication.OAuth/OAuthOptions.cs similarity index 89% rename from src/Microsoft.AspNet.Authentication.OAuth/OAuthAuthenticationOptions.cs rename to src/Microsoft.AspNet.Authentication.OAuth/OAuthOptions.cs index 58749deed8..b20ada53ca 100644 --- a/src/Microsoft.AspNet.Authentication.OAuth/OAuthAuthenticationOptions.cs +++ b/src/Microsoft.AspNet.Authentication.OAuth/OAuthOptions.cs @@ -11,9 +11,9 @@ using Microsoft.Framework.OptionsModel; namespace Microsoft.AspNet.Authentication.OAuth { /// - /// Configuration options for . + /// Configuration options for . /// - public class OAuthAuthenticationOptions : AuthenticationOptions, IOptions + public class OAuthOptions : AuthenticationOptions, IOptions { /// /// Gets or sets the provider-assigned client id. @@ -67,9 +67,9 @@ namespace Microsoft.AspNet.Authentication.OAuth public HttpMessageHandler BackchannelHttpHandler { get; set; } /// - /// Gets or sets the used to handle authentication events. + /// Gets or sets the used to handle authentication events. /// - public IOAuthAuthenticationEvents Events { get; set; } = new OAuthAuthenticationEvents(); + public IOAuthEvents Events { get; set; } = new OAuthEvents(); /// /// A list of permissions to request. @@ -103,7 +103,7 @@ namespace Microsoft.AspNet.Authentication.OAuth /// public bool SaveTokensAsClaims { get; set; } = true; - OAuthAuthenticationOptions IOptions.Value + OAuthOptions IOptions.Value { get { diff --git a/src/Microsoft.AspNet.Authentication.OpenIdConnect/Events/AuthenticationFailedContext.cs b/src/Microsoft.AspNet.Authentication.OpenIdConnect/Events/AuthenticationFailedContext.cs index 7521ed7ce0..ef5307c469 100644 --- a/src/Microsoft.AspNet.Authentication.OpenIdConnect/Events/AuthenticationFailedContext.cs +++ b/src/Microsoft.AspNet.Authentication.OpenIdConnect/Events/AuthenticationFailedContext.cs @@ -7,9 +7,9 @@ using Microsoft.IdentityModel.Protocols.OpenIdConnect; namespace Microsoft.AspNet.Authentication.OpenIdConnect { - public class AuthenticationFailedContext : BaseControlContext + public class AuthenticationFailedContext : BaseControlContext { - public AuthenticationFailedContext(HttpContext context, OpenIdConnectAuthenticationOptions options) + public AuthenticationFailedContext(HttpContext context, OpenIdConnectOptions options) : base(context, options) { } diff --git a/src/Microsoft.AspNet.Authentication.OpenIdConnect/Events/AuthorizationCodeReceivedContext.cs b/src/Microsoft.AspNet.Authentication.OpenIdConnect/Events/AuthorizationCodeReceivedContext.cs index 22c00742de..53e44cdf62 100644 --- a/src/Microsoft.AspNet.Authentication.OpenIdConnect/Events/AuthorizationCodeReceivedContext.cs +++ b/src/Microsoft.AspNet.Authentication.OpenIdConnect/Events/AuthorizationCodeReceivedContext.cs @@ -11,12 +11,12 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect /// /// This Context can be used to be informed when an 'AuthorizationCode' is received over the OpenIdConnect protocol. /// - public class AuthorizationCodeReceivedContext : BaseControlContext + public class AuthorizationCodeReceivedContext : BaseControlContext { /// /// Creates a /// - public AuthorizationCodeReceivedContext(HttpContext context, OpenIdConnectAuthenticationOptions options) + public AuthorizationCodeReceivedContext(HttpContext context, OpenIdConnectOptions options) : base(context, options) { } diff --git a/src/Microsoft.AspNet.Authentication.OpenIdConnect/Events/AuthorizationCodeRedeemedContext.cs b/src/Microsoft.AspNet.Authentication.OpenIdConnect/Events/AuthorizationCodeRedeemedContext.cs index c511832cab..4794319126 100644 --- a/src/Microsoft.AspNet.Authentication.OpenIdConnect/Events/AuthorizationCodeRedeemedContext.cs +++ b/src/Microsoft.AspNet.Authentication.OpenIdConnect/Events/AuthorizationCodeRedeemedContext.cs @@ -6,12 +6,12 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect /// /// This Context can be used to be informed when an 'AuthorizationCode' is redeemed for tokens at the token endpoint. /// - public class AuthorizationCodeRedeemedContext : BaseControlContext + public class AuthorizationCodeRedeemedContext : BaseControlContext { /// /// Creates a /// - public AuthorizationCodeRedeemedContext(HttpContext context, OpenIdConnectAuthenticationOptions options) + public AuthorizationCodeRedeemedContext(HttpContext context, OpenIdConnectOptions options) : base(context, options) { } diff --git a/src/Microsoft.AspNet.Authentication.OpenIdConnect/Events/IOpenIdConnectAuthenticationEvents.cs b/src/Microsoft.AspNet.Authentication.OpenIdConnect/Events/IOpenIdConnectEvents.cs similarity index 89% rename from src/Microsoft.AspNet.Authentication.OpenIdConnect/Events/IOpenIdConnectAuthenticationEvents.cs rename to src/Microsoft.AspNet.Authentication.OpenIdConnect/Events/IOpenIdConnectEvents.cs index 4c69a1b39f..a6b4fcedf2 100644 --- a/src/Microsoft.AspNet.Authentication.OpenIdConnect/Events/IOpenIdConnectAuthenticationEvents.cs +++ b/src/Microsoft.AspNet.Authentication.OpenIdConnect/Events/IOpenIdConnectEvents.cs @@ -6,9 +6,9 @@ using System.Threading.Tasks; namespace Microsoft.AspNet.Authentication.OpenIdConnect { /// - /// Specifies events which the invokes to enable developer control over the authentication process. + /// Specifies events which the invokes to enable developer control over the authentication process. /// - public interface IOpenIdConnectAuthenticationEvents + public interface IOpenIdConnectEvents { /// /// Invoked if exceptions are thrown during request processing. The exceptions will be re-thrown after this event unless suppressed. diff --git a/src/Microsoft.AspNet.Authentication.OpenIdConnect/Events/MessageReceivedContext.cs b/src/Microsoft.AspNet.Authentication.OpenIdConnect/Events/MessageReceivedContext.cs index ece53d3dda..ecbf082779 100644 --- a/src/Microsoft.AspNet.Authentication.OpenIdConnect/Events/MessageReceivedContext.cs +++ b/src/Microsoft.AspNet.Authentication.OpenIdConnect/Events/MessageReceivedContext.cs @@ -6,9 +6,9 @@ using Microsoft.IdentityModel.Protocols.OpenIdConnect; namespace Microsoft.AspNet.Authentication.OpenIdConnect { - public class MessageReceivedContext : BaseControlContext + public class MessageReceivedContext : BaseControlContext { - public MessageReceivedContext(HttpContext context, OpenIdConnectAuthenticationOptions options) + public MessageReceivedContext(HttpContext context, OpenIdConnectOptions options) : base(context, options) { } diff --git a/src/Microsoft.AspNet.Authentication.OpenIdConnect/Events/OpenIdConnectAuthenticationEvents.cs b/src/Microsoft.AspNet.Authentication.OpenIdConnect/Events/OpenIdConnectEvents.cs similarity index 92% rename from src/Microsoft.AspNet.Authentication.OpenIdConnect/Events/OpenIdConnectAuthenticationEvents.cs rename to src/Microsoft.AspNet.Authentication.OpenIdConnect/Events/OpenIdConnectEvents.cs index 9f21f74537..90ab05eedf 100644 --- a/src/Microsoft.AspNet.Authentication.OpenIdConnect/Events/OpenIdConnectAuthenticationEvents.cs +++ b/src/Microsoft.AspNet.Authentication.OpenIdConnect/Events/OpenIdConnectEvents.cs @@ -7,9 +7,9 @@ using System.Threading.Tasks; namespace Microsoft.AspNet.Authentication.OpenIdConnect { /// - /// Specifies events which the invokes to enable developer control over the authentication process. + /// Specifies events which the invokes to enable developer control over the authentication process. /// - public class OpenIdConnectAuthenticationEvents : IOpenIdConnectAuthenticationEvents + public class OpenIdConnectEvents : IOpenIdConnectEvents { /// /// Invoked if exceptions are thrown during request processing. The exceptions will be re-thrown after this event unless suppressed. diff --git a/src/Microsoft.AspNet.Authentication.OpenIdConnect/Events/RedirectToIdentityProviderContext.cs b/src/Microsoft.AspNet.Authentication.OpenIdConnect/Events/RedirectToIdentityProviderContext.cs index 9216e86248..ca7ba6ca87 100644 --- a/src/Microsoft.AspNet.Authentication.OpenIdConnect/Events/RedirectToIdentityProviderContext.cs +++ b/src/Microsoft.AspNet.Authentication.OpenIdConnect/Events/RedirectToIdentityProviderContext.cs @@ -14,9 +14,9 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect /// /// protocol specific message. /// protocol specific options. - public class RedirectToIdentityProviderContext : BaseControlContext + public class RedirectToIdentityProviderContext : BaseControlContext { - public RedirectToIdentityProviderContext([NotNull] HttpContext context, [NotNull] OpenIdConnectAuthenticationOptions options) + public RedirectToIdentityProviderContext([NotNull] HttpContext context, [NotNull] OpenIdConnectOptions options) : base(context, options) { } diff --git a/src/Microsoft.AspNet.Authentication.OpenIdConnect/Events/SecurityTokenReceivedContext.cs b/src/Microsoft.AspNet.Authentication.OpenIdConnect/Events/SecurityTokenReceivedContext.cs index 0b960e033b..570942c6a0 100644 --- a/src/Microsoft.AspNet.Authentication.OpenIdConnect/Events/SecurityTokenReceivedContext.cs +++ b/src/Microsoft.AspNet.Authentication.OpenIdConnect/Events/SecurityTokenReceivedContext.cs @@ -6,9 +6,9 @@ using Microsoft.IdentityModel.Protocols.OpenIdConnect; namespace Microsoft.AspNet.Authentication.OpenIdConnect { - public class SecurityTokenReceivedContext : BaseControlContext + public class SecurityTokenReceivedContext : BaseControlContext { - public SecurityTokenReceivedContext(HttpContext context, OpenIdConnectAuthenticationOptions options) + public SecurityTokenReceivedContext(HttpContext context, OpenIdConnectOptions options) : base(context, options) { } diff --git a/src/Microsoft.AspNet.Authentication.OpenIdConnect/Events/SecurityTokenValidatedContext.cs b/src/Microsoft.AspNet.Authentication.OpenIdConnect/Events/SecurityTokenValidatedContext.cs index e0d12c50a4..70392282f1 100644 --- a/src/Microsoft.AspNet.Authentication.OpenIdConnect/Events/SecurityTokenValidatedContext.cs +++ b/src/Microsoft.AspNet.Authentication.OpenIdConnect/Events/SecurityTokenValidatedContext.cs @@ -6,9 +6,9 @@ using Microsoft.IdentityModel.Protocols.OpenIdConnect; namespace Microsoft.AspNet.Authentication.OpenIdConnect { - public class SecurityTokenValidatedContext : BaseControlContext + public class SecurityTokenValidatedContext : BaseControlContext { - public SecurityTokenValidatedContext(HttpContext context, OpenIdConnectAuthenticationOptions options) + public SecurityTokenValidatedContext(HttpContext context, OpenIdConnectOptions options) : base(context, options) { } diff --git a/src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectAuthenticationDefaults.cs b/src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectDefaults.cs similarity index 87% rename from src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectAuthenticationDefaults.cs rename to src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectDefaults.cs index 35a85e8437..3ddeb0fc88 100644 --- a/src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectAuthenticationDefaults.cs +++ b/src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectDefaults.cs @@ -6,7 +6,7 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect /// /// Default values related to OpenIdConnect authentication middleware /// - public static class OpenIdConnectAuthenticationDefaults + public static class OpenIdConnectDefaults { /// /// Constant used to identify state in openIdConnect protocol message. @@ -14,12 +14,12 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect public const string AuthenticationPropertiesKey = "OpenIdConnect.AuthenticationProperties"; /// - /// The default value used for OpenIdConnectAuthenticationOptions.AuthenticationScheme. + /// The default value used for OpenIdConnectOptions.AuthenticationScheme. /// public const string AuthenticationScheme = "OpenIdConnect"; /// - /// The default value for OpenIdConnectAuthenticationOptions.Caption. + /// The default value for OpenIdConnectOptions.Caption. /// public const string Caption = "OpenIdConnect"; diff --git a/src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectAuthenticationExtensions.cs b/src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectExtensions.cs similarity index 57% rename from src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectAuthenticationExtensions.cs rename to src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectExtensions.cs index 001d583abe..18b83580bc 100644 --- a/src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectAuthenticationExtensions.cs +++ b/src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectExtensions.cs @@ -8,31 +8,31 @@ using Microsoft.Framework.OptionsModel; namespace Microsoft.AspNet.Builder { /// - /// Extension methods for using + /// Extension methods for using /// - public static class OpenIdConnectAuthenticationExtensions + public static class OpenIdConnectExtensions { /// - /// Adds the into the ASP.NET runtime. + /// Adds the into the ASP.NET runtime. /// /// The application builder /// Options which control the processing of the OpenIdConnect protocol and token validation. /// The application builder - public static IApplicationBuilder UseOpenIdConnectAuthentication(this IApplicationBuilder app, Action configureOptions = null) + public static IApplicationBuilder UseOpenIdConnectAuthentication(this IApplicationBuilder app, Action configureOptions = null) { - return app.UseMiddleware( - new ConfigureOptions(configureOptions ?? (o => { }))); + return app.UseMiddleware( + new ConfigureOptions(configureOptions ?? (o => { }))); } /// - /// Adds the into the ASP.NET runtime. + /// Adds the into the ASP.NET runtime. /// /// The application builder /// Options which control the processing of the OpenIdConnect protocol and token validation. /// The application builder - public static IApplicationBuilder UseOpenIdConnectAuthentication(this IApplicationBuilder app, IOptions options) + public static IApplicationBuilder UseOpenIdConnectAuthentication(this IApplicationBuilder app, IOptions options) { - return app.UseMiddleware(options); + return app.UseMiddleware(options); } } } diff --git a/src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectAuthenticationHandler.cs b/src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectHandler.cs similarity index 95% rename from src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectAuthenticationHandler.cs rename to src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectHandler.cs index a7257db09a..f88d7f27e3 100644 --- a/src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectAuthenticationHandler.cs +++ b/src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectHandler.cs @@ -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 /// /// A per-request authentication handler for the OpenIdConnectAuthenticationMiddleware. /// - public class OpenIdConnectAuthenticationHandler : AuthenticationHandler + public class OpenIdConnectHandler : AuthenticationHandler { 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 . /// /// the nonce to remember. - /// is called to add a cookie with the name: 'OpenIdConnectAuthenticationDefaults.Nonce + (nonce)'. + /// is called to add a cookie with the name: 'OpenIdConnectAuthenticationDefaults.Nonce + (nonce)'. /// The value of the cookie is: "N". 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 /// the nonce that we are looking for. /// echos 'nonce' if a cookie is found that matches, null otherwise. /// Examine that start with the prefix: 'OpenIdConnectAuthenticationDefaults.Nonce'. - /// is used to obtain the actual 'nonce'. If the nonce is found, then is called. + /// is used to obtain the actual 'nonce'. If the nonce is found, then is called. 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: 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 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); diff --git a/src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectAuthenticationMiddleware.cs b/src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectMiddleware.cs similarity index 83% rename from src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectAuthenticationMiddleware.cs rename to src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectMiddleware.cs index 13a3d25562..667ecf0615 100644 --- a/src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectAuthenticationMiddleware.cs +++ b/src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectMiddleware.cs @@ -22,10 +22,10 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect /// /// ASP.NET middleware for obtaining identities using OpenIdConnect protocol. /// - public class OpenIdConnectAuthenticationMiddleware : AuthenticationMiddleware + public class OpenIdConnectMiddleware : AuthenticationMiddleware { /// - /// Initializes a + /// Initializes a /// /// The next middleware in the ASP.NET pipeline to invoke. /// provider for creating a data protector. @@ -33,20 +33,20 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect /// /// /// - /// a instance that will supply + /// a instance that will supply /// if configureOptions is null. - /// a instance that will be passed to an instance of - /// that is retrieved by calling where string == provides runtime configuration. + /// a instance that will be passed to an instance of + /// that is retrieved by calling where string == provides runtime configuration. [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 sharedOptions, - [NotNull] IOptions options, - ConfigureOptions configureOptions = null) + [NotNull] IOptions options, + ConfigureOptions 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 /// /// Provides the object for processing authentication-related requests. /// - /// An configured with the supplied to the constructor. - protected override AuthenticationHandler CreateHandler() + /// An configured with the supplied to the constructor. + protected override AuthenticationHandler CreateHandler() { - return new OpenIdConnectAuthenticationHandler(Backchannel); + return new OpenIdConnectHandler(Backchannel); } private class StringSerializer : IDataSerializer diff --git a/src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectAuthenticationOptions.cs b/src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectOptions.cs similarity index 89% rename from src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectAuthenticationOptions.cs rename to src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectOptions.cs index 44427e4b5e..2cdec8f4c1 100644 --- a/src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectAuthenticationOptions.cs +++ b/src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectOptions.cs @@ -17,26 +17,26 @@ using Microsoft.IdentityModel.Protocols.OpenIdConnect; namespace Microsoft.AspNet.Authentication.OpenIdConnect { /// - /// Configuration options for + /// Configuration options for /// - public class OpenIdConnectAuthenticationOptions : AuthenticationOptions + public class OpenIdConnectOptions : AuthenticationOptions { /// - /// Initializes a new + /// Initializes a new /// - public OpenIdConnectAuthenticationOptions() - : this(OpenIdConnectAuthenticationDefaults.AuthenticationScheme) + public OpenIdConnectOptions() + : this(OpenIdConnectDefaults.AuthenticationScheme) { } /// - /// Initializes a new + /// Initializes a new /// /// /// Defaults: /// AddNonceToRequest: true. /// BackchannelTimeout: 1 minute. - /// Caption: . + /// Caption: . /// ProtocolValidator: new . /// RefreshOnIssuerKeyNotFound: true /// ResponseType: @@ -45,11 +45,11 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect /// UseTokenLifetime: true. /// /// will be used to when creating the for the AuthenticationScheme property. - [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; } /// @@ -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. /// - /// If you set this value, then the will only listen for posts at this address. + /// If you set this value, then the 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 -> ... public PathString CallbackPath { get; set; } @@ -147,9 +147,9 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect public bool CacheNonces { get; set; } /// - /// Gets or sets the to notify when processing OpenIdConnect messages. + /// Gets or sets the to notify when processing OpenIdConnect messages. /// - public IOpenIdConnectAuthenticationEvents Events { get; set; } = new OpenIdConnectAuthenticationEvents(); + public IOpenIdConnectEvents Events { get; set; } = new OpenIdConnectEvents(); /// /// Gets or sets the that is used to ensure that the 'id_token' received @@ -185,7 +185,7 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect /// /// Gets or sets the method used to redirect the user agent to the identity provider. /// - public OpenIdConnectAuthenticationMethod AuthenticationMethod { get; set; } + public OpenIdConnectRedirectBehavior AuthenticationMethod { get; set; } /// /// Gets or sets the 'resource'. diff --git a/src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectAuthenticationMethod.cs b/src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectRedirectBehavior .cs similarity index 92% rename from src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectAuthenticationMethod.cs rename to src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectRedirectBehavior .cs index 147d576f9b..5c0176627f 100644 --- a/src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectAuthenticationMethod.cs +++ b/src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectRedirectBehavior .cs @@ -4,7 +4,7 @@ /// Lists the different authentication methods used to /// redirect the user agent to the identity provider. /// - public enum OpenIdConnectAuthenticationMethod + public enum OpenIdConnectRedirectBehavior { /// /// Emits a 302 response to redirect the user agent to diff --git a/src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectServiceCollectionExtensions.cs b/src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectServiceCollectionExtensions.cs index 029ed08acc..c6f4b6ec48 100644 --- a/src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectServiceCollectionExtensions.cs +++ b/src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectServiceCollectionExtensions.cs @@ -13,14 +13,14 @@ namespace Microsoft.Framework.DependencyInjection /// public static class OpenIdConnectServiceCollectionExtensions { - public static IServiceCollection AddOpenIdConnectAuthentication([NotNull] this IServiceCollection services, [NotNull] Action configure) + public static IServiceCollection AddOpenIdConnectAuthentication([NotNull] this IServiceCollection services, [NotNull] Action configure) { return services.Configure(configure); } public static IServiceCollection AddOpenIdConnectAuthentication([NotNull] this IServiceCollection services, [NotNull] IConfiguration config) { - return services.Configure(config); + return services.Configure(config); } } } diff --git a/src/Microsoft.AspNet.Authentication.Twitter/Events/ITwitterAuthenticationEvents.cs b/src/Microsoft.AspNet.Authentication.Twitter/Events/ITwitterEvents.cs similarity index 83% rename from src/Microsoft.AspNet.Authentication.Twitter/Events/ITwitterAuthenticationEvents.cs rename to src/Microsoft.AspNet.Authentication.Twitter/Events/ITwitterEvents.cs index 556fcc4a8e..c96eec4687 100644 --- a/src/Microsoft.AspNet.Authentication.Twitter/Events/ITwitterAuthenticationEvents.cs +++ b/src/Microsoft.AspNet.Authentication.Twitter/Events/ITwitterEvents.cs @@ -6,9 +6,9 @@ using System.Threading.Tasks; namespace Microsoft.AspNet.Authentication.Twitter { /// - /// Specifies callback methods which the invokes to enable developer control over the authentication process. /> + /// Specifies callback methods which the invokes to enable developer control over the authentication process. /> /// - public interface ITwitterAuthenticationEvents + public interface ITwitterEvents { /// /// 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 /// /// Contains redirect URI and of the challenge - void ApplyRedirect(TwitterApplyRedirectContext context); + Task ApplyRedirect(TwitterApplyRedirectContext context); } } diff --git a/src/Microsoft.AspNet.Authentication.Twitter/Events/TwitterApplyRedirectContext.cs b/src/Microsoft.AspNet.Authentication.Twitter/Events/TwitterApplyRedirectContext.cs index 90bfd92a2a..ab4f1aecac 100644 --- a/src/Microsoft.AspNet.Authentication.Twitter/Events/TwitterApplyRedirectContext.cs +++ b/src/Microsoft.AspNet.Authentication.Twitter/Events/TwitterApplyRedirectContext.cs @@ -9,7 +9,7 @@ namespace Microsoft.AspNet.Authentication.Twitter /// /// The Context passed when a Challenge causes a redirect to authorize endpoint in the Twitter middleware. /// - public class TwitterApplyRedirectContext : BaseContext + public class TwitterApplyRedirectContext : BaseContext { /// /// Creates a new context object. @@ -18,7 +18,7 @@ namespace Microsoft.AspNet.Authentication.Twitter /// The Twitter middleware options. /// The authentication properties of the challenge. /// The initial redirect URI. - public TwitterApplyRedirectContext(HttpContext context, TwitterAuthenticationOptions options, + public TwitterApplyRedirectContext(HttpContext context, TwitterOptions options, AuthenticationProperties properties, string redirectUri) : base(context, options) { diff --git a/src/Microsoft.AspNet.Authentication.Twitter/Events/TwitterAuthenticationEvents.cs b/src/Microsoft.AspNet.Authentication.Twitter/Events/TwitterEvents.cs similarity index 85% rename from src/Microsoft.AspNet.Authentication.Twitter/Events/TwitterAuthenticationEvents.cs rename to src/Microsoft.AspNet.Authentication.Twitter/Events/TwitterEvents.cs index deae986da7..a3bdfff6ef 100644 --- a/src/Microsoft.AspNet.Authentication.Twitter/Events/TwitterAuthenticationEvents.cs +++ b/src/Microsoft.AspNet.Authentication.Twitter/Events/TwitterEvents.cs @@ -7,9 +7,9 @@ using System.Threading.Tasks; namespace Microsoft.AspNet.Authentication.Twitter { /// - /// Default implementation. + /// Default implementation. /// - public class TwitterAuthenticationEvents : ITwitterAuthenticationEvents + public class TwitterEvents : ITwitterEvents { /// /// Gets or sets the function that is invoked when the Authenticated method is invoked. @@ -24,7 +24,11 @@ namespace Microsoft.AspNet.Authentication.Twitter /// /// Gets or sets the delegate that is invoked when the ApplyRedirect method is invoked. /// - public Action OnApplyRedirect { get; set; } = context => context.Response.Redirect(context.RedirectUri); + public Func OnApplyRedirect { get; set; } = context => + { + context.Response.Redirect(context.RedirectUri); + return Task.FromResult(0); + }; /// /// 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 /// /// Contains redirect URI and of the challenge - public virtual void ApplyRedirect(TwitterApplyRedirectContext context) => OnApplyRedirect(context); + public virtual Task ApplyRedirect(TwitterApplyRedirectContext context) => OnApplyRedirect(context); } } diff --git a/src/Microsoft.AspNet.Authentication.Twitter/TwitterAppBuilderExtensions.cs b/src/Microsoft.AspNet.Authentication.Twitter/TwitterAppBuilderExtensions.cs index 15267d02ac..286e79f22f 100644 --- a/src/Microsoft.AspNet.Authentication.Twitter/TwitterAppBuilderExtensions.cs +++ b/src/Microsoft.AspNet.Authentication.Twitter/TwitterAppBuilderExtensions.cs @@ -9,14 +9,14 @@ using Microsoft.Framework.OptionsModel; namespace Microsoft.AspNet.Builder { /// - /// Extension methods for using + /// Extension methods for using /// public static class TwitterAppBuilderExtensions { - public static IApplicationBuilder UseTwitterAuthentication([NotNull] this IApplicationBuilder app, Action configureOptions = null) + public static IApplicationBuilder UseTwitterAuthentication([NotNull] this IApplicationBuilder app, Action configureOptions = null) { - return app.UseMiddleware( - new ConfigureOptions(configureOptions ?? (o => { }))); + return app.UseMiddleware( + new ConfigureOptions(configureOptions ?? (o => { }))); } } } diff --git a/src/Microsoft.AspNet.Authentication.Twitter/TwitterAuthenticationDefaults.cs b/src/Microsoft.AspNet.Authentication.Twitter/TwitterDefaults.cs similarity index 84% rename from src/Microsoft.AspNet.Authentication.Twitter/TwitterAuthenticationDefaults.cs rename to src/Microsoft.AspNet.Authentication.Twitter/TwitterDefaults.cs index 9b7d8c0fac..a546dba9cd 100644 --- a/src/Microsoft.AspNet.Authentication.Twitter/TwitterAuthenticationDefaults.cs +++ b/src/Microsoft.AspNet.Authentication.Twitter/TwitterDefaults.cs @@ -3,7 +3,7 @@ namespace Microsoft.AspNet.Authentication.Twitter { - public static class TwitterAuthenticationDefaults + public static class TwitterDefaults { public const string AuthenticationScheme = "Twitter"; } diff --git a/src/Microsoft.AspNet.Authentication.Twitter/TwitterAuthenticationHandler.cs b/src/Microsoft.AspNet.Authentication.Twitter/TwitterHandler.cs similarity index 98% rename from src/Microsoft.AspNet.Authentication.Twitter/TwitterAuthenticationHandler.cs rename to src/Microsoft.AspNet.Authentication.Twitter/TwitterHandler.cs index e3dde58588..b8ecef66a8 100644 --- a/src/Microsoft.AspNet.Authentication.Twitter/TwitterAuthenticationHandler.cs +++ b/src/Microsoft.AspNet.Authentication.Twitter/TwitterHandler.cs @@ -20,7 +20,7 @@ using Microsoft.Framework.Primitives; namespace Microsoft.AspNet.Authentication.Twitter { - internal class TwitterAuthenticationHandler : AuthenticationHandler + internal class TwitterHandler : AuthenticationHandler { 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 diff --git a/src/Microsoft.AspNet.Authentication.Twitter/TwitterAuthenticationMiddleware.cs b/src/Microsoft.AspNet.Authentication.Twitter/TwitterMiddleware.cs similarity index 82% rename from src/Microsoft.AspNet.Authentication.Twitter/TwitterAuthenticationMiddleware.cs rename to src/Microsoft.AspNet.Authentication.Twitter/TwitterMiddleware.cs index ae8c118769..8a16dc09b2 100644 --- a/src/Microsoft.AspNet.Authentication.Twitter/TwitterAuthenticationMiddleware.cs +++ b/src/Microsoft.AspNet.Authentication.Twitter/TwitterMiddleware.cs @@ -18,12 +18,12 @@ namespace Microsoft.AspNet.Authentication.Twitter /// ASP.NET middleware for authenticating users using Twitter /// [SuppressMessage("Microsoft.Design", "CA1001:TypesThatOwnDisposableFieldsShouldBeDisposable", Justification = "Middleware are not disposable.")] - public class TwitterAuthenticationMiddleware : AuthenticationMiddleware + public class TwitterMiddleware : AuthenticationMiddleware { private readonly HttpClient _httpClient; /// - /// Initializes a + /// Initializes a /// /// The next middleware in the HTTP pipeline to invoke /// @@ -32,14 +32,14 @@ namespace Microsoft.AspNet.Authentication.Twitter /// /// Configuration options for the middleware /// - public TwitterAuthenticationMiddleware( + public TwitterMiddleware( [NotNull] RequestDelegate next, [NotNull] IDataProtectionProvider dataProtectionProvider, [NotNull] ILoggerFactory loggerFactory, [NotNull] IUrlEncoder encoder, [NotNull] IOptions sharedOptions, - [NotNull] IOptions options, - ConfigureOptions configureOptions = null) + [NotNull] IOptions options, + ConfigureOptions 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( Serializers.RequestToken, dataProtector, @@ -85,10 +85,10 @@ namespace Microsoft.AspNet.Authentication.Twitter /// /// Provides the object for processing authentication-related requests. /// - /// An configured with the supplied to the constructor. - protected override AuthenticationHandler CreateHandler() + /// An configured with the supplied to the constructor. + protected override AuthenticationHandler CreateHandler() { - return new TwitterAuthenticationHandler(_httpClient); + return new TwitterHandler(_httpClient); } } } diff --git a/src/Microsoft.AspNet.Authentication.Twitter/TwitterAuthenticationOptions.cs b/src/Microsoft.AspNet.Authentication.Twitter/TwitterOptions.cs similarity index 89% rename from src/Microsoft.AspNet.Authentication.Twitter/TwitterAuthenticationOptions.cs rename to src/Microsoft.AspNet.Authentication.Twitter/TwitterOptions.cs index dd075ea14b..ebc26fe2a9 100644 --- a/src/Microsoft.AspNet.Authentication.Twitter/TwitterAuthenticationOptions.cs +++ b/src/Microsoft.AspNet.Authentication.Twitter/TwitterOptions.cs @@ -10,14 +10,14 @@ namespace Microsoft.AspNet.Authentication.Twitter /// /// Options for the Twitter authentication middleware. /// - public class TwitterAuthenticationOptions : AuthenticationOptions + public class TwitterOptions : AuthenticationOptions { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// - 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 StateDataFormat { get; set; } /// - /// Gets or sets the used to handle authentication events. + /// Gets or sets the used to handle authentication events. /// - public ITwitterAuthenticationEvents Events { get; set; } + public ITwitterEvents Events { get; set; } /// /// Defines whether access tokens should be stored in the diff --git a/src/Microsoft.AspNet.Authentication.Twitter/TwitterServiceCollectionExtensions.cs b/src/Microsoft.AspNet.Authentication.Twitter/TwitterServiceCollectionExtensions.cs index 75dc1465fe..fdc48d26b8 100644 --- a/src/Microsoft.AspNet.Authentication.Twitter/TwitterServiceCollectionExtensions.cs +++ b/src/Microsoft.AspNet.Authentication.Twitter/TwitterServiceCollectionExtensions.cs @@ -9,18 +9,18 @@ using Microsoft.Framework.Internal; namespace Microsoft.Framework.DependencyInjection { /// - /// Extension methods for using + /// Extension methods for using /// public static class TwitterAuthenticationExtensions { - public static IServiceCollection AddTwitterAuthentication([NotNull] this IServiceCollection services, [NotNull] Action configure) + public static IServiceCollection AddTwitterAuthentication([NotNull] this IServiceCollection services, [NotNull] Action configure) { return services.Configure(configure); } public static IServiceCollection AddTwitterAuthentication([NotNull] this IServiceCollection services, [NotNull] IConfiguration config) { - return services.Configure(config); + return services.Configure(config); } } } diff --git a/src/Microsoft.AspNet.Authentication/ClaimsTransformationAuthenticationHandler.cs b/src/Microsoft.AspNet.Authentication/ClaimsTransformationAuthenticationHandler.cs index ebc04cb696..d5c4da165e 100644 --- a/src/Microsoft.AspNet.Authentication/ClaimsTransformationAuthenticationHandler.cs +++ b/src/Microsoft.AspNet.Authentication/ClaimsTransformationAuthenticationHandler.cs @@ -9,11 +9,11 @@ namespace Microsoft.AspNet.Authentication /// /// Handler that applies ClaimsTransformation to authentication /// - public class ClaimsTransformationAuthenticationHandler : IAuthenticationHandler + public class ClaimsTransformationHandler : IAuthenticationHandler { private readonly IClaimsTransformer _transform; - public ClaimsTransformationAuthenticationHandler(IClaimsTransformer transform) + public ClaimsTransformationHandler(IClaimsTransformer transform) { _transform = transform; } diff --git a/src/Microsoft.AspNet.Authentication/ClaimsTransformationMiddleware.cs b/src/Microsoft.AspNet.Authentication/ClaimsTransformationMiddleware.cs index 9d7af5b448..e72ab3ab12 100644 --- a/src/Microsoft.AspNet.Authentication/ClaimsTransformationMiddleware.cs +++ b/src/Microsoft.AspNet.Authentication/ClaimsTransformationMiddleware.cs @@ -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) diff --git a/test/Microsoft.AspNet.Authentication.Test/Cookies/CookieMiddlewareTests.cs b/test/Microsoft.AspNet.Authentication.Test/Cookies/CookieMiddlewareTests.cs index 686a7ce76e..4af812193f 100644 --- a/test/Microsoft.AspNet.Authentication.Test/Cookies/CookieMiddlewareTests.cs +++ b/test/Microsoft.AspNet.Authentication.Test/Cookies/CookieMiddlewareTests.cs @@ -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); diff --git a/test/Microsoft.AspNet.Authentication.Test/Facebook/FacebookMiddlewareTests.cs b/test/Microsoft.AspNet.Authentication.Test/Facebook/FacebookMiddlewareTests.cs index 22f9cfd8ce..03316722d2 100644 --- a/test/Microsoft.AspNet.Authentication.Test/Facebook/FacebookMiddlewareTests.cs +++ b/test/Microsoft.AspNet.Authentication.Test/Facebook/FacebookMiddlewareTests.cs @@ -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 diff --git a/test/Microsoft.AspNet.Authentication.Test/Google/GoogleMiddlewareTests.cs b/test/Microsoft.AspNet.Authentication.Test/Google/GoogleMiddlewareTests.cs index 4a35c55c77..97a6664456 100644 --- a/test/Microsoft.AspNet.Authentication.Test/Google/GoogleMiddlewareTests.cs +++ b/test/Microsoft.AspNet.Authentication.Test/Google/GoogleMiddlewareTests.cs @@ -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 configureOptions, Func testpath = null) + private static TestServer CreateServer(Action configureOptions, Func testpath = null) { return TestServer.Create(app => { diff --git a/test/Microsoft.AspNet.Authentication.Test/JwtBearer/JwtBearerMiddlewareTests.cs b/test/Microsoft.AspNet.Authentication.Test/JwtBearer/JwtBearerMiddlewareTests.cs index aebeb06170..89a37377b0 100644 --- a/test/Microsoft.AspNet.Authentication.Test/JwtBearer/JwtBearerMiddlewareTests.cs +++ b/test/Microsoft.AspNet.Authentication.Test/JwtBearer/JwtBearerMiddlewareTests.cs @@ -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 configureOptions, Func handler = null) + private static TestServer CreateServer(Action configureOptions, Func 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(() => context.Authentication.SignInAsync(JwtBearerAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal())); + await Assert.ThrowsAsync(() => context.Authentication.SignInAsync(JwtBearerDefaults.AuthenticationScheme, new ClaimsPrincipal())); } else if (context.Request.Path == new PathString("/signOut")) { - await Assert.ThrowsAsync(() => context.Authentication.SignOutAsync(JwtBearerAuthenticationDefaults.AuthenticationScheme)); + await Assert.ThrowsAsync(() => context.Authentication.SignOutAsync(JwtBearerDefaults.AuthenticationScheme)); } else { diff --git a/test/Microsoft.AspNet.Authentication.Test/MicrosoftAccount/MicrosoftAccountMiddlewareTests.cs b/test/Microsoft.AspNet.Authentication.Test/MicrosoftAccount/MicrosoftAccountMiddlewareTests.cs index 42c6a8cd3c..33a58bca43 100644 --- a/test/Microsoft.AspNet.Authentication.Test/MicrosoftAccount/MicrosoftAccountMiddlewareTests.cs +++ b/test/Microsoft.AspNet.Authentication.Test/MicrosoftAccount/MicrosoftAccountMiddlewareTests.cs @@ -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 configureOptions) + private static TestServer CreateServer(Action configureOptions) { return TestServer.Create(app => { diff --git a/test/Microsoft.AspNet.Authentication.Test/OpenIdConnect/OpenIdConnectAuthenticationHandlerForTestingAuthenticate.cs b/test/Microsoft.AspNet.Authentication.Test/OpenIdConnect/OpenIdConnectHandlerForTestingAuthenticate.cs similarity index 90% rename from test/Microsoft.AspNet.Authentication.Test/OpenIdConnect/OpenIdConnectAuthenticationHandlerForTestingAuthenticate.cs rename to test/Microsoft.AspNet.Authentication.Test/OpenIdConnect/OpenIdConnectHandlerForTestingAuthenticate.cs index bf6d128c5e..2fbab74cff 100644 --- a/test/Microsoft.AspNet.Authentication.Test/OpenIdConnect/OpenIdConnectAuthenticationHandlerForTestingAuthenticate.cs +++ b/test/Microsoft.AspNet.Authentication.Test/OpenIdConnect/OpenIdConnectHandlerForTestingAuthenticate.cs @@ -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 /// /// Allows for custom processing of ApplyResponseChallenge, ApplyResponseGrant and AuthenticateCore /// - public class OpenIdConnectAuthenticationHandlerForTestingAuthenticate : OpenIdConnectAuthenticationHandler + public class OpenIdConnectHandlerForTestingAuthenticate : OpenIdConnectHandler { - public OpenIdConnectAuthenticationHandlerForTestingAuthenticate() + public OpenIdConnectHandlerForTestingAuthenticate() : base(null) { } diff --git a/test/Microsoft.AspNet.Authentication.Test/OpenIdConnect/OpenIdConnectHandlerTests.cs b/test/Microsoft.AspNet.Authentication.Test/OpenIdConnect/OpenIdConnectHandlerTests.cs index d0914fc8ad..1d5741478a 100644 --- a/test/Microsoft.AspNet.Authentication.Test/OpenIdConnect/OpenIdConnectHandlerTests.cs +++ b/test/Microsoft.AspNet.Authentication.Test/OpenIdConnect/OpenIdConnectHandlerTests.cs @@ -58,20 +58,20 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect } [Theory, MemberData("AuthenticateCoreStateDataSet")] - public async Task AuthenticateCoreState(Action action, OpenIdConnectMessage message) + public async Task AuthenticateCoreState(Action action, OpenIdConnectMessage message) { - var handler = new OpenIdConnectAuthenticationHandlerForTestingAuthenticate(); - var server = CreateServer(new ConfigureOptions(action), UrlEncoder.Default, handler); + var handler = new OpenIdConnectHandlerForTestingAuthenticate(); + var server = CreateServer(new ConfigureOptions(action), UrlEncoder.Default, handler); await server.CreateClient().PostAsync("http://localhost", new FormUrlEncodedContent(message.Parameters.Where(pair => pair.Value != null))); } - public static TheoryData, OpenIdConnectMessage> AuthenticateCoreStateDataSet + public static TheoryData, OpenIdConnectMessage> AuthenticateCoreStateDataSet { get { var formater = new AuthenticationPropertiesFormaterKeyValue(); var properties = new AuthenticationProperties(); - var dataset = new TheoryData, OpenIdConnectMessage>(); + var dataset = new TheoryData, 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(); @@ -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(); @@ -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 options, IUrlEncoder encoder, OpenIdConnectAuthenticationHandler handler = null) + private static TestServer CreateServer(ConfigureOptions options, IUrlEncoder encoder, OpenIdConnectHandler handler = null) { return TestServer.Create( app => { - app.UseMiddleware(options, encoder, handler); + app.UseMiddleware(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 configureOptions, IUrlEncoder encoder, ILoggerFactory loggerFactory, OpenIdConnectAuthenticationHandler handler = null) + private static TestServer CreateServer(ConfigureOptions configureOptions, IUrlEncoder encoder, ILoggerFactory loggerFactory, OpenIdConnectHandler handler = null) { return TestServer.Create( app => { - app.UseMiddleware(configureOptions, encoder, loggerFactory, handler); + app.UseMiddleware(configureOptions, encoder, loggerFactory, handler); app.Use(async (context, next) => { await next(); diff --git a/test/Microsoft.AspNet.Authentication.Test/OpenIdConnect/OpenIdConnectAuthenticationMiddlewareForTestingAuthenticate.cs b/test/Microsoft.AspNet.Authentication.Test/OpenIdConnect/OpenIdConnectMiddlewareForTestingAuthenticate.cs similarity index 66% rename from test/Microsoft.AspNet.Authentication.Test/OpenIdConnect/OpenIdConnectAuthenticationMiddlewareForTestingAuthenticate.cs rename to test/Microsoft.AspNet.Authentication.Test/OpenIdConnect/OpenIdConnectMiddlewareForTestingAuthenticate.cs index 80a17c12b7..e76c213259 100644 --- a/test/Microsoft.AspNet.Authentication.Test/OpenIdConnect/OpenIdConnectAuthenticationMiddlewareForTestingAuthenticate.cs +++ b/test/Microsoft.AspNet.Authentication.Test/OpenIdConnect/OpenIdConnectMiddlewareForTestingAuthenticate.cs @@ -13,23 +13,23 @@ namespace Microsoft.AspNet.Authentication.Tests.OpenIdConnect { /// - /// pass a as the AuthenticationHandler + /// pass a as the AuthenticationHandler /// configured to handle certain messages. /// - 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 sharedOptions, - IOptions options, - ConfigureOptions configureOptions = null, - OpenIdConnectAuthenticationHandler handler = null + IOptions options, + ConfigureOptions 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 CreateHandler() + protected override AuthenticationHandler CreateHandler() { return _handler ?? base.CreateHandler(); } diff --git a/test/Microsoft.AspNet.Authentication.Test/OpenIdConnect/OpenIdConnectMiddlewareTests.cs b/test/Microsoft.AspNet.Authentication.Test/OpenIdConnect/OpenIdConnectMiddlewareTests.cs index 71fc4c855f..8e2c4ba7d8 100644 --- a/test/Microsoft.AspNet.Authentication.Test/OpenIdConnect/OpenIdConnectMiddlewareTests.cs +++ b/test/Microsoft.AspNet.Authentication.Test/OpenIdConnect/OpenIdConnectMiddlewareTests.cs @@ -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(); 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 parameters, ExpectedQueryValues queryValues, ISecureDataFormat secureDataFormat = null) + private void SetOptions(OpenIdConnectOptions options, List parameters, ExpectedQueryValues queryValues, ISecureDataFormat 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 configureOptions, Func handler = null, AuthenticationProperties properties = null) + private static TestServer CreateServer(Action configureOptions, Func 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) diff --git a/test/Microsoft.AspNet.Authentication.Test/Twitter/TwitterMiddlewareTests.cs b/test/Microsoft.AspNet.Authentication.Test/Twitter/TwitterMiddlewareTests.cs index 33531ba058..b8c2a1a72e 100644 --- a/test/Microsoft.AspNet.Authentication.Test/Twitter/TwitterMiddlewareTests.cs +++ b/test/Microsoft.AspNet.Authentication.Test/Twitter/TwitterMiddlewareTests.cs @@ -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 configure, Func handler = null) + private static TestServer CreateServer(Action configure, Func handler = null) { return TestServer.Create(app => {