From 95f19407fc0a3f4c49f8ad618d8a3452b3474ee4 Mon Sep 17 00:00:00 2001 From: Chris Ross Date: Tue, 21 Oct 2014 14:00:49 -0700 Subject: [PATCH] #74 - Clean up data protection provider helper. --- .../CookieSessionSample/MemoryCacheSessionStore.cs | 2 +- .../CookieAuthenticationMiddleware.cs | 2 +- .../OAuthAuthenticationMiddleware.cs | 2 +- .../OAuthBearerAuthenticationMiddleware.cs | 2 +- .../TwitterAuthenticationMiddleware.cs | 2 +- .../DataProtection/DataProtectionHelpers.cs | 12 +----------- 6 files changed, 6 insertions(+), 16 deletions(-) diff --git a/samples/CookieSessionSample/MemoryCacheSessionStore.cs b/samples/CookieSessionSample/MemoryCacheSessionStore.cs index e452683d41..9877ded68d 100644 --- a/samples/CookieSessionSample/MemoryCacheSessionStore.cs +++ b/samples/CookieSessionSample/MemoryCacheSessionStore.cs @@ -13,7 +13,7 @@ namespace CookieSessionSample public MemoryCacheSessionStore() { - _cache = new MemoryCache(); + _cache = new MemoryCache(new MemoryCacheOptions()); } public async Task StoreAsync(AuthenticationTicket ticket) diff --git a/src/Microsoft.AspNet.Security.Cookies/CookieAuthenticationMiddleware.cs b/src/Microsoft.AspNet.Security.Cookies/CookieAuthenticationMiddleware.cs index fdbd3cc081..482f43b373 100644 --- a/src/Microsoft.AspNet.Security.Cookies/CookieAuthenticationMiddleware.cs +++ b/src/Microsoft.AspNet.Security.Cookies/CookieAuthenticationMiddleware.cs @@ -35,7 +35,7 @@ namespace Microsoft.AspNet.Security.Cookies } if (Options.TicketDataFormat == null) { - IDataProtector dataProtector = DataProtectionHelpers.CreateDataProtector(dataProtectionProvider, + IDataProtector dataProtector = dataProtectionProvider.CreateDataProtector( typeof(CookieAuthenticationMiddleware).FullName, Options.AuthenticationType, "v1"); Options.TicketDataFormat = new TicketDataFormat(dataProtector); } diff --git a/src/Microsoft.AspNet.Security.OAuth/OAuthAuthenticationMiddleware.cs b/src/Microsoft.AspNet.Security.OAuth/OAuthAuthenticationMiddleware.cs index 1f9eace704..2628d38491 100644 --- a/src/Microsoft.AspNet.Security.OAuth/OAuthAuthenticationMiddleware.cs +++ b/src/Microsoft.AspNet.Security.OAuth/OAuthAuthenticationMiddleware.cs @@ -66,7 +66,7 @@ namespace Microsoft.AspNet.Security.OAuth if (Options.StateDataFormat == null) { - IDataProtector dataProtector = DataProtectionHelpers.CreateDataProtector(dataProtectionProvider, + IDataProtector dataProtector = dataProtectionProvider.CreateDataProtector( this.GetType().FullName, Options.AuthenticationType, "v1"); Options.StateDataFormat = new PropertiesDataFormat(dataProtector); } diff --git a/src/Microsoft.AspNet.Security.OAuth/OAuthBearerAuthenticationMiddleware.cs b/src/Microsoft.AspNet.Security.OAuth/OAuthBearerAuthenticationMiddleware.cs index eaa862a280..0661c4fede 100644 --- a/src/Microsoft.AspNet.Security.OAuth/OAuthBearerAuthenticationMiddleware.cs +++ b/src/Microsoft.AspNet.Security.OAuth/OAuthBearerAuthenticationMiddleware.cs @@ -58,7 +58,7 @@ namespace Microsoft.AspNet.Security.OAuth if (Options.AccessTokenFormat == null) { - var dataProtector = DataProtectionHelpers.CreateDataProtector(dataProtectionProvider, + IDataProtector dataProtector = dataProtectionProvider.CreateDataProtector( this.GetType().FullName, Options.AuthenticationType, "v1"); Options.AccessTokenFormat = new TicketDataFormat(dataProtector); } diff --git a/src/Microsoft.AspNet.Security.Twitter/TwitterAuthenticationMiddleware.cs b/src/Microsoft.AspNet.Security.Twitter/TwitterAuthenticationMiddleware.cs index e3a56efab5..6c4204a4b6 100644 --- a/src/Microsoft.AspNet.Security.Twitter/TwitterAuthenticationMiddleware.cs +++ b/src/Microsoft.AspNet.Security.Twitter/TwitterAuthenticationMiddleware.cs @@ -60,7 +60,7 @@ namespace Microsoft.AspNet.Security.Twitter } if (Options.StateDataFormat == null) { - IDataProtector dataProtector = DataProtectionHelpers.CreateDataProtector(dataProtectionProvider, + IDataProtector dataProtector = dataProtectionProvider.CreateDataProtector( typeof(TwitterAuthenticationMiddleware).FullName, Options.AuthenticationType, "v1"); Options.StateDataFormat = new SecureDataFormat( Serializers.RequestToken, diff --git a/src/Microsoft.AspNet.Security/DataProtection/DataProtectionHelpers.cs b/src/Microsoft.AspNet.Security/DataProtection/DataProtectionHelpers.cs index eba80e708a..986bc8dc80 100644 --- a/src/Microsoft.AspNet.Security/DataProtection/DataProtectionHelpers.cs +++ b/src/Microsoft.AspNet.Security/DataProtection/DataProtectionHelpers.cs @@ -1,22 +1,12 @@ // 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.Http; - namespace Microsoft.AspNet.Security.DataProtection { public static class DataProtectionHelpers { - public static IDataProtector CreateDataProtector(IDataProtectionProvider dataProtectionProvider, params string[] purposes) + public static IDataProtector CreateDataProtector([NotNull] this IDataProtectionProvider dataProtectionProvider, params string[] purposes) { - if (dataProtectionProvider == null) - { - // TODO: Get this from the environment. - dataProtectionProvider = new EphemeralDataProtectionProvider(); - } - return dataProtectionProvider.CreateProtector(string.Join(";", purposes)); } }