#74 - Clean up data protection provider helper.
This commit is contained in:
parent
2c64ebdbc2
commit
95f19407fc
|
|
@ -13,7 +13,7 @@ namespace CookieSessionSample
|
||||||
|
|
||||||
public MemoryCacheSessionStore()
|
public MemoryCacheSessionStore()
|
||||||
{
|
{
|
||||||
_cache = new MemoryCache();
|
_cache = new MemoryCache(new MemoryCacheOptions());
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<string> StoreAsync(AuthenticationTicket ticket)
|
public async Task<string> StoreAsync(AuthenticationTicket ticket)
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ namespace Microsoft.AspNet.Security.Cookies
|
||||||
}
|
}
|
||||||
if (Options.TicketDataFormat == null)
|
if (Options.TicketDataFormat == null)
|
||||||
{
|
{
|
||||||
IDataProtector dataProtector = DataProtectionHelpers.CreateDataProtector(dataProtectionProvider,
|
IDataProtector dataProtector = dataProtectionProvider.CreateDataProtector(
|
||||||
typeof(CookieAuthenticationMiddleware).FullName, Options.AuthenticationType, "v1");
|
typeof(CookieAuthenticationMiddleware).FullName, Options.AuthenticationType, "v1");
|
||||||
Options.TicketDataFormat = new TicketDataFormat(dataProtector);
|
Options.TicketDataFormat = new TicketDataFormat(dataProtector);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -66,7 +66,7 @@ namespace Microsoft.AspNet.Security.OAuth
|
||||||
|
|
||||||
if (Options.StateDataFormat == null)
|
if (Options.StateDataFormat == null)
|
||||||
{
|
{
|
||||||
IDataProtector dataProtector = DataProtectionHelpers.CreateDataProtector(dataProtectionProvider,
|
IDataProtector dataProtector = dataProtectionProvider.CreateDataProtector(
|
||||||
this.GetType().FullName, Options.AuthenticationType, "v1");
|
this.GetType().FullName, Options.AuthenticationType, "v1");
|
||||||
Options.StateDataFormat = new PropertiesDataFormat(dataProtector);
|
Options.StateDataFormat = new PropertiesDataFormat(dataProtector);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,7 @@ namespace Microsoft.AspNet.Security.OAuth
|
||||||
|
|
||||||
if (Options.AccessTokenFormat == null)
|
if (Options.AccessTokenFormat == null)
|
||||||
{
|
{
|
||||||
var dataProtector = DataProtectionHelpers.CreateDataProtector(dataProtectionProvider,
|
IDataProtector dataProtector = dataProtectionProvider.CreateDataProtector(
|
||||||
this.GetType().FullName, Options.AuthenticationType, "v1");
|
this.GetType().FullName, Options.AuthenticationType, "v1");
|
||||||
Options.AccessTokenFormat = new TicketDataFormat(dataProtector);
|
Options.AccessTokenFormat = new TicketDataFormat(dataProtector);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,7 @@ namespace Microsoft.AspNet.Security.Twitter
|
||||||
}
|
}
|
||||||
if (Options.StateDataFormat == null)
|
if (Options.StateDataFormat == null)
|
||||||
{
|
{
|
||||||
IDataProtector dataProtector = DataProtectionHelpers.CreateDataProtector(dataProtectionProvider,
|
IDataProtector dataProtector = dataProtectionProvider.CreateDataProtector(
|
||||||
typeof(TwitterAuthenticationMiddleware).FullName, Options.AuthenticationType, "v1");
|
typeof(TwitterAuthenticationMiddleware).FullName, Options.AuthenticationType, "v1");
|
||||||
Options.StateDataFormat = new SecureDataFormat<RequestToken>(
|
Options.StateDataFormat = new SecureDataFormat<RequestToken>(
|
||||||
Serializers.RequestToken,
|
Serializers.RequestToken,
|
||||||
|
|
|
||||||
|
|
@ -1,22 +1,12 @@
|
||||||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
|
// 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.
|
// 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
|
namespace Microsoft.AspNet.Security.DataProtection
|
||||||
{
|
{
|
||||||
public static class DataProtectionHelpers
|
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));
|
return dataProtectionProvider.CreateProtector(string.Join(";", purposes));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue