From aacc00aaeefb64279edb4b00482fa1b6dcd6fa6c Mon Sep 17 00:00:00 2001 From: Hao Kung Date: Thu, 5 Mar 2015 16:04:57 -0800 Subject: [PATCH] Move extension methods to proper namespaces Also add sugar for OpenIdConnect Fixes https://github.com/aspnet/Security/issues/107 Fixes https://github.com/aspnet/Security/issues/113 --- ...sions.cs => CookieAppBuilderExtensions.cs} | 8 +------- .../CookieServiceCollectionExtensions.cs | 20 +++++++++++++++++++ ...ons.cs => FacebookAppBuilderExtensions.cs} | 12 +++-------- .../FacebookServiceCollectionExtensions.cs | 20 +++++++++++++++++++ ...sions.cs => GoogleAppBuilderExtensions.cs} | 12 +++-------- .../GoogleServiceCollectionExtensions.cs | 19 ++++++++++++++++++ ...> MicrosoftAccountAppBuilderExtensions.cs} | 6 ------ ...osoftAccountServiceCollectionExtensions.cs | 19 ++++++++++++++++++ ....cs => OAuthBearerAppBuilderExtensions.cs} | 8 +------- .../OAuthBearerServiceCollectionExtensions.cs | 19 ++++++++++++++++++ ...penIdConnectServiceCollectionExtensions.cs | 19 ++++++++++++++++++ ...ions.cs => TwitterAppBuilderExtensions.cs} | 13 +++--------- .../TwitterServiceCollectionExtensions.cs | 19 ++++++++++++++++++ .../Twitter/TwitterMiddlewareTests.cs | 5 ----- 14 files changed, 146 insertions(+), 53 deletions(-) rename src/Microsoft.AspNet.Authentication.Cookies/{CookieAuthenticationExtensions.cs => CookieAppBuilderExtensions.cs} (80%) create mode 100644 src/Microsoft.AspNet.Authentication.Cookies/CookieServiceCollectionExtensions.cs rename src/Microsoft.AspNet.Authentication.Facebook/{FacebookAuthenticationExtensions.cs => FacebookAppBuilderExtensions.cs} (77%) create mode 100644 src/Microsoft.AspNet.Authentication.Facebook/FacebookServiceCollectionExtensions.cs rename src/Microsoft.AspNet.Authentication.Google/{GoogleAuthenticationExtensions.cs => GoogleAppBuilderExtensions.cs} (79%) create mode 100644 src/Microsoft.AspNet.Authentication.Google/GoogleServiceCollectionExtensions.cs rename src/Microsoft.AspNet.Authentication.MicrosoftAccount/{MicrosoftAccountAuthenticationExtensions.cs => MicrosoftAccountAppBuilderExtensions.cs} (77%) create mode 100644 src/Microsoft.AspNet.Authentication.MicrosoftAccount/MicrosoftAccountServiceCollectionExtensions.cs rename src/Microsoft.AspNet.Authentication.OAuthBearer/{OAuthBearerAuthenticationExtensions.cs => OAuthBearerAppBuilderExtensions.cs} (83%) create mode 100644 src/Microsoft.AspNet.Authentication.OAuthBearer/OAuthBearerServiceCollectionExtensions.cs create mode 100644 src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectServiceCollectionExtensions.cs rename src/Microsoft.AspNet.Authentication.Twitter/{TwitterAuthenticationExtensions.cs => TwitterAppBuilderExtensions.cs} (70%) create mode 100644 src/Microsoft.AspNet.Authentication.Twitter/TwitterServiceCollectionExtensions.cs diff --git a/src/Microsoft.AspNet.Authentication.Cookies/CookieAuthenticationExtensions.cs b/src/Microsoft.AspNet.Authentication.Cookies/CookieAppBuilderExtensions.cs similarity index 80% rename from src/Microsoft.AspNet.Authentication.Cookies/CookieAuthenticationExtensions.cs rename to src/Microsoft.AspNet.Authentication.Cookies/CookieAppBuilderExtensions.cs index 08f4cc71a6..5a00ca2341 100644 --- a/src/Microsoft.AspNet.Authentication.Cookies/CookieAuthenticationExtensions.cs +++ b/src/Microsoft.AspNet.Authentication.Cookies/CookieAppBuilderExtensions.cs @@ -3,7 +3,6 @@ using System; using Microsoft.AspNet.Authentication.Cookies; -using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.OptionsModel; namespace Microsoft.AspNet.Builder @@ -11,13 +10,8 @@ namespace Microsoft.AspNet.Builder /// /// Extension methods provided by the cookies authentication middleware /// - public static class CookieAuthenticationExtensions + public static class CookieAppBuilderExtensions { - public static IServiceCollection ConfigureCookieAuthentication([NotNull] this IServiceCollection services, [NotNull] Action configure) - { - return services.Configure(configure); - } - /// /// Adds a cookie-based authentication middleware to your web application pipeline. /// diff --git a/src/Microsoft.AspNet.Authentication.Cookies/CookieServiceCollectionExtensions.cs b/src/Microsoft.AspNet.Authentication.Cookies/CookieServiceCollectionExtensions.cs new file mode 100644 index 0000000000..476dc948fa --- /dev/null +++ b/src/Microsoft.AspNet.Authentication.Cookies/CookieServiceCollectionExtensions.cs @@ -0,0 +1,20 @@ +// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using Microsoft.AspNet.Authentication.Cookies; +using Microsoft.Framework.DependencyInjection; + +namespace Microsoft.Framework.DependencyInjection +{ + /// + /// Extension methods provided by the cookies authentication middleware + /// + public static class CookieServiceCollectionExtensions + { + public static IServiceCollection ConfigureCookieAuthentication([NotNull] this IServiceCollection services, [NotNull] Action configure) + { + return services.Configure(configure); + } + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Authentication.Facebook/FacebookAuthenticationExtensions.cs b/src/Microsoft.AspNet.Authentication.Facebook/FacebookAppBuilderExtensions.cs similarity index 77% rename from src/Microsoft.AspNet.Authentication.Facebook/FacebookAuthenticationExtensions.cs rename to src/Microsoft.AspNet.Authentication.Facebook/FacebookAppBuilderExtensions.cs index 3664bb592b..c91855790c 100644 --- a/src/Microsoft.AspNet.Authentication.Facebook/FacebookAuthenticationExtensions.cs +++ b/src/Microsoft.AspNet.Authentication.Facebook/FacebookAppBuilderExtensions.cs @@ -1,23 +1,17 @@ // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.AspNet.Authentication.Facebook; -using Microsoft.Framework.DependencyInjection; -using Microsoft.Framework.OptionsModel; using System; +using Microsoft.AspNet.Authentication.Facebook; +using Microsoft.Framework.OptionsModel; namespace Microsoft.AspNet.Builder { /// /// Extension methods for using . /// - public static class FacebookAuthenticationExtensions + public static class FacebookAppBuilderExtensions { - public static IServiceCollection ConfigureFacebookAuthentication([NotNull] this IServiceCollection services, [NotNull] Action configure) - { - return services.Configure(configure); - } - /// /// Authenticate users using Facebook. /// diff --git a/src/Microsoft.AspNet.Authentication.Facebook/FacebookServiceCollectionExtensions.cs b/src/Microsoft.AspNet.Authentication.Facebook/FacebookServiceCollectionExtensions.cs new file mode 100644 index 0000000000..8d044dd40a --- /dev/null +++ b/src/Microsoft.AspNet.Authentication.Facebook/FacebookServiceCollectionExtensions.cs @@ -0,0 +1,20 @@ +// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using Microsoft.AspNet.Authentication.Facebook; +using Microsoft.Framework.OptionsModel; +using System; + +namespace Microsoft.Framework.DependencyInjection +{ + /// + /// Extension methods for using . + /// + public static class FacebookServiceCollectionExtensions + { + public static IServiceCollection ConfigureFacebookAuthentication([NotNull] this IServiceCollection services, [NotNull] Action configure) + { + return services.Configure(configure); + } + } +} diff --git a/src/Microsoft.AspNet.Authentication.Google/GoogleAuthenticationExtensions.cs b/src/Microsoft.AspNet.Authentication.Google/GoogleAppBuilderExtensions.cs similarity index 79% rename from src/Microsoft.AspNet.Authentication.Google/GoogleAuthenticationExtensions.cs rename to src/Microsoft.AspNet.Authentication.Google/GoogleAppBuilderExtensions.cs index fd46b062a9..8613d4368f 100644 --- a/src/Microsoft.AspNet.Authentication.Google/GoogleAuthenticationExtensions.cs +++ b/src/Microsoft.AspNet.Authentication.Google/GoogleAppBuilderExtensions.cs @@ -1,23 +1,17 @@ // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.AspNet.Authentication.Google; -using Microsoft.Framework.DependencyInjection; -using Microsoft.Framework.OptionsModel; using System; +using Microsoft.AspNet.Authentication.Google; +using Microsoft.Framework.OptionsModel; namespace Microsoft.AspNet.Builder { /// /// Extension methods for using . /// - public static class GoogleAuthenticationExtensions + public static class GoogleAppBuilderExtensions { - public static IServiceCollection ConfigureGoogleAuthentication([NotNull] this IServiceCollection services, [NotNull] Action configure) - { - return services.Configure(configure); - } - /// /// Authenticate users using Google OAuth 2.0. /// diff --git a/src/Microsoft.AspNet.Authentication.Google/GoogleServiceCollectionExtensions.cs b/src/Microsoft.AspNet.Authentication.Google/GoogleServiceCollectionExtensions.cs new file mode 100644 index 0000000000..a5a8b4b508 --- /dev/null +++ b/src/Microsoft.AspNet.Authentication.Google/GoogleServiceCollectionExtensions.cs @@ -0,0 +1,19 @@ +// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using Microsoft.AspNet.Authentication.Google; + +namespace Microsoft.Framework.DependencyInjection +{ + /// + /// Extension methods for using . + /// + public static class GoogleServiceCollectionExtensions + { + public static IServiceCollection ConfigureGoogleAuthentication([NotNull] this IServiceCollection services, [NotNull] Action configure) + { + return services.Configure(configure); + } + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Authentication.MicrosoftAccount/MicrosoftAccountAuthenticationExtensions.cs b/src/Microsoft.AspNet.Authentication.MicrosoftAccount/MicrosoftAccountAppBuilderExtensions.cs similarity index 77% rename from src/Microsoft.AspNet.Authentication.MicrosoftAccount/MicrosoftAccountAuthenticationExtensions.cs rename to src/Microsoft.AspNet.Authentication.MicrosoftAccount/MicrosoftAccountAppBuilderExtensions.cs index 397a1b32b5..e068b5f5a1 100644 --- a/src/Microsoft.AspNet.Authentication.MicrosoftAccount/MicrosoftAccountAuthenticationExtensions.cs +++ b/src/Microsoft.AspNet.Authentication.MicrosoftAccount/MicrosoftAccountAppBuilderExtensions.cs @@ -2,7 +2,6 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.AspNet.Authentication.MicrosoftAccount; -using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.OptionsModel; using System; @@ -13,11 +12,6 @@ namespace Microsoft.AspNet.Builder /// public static class MicrosoftAccountAuthenticationExtensions { - public static IServiceCollection ConfigureMicrosoftAccountAuthentication([NotNull] this IServiceCollection services, [NotNull] Action configure) - { - return services.Configure(configure); - } - public static IApplicationBuilder UseMicrosoftAccountAuthentication([NotNull] this IApplicationBuilder app, Action configureOptions = null, string optionsName = "") { return app.UseMiddleware( diff --git a/src/Microsoft.AspNet.Authentication.MicrosoftAccount/MicrosoftAccountServiceCollectionExtensions.cs b/src/Microsoft.AspNet.Authentication.MicrosoftAccount/MicrosoftAccountServiceCollectionExtensions.cs new file mode 100644 index 0000000000..b3e1e11103 --- /dev/null +++ b/src/Microsoft.AspNet.Authentication.MicrosoftAccount/MicrosoftAccountServiceCollectionExtensions.cs @@ -0,0 +1,19 @@ +// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using Microsoft.AspNet.Authentication.MicrosoftAccount; + +namespace Microsoft.Framework.DependencyInjection +{ + /// + /// Extension methods for using + /// + public static class MicrosoftAccountServiceCollectionExtensions + { + public static IServiceCollection ConfigureMicrosoftAccountAuthentication([NotNull] this IServiceCollection services, [NotNull] Action configure) + { + return services.Configure(configure); + } + } +} diff --git a/src/Microsoft.AspNet.Authentication.OAuthBearer/OAuthBearerAuthenticationExtensions.cs b/src/Microsoft.AspNet.Authentication.OAuthBearer/OAuthBearerAppBuilderExtensions.cs similarity index 83% rename from src/Microsoft.AspNet.Authentication.OAuthBearer/OAuthBearerAuthenticationExtensions.cs rename to src/Microsoft.AspNet.Authentication.OAuthBearer/OAuthBearerAppBuilderExtensions.cs index b1a6293341..88151eb160 100644 --- a/src/Microsoft.AspNet.Authentication.OAuthBearer/OAuthBearerAuthenticationExtensions.cs +++ b/src/Microsoft.AspNet.Authentication.OAuthBearer/OAuthBearerAppBuilderExtensions.cs @@ -3,7 +3,6 @@ using System; using Microsoft.AspNet.Authentication.OAuthBearer; -using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.OptionsModel; namespace Microsoft.AspNet.Builder @@ -11,13 +10,8 @@ namespace Microsoft.AspNet.Builder /// /// Extension methods to add OAuth Bearer authentication capabilities to an HTTP application pipeline /// - public static class OAuthBearerAuthenticationExtensions + public static class OAuthBearerAppBuilderExtensions { - public static IServiceCollection ConfigureOAuthBearerAuthentication([NotNull] this IServiceCollection services, [NotNull] Action configure) - { - return services.ConfigureOptions(configure); - } - /// /// Adds Bearer token processing to an HTTP application pipeline. This middleware understands appropriately /// formatted and secured tokens which appear in the request header. If the Options.AuthenticationMode is Active, the diff --git a/src/Microsoft.AspNet.Authentication.OAuthBearer/OAuthBearerServiceCollectionExtensions.cs b/src/Microsoft.AspNet.Authentication.OAuthBearer/OAuthBearerServiceCollectionExtensions.cs new file mode 100644 index 0000000000..5a878dcbb1 --- /dev/null +++ b/src/Microsoft.AspNet.Authentication.OAuthBearer/OAuthBearerServiceCollectionExtensions.cs @@ -0,0 +1,19 @@ +// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using Microsoft.AspNet.Authentication.OAuthBearer; + +namespace Microsoft.Framework.DependencyInjection +{ + /// + /// Extension methods to add OAuth Bearer authentication capabilities to an HTTP application pipeline + /// + public static class OAuthBearerServiceCollectionExtensions + { + public static IServiceCollection ConfigureOAuthBearerAuthentication([NotNull] this IServiceCollection services, [NotNull] Action configure) + { + return services.ConfigureOptions(configure); + } + } +} diff --git a/src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectServiceCollectionExtensions.cs b/src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectServiceCollectionExtensions.cs new file mode 100644 index 0000000000..390568fd3b --- /dev/null +++ b/src/Microsoft.AspNet.Authentication.OpenIdConnect/OpenIdConnectServiceCollectionExtensions.cs @@ -0,0 +1,19 @@ +// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using Microsoft.AspNet.Authentication.OpenIdConnect; + +namespace Microsoft.Framework.DependencyInjection +{ + /// + /// Extension methods to configure OpenIdConnect authentication options + /// + public static class OpenIdConnectServiceCollectionExtensions + { + public static IServiceCollection ConfigureOpenIdConnect(this IServiceCollection services, Action configure) + { + return services.ConfigureOptions(configure); + } + } +} diff --git a/src/Microsoft.AspNet.Authentication.Twitter/TwitterAuthenticationExtensions.cs b/src/Microsoft.AspNet.Authentication.Twitter/TwitterAppBuilderExtensions.cs similarity index 70% rename from src/Microsoft.AspNet.Authentication.Twitter/TwitterAuthenticationExtensions.cs rename to src/Microsoft.AspNet.Authentication.Twitter/TwitterAppBuilderExtensions.cs index bff1897923..ce27cdadf2 100644 --- a/src/Microsoft.AspNet.Authentication.Twitter/TwitterAuthenticationExtensions.cs +++ b/src/Microsoft.AspNet.Authentication.Twitter/TwitterAppBuilderExtensions.cs @@ -1,24 +1,17 @@ // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.AspNet.Authentication; -using Microsoft.AspNet.Authentication.Twitter; -using Microsoft.Framework.DependencyInjection; -using Microsoft.Framework.OptionsModel; using System; +using Microsoft.AspNet.Authentication.Twitter; +using Microsoft.Framework.OptionsModel; namespace Microsoft.AspNet.Builder { /// /// Extension methods for using /// - public static class TwitterAuthenticationExtensions + public static class TwitterAppBuilderExtensions { - public static IServiceCollection ConfigureTwitterAuthentication([NotNull] this IServiceCollection services, [NotNull] Action configure) - { - return services.Configure(configure); - } - public static IApplicationBuilder UseTwitterAuthentication([NotNull] this IApplicationBuilder app, Action configureOptions = null, string optionsName = "") { return app.UseMiddleware( diff --git a/src/Microsoft.AspNet.Authentication.Twitter/TwitterServiceCollectionExtensions.cs b/src/Microsoft.AspNet.Authentication.Twitter/TwitterServiceCollectionExtensions.cs new file mode 100644 index 0000000000..7c25c17377 --- /dev/null +++ b/src/Microsoft.AspNet.Authentication.Twitter/TwitterServiceCollectionExtensions.cs @@ -0,0 +1,19 @@ +// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using Microsoft.AspNet.Authentication.Twitter; + +namespace Microsoft.Framework.DependencyInjection +{ + /// + /// Extension methods for using + /// + public static class TwitterAuthenticationExtensions + { + public static IServiceCollection ConfigureTwitterAuthentication([NotNull] this IServiceCollection services, [NotNull] Action configure) + { + return services.Configure(configure); + } + } +} diff --git a/test/Microsoft.AspNet.Authentication.Test/Twitter/TwitterMiddlewareTests.cs b/test/Microsoft.AspNet.Authentication.Test/Twitter/TwitterMiddlewareTests.cs index 6b54b6cd94..fd281086fc 100644 --- a/test/Microsoft.AspNet.Authentication.Test/Twitter/TwitterMiddlewareTests.cs +++ b/test/Microsoft.AspNet.Authentication.Test/Twitter/TwitterMiddlewareTests.cs @@ -8,14 +8,9 @@ using System.Net.Http; using System.Text; using System.Threading.Tasks; using Microsoft.AspNet.Builder; -using Microsoft.AspNet.DataProtection; using Microsoft.AspNet.Http; -using Microsoft.AspNet.Authentication.Cookies; -using Microsoft.AspNet.Authentication.Twitter; using Microsoft.AspNet.TestHost; using Microsoft.Framework.DependencyInjection; -using Microsoft.Framework.OptionsModel; -using Newtonsoft.Json; using Shouldly; using Xunit;