diff options
author | Andrew Arnott <andrewarnott@gmail.com> | 2011-05-09 07:43:15 -0700 |
---|---|---|
committer | Andrew Arnott <andrewarnott@gmail.com> | 2011-05-09 07:43:15 -0700 |
commit | 092a3b1a9058626ec61e3355b2f79572c6013482 (patch) | |
tree | fb8c7eae173276fef97da6d21148780e62a79317 /src | |
parent | 43332e0dc92f9ad81fa0a25bac977760d70c3d2c (diff) | |
download | DotNetOpenAuth-092a3b1a9058626ec61e3355b2f79572c6013482.zip DotNetOpenAuth-092a3b1a9058626ec61e3355b2f79572c6013482.tar.gz DotNetOpenAuth-092a3b1a9058626ec61e3355b2f79572c6013482.tar.bz2 |
Brought custom association store sample for Providers up to date.
Diffstat (limited to 'src')
4 files changed, 21 insertions, 6 deletions
diff --git a/src/DotNetOpenAuth/OpenId/OpenIdUtilities.cs b/src/DotNetOpenAuth/OpenId/OpenIdUtilities.cs index 15e448b..a28a1be 100644 --- a/src/DotNetOpenAuth/OpenId/OpenIdUtilities.cs +++ b/src/DotNetOpenAuth/OpenId/OpenIdUtilities.cs @@ -9,6 +9,7 @@ namespace DotNetOpenAuth.OpenId { using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Diagnostics.Contracts; + using System.Globalization; using System.Linq; using System.Text; using System.Text.RegularExpressions; @@ -23,13 +24,26 @@ namespace DotNetOpenAuth.OpenId { /// <summary> /// A set of utilities especially useful to OpenID. /// </summary> - internal static class OpenIdUtilities { + public static class OpenIdUtilities { /// <summary> /// The prefix to designate this library's proprietary parameters added to the protocol. /// </summary> internal const string CustomParameterPrefix = "dnoa."; /// <summary> + /// Creates a random association handle. + /// </summary> + /// <returns>The association handle.</returns> + public static string GenerateRandomAssociationHandle() { + Contract.Ensures(!String.IsNullOrEmpty(Contract.Result<string>())); + + // Generate the handle. It must be unique, and preferably unpredictable, + // so we use a time element and a random data element to generate it. + string uniq = MessagingUtilities.GetCryptoRandomDataAsBase64(4); + return string.Format(CultureInfo.InvariantCulture, "{{{0}}}{{{1}}}", DateTime.UtcNow.Ticks, uniq); + } + + /// <summary> /// Gets the OpenID protocol instance for the version in a message. /// </summary> /// <param name="message">The message.</param> diff --git a/src/DotNetOpenAuth/OpenId/Provider/IProviderApplicationStore.cs b/src/DotNetOpenAuth/OpenId/Provider/IProviderApplicationStore.cs index cea303f..b8d40e6 100644 --- a/src/DotNetOpenAuth/OpenId/Provider/IProviderApplicationStore.cs +++ b/src/DotNetOpenAuth/OpenId/Provider/IProviderApplicationStore.cs @@ -14,6 +14,6 @@ namespace DotNetOpenAuth.OpenId.Provider { /// <summary> /// A hybrid of all the store interfaces that an OpenID Provider must implement. /// </summary> - public interface IProviderApplicationStore : INonceStore { + public interface IProviderApplicationStore : IProviderAssociationStore, INonceStore { } } diff --git a/src/DotNetOpenAuth/OpenId/Provider/OpenIdProvider.cs b/src/DotNetOpenAuth/OpenId/Provider/OpenIdProvider.cs index b99ac5a..dbde982 100644 --- a/src/DotNetOpenAuth/OpenId/Provider/OpenIdProvider.cs +++ b/src/DotNetOpenAuth/OpenId/Provider/OpenIdProvider.cs @@ -64,7 +64,7 @@ namespace DotNetOpenAuth.OpenId.Provider { /// </summary> /// <param name="applicationStore">The application store to use. Cannot be null.</param> public OpenIdProvider(IProviderApplicationStore applicationStore) - : this((INonceStore)applicationStore) { + : this((INonceStore)applicationStore, (IProviderAssociationStore)applicationStore) { Contract.Requires<ArgumentNullException>(applicationStore != null); Contract.Ensures(this.SecuritySettings != null); Contract.Ensures(this.Channel != null); @@ -74,12 +74,13 @@ namespace DotNetOpenAuth.OpenId.Provider { /// Initializes a new instance of the <see cref="OpenIdProvider"/> class. /// </summary> /// <param name="nonceStore">The nonce store to use. Cannot be null.</param> - private OpenIdProvider(INonceStore nonceStore) { + private OpenIdProvider(INonceStore nonceStore, IProviderAssociationStore associationStore) { Contract.Requires<ArgumentNullException>(nonceStore != null); + Contract.Requires<ArgumentNullException>(associationStore != null, "associationStore"); Contract.Ensures(this.SecuritySettings != null); Contract.Ensures(this.Channel != null); - this.AssociationStore = new ProviderAssociationHandleEncoder(); + this.AssociationStore = associationStore; this.SecuritySettings = DotNetOpenAuthSection.Configuration.OpenId.Provider.SecuritySettings.CreateSecuritySettings(); this.behaviors.CollectionChanged += this.OnBehaviorsChanged; foreach (var behavior in DotNetOpenAuthSection.Configuration.OpenId.Provider.Behaviors.CreateInstances(false)) { diff --git a/src/DotNetOpenAuth/OpenId/Provider/StandardProviderApplicationStore.cs b/src/DotNetOpenAuth/OpenId/Provider/StandardProviderApplicationStore.cs index 59f79ba..13b3787 100644 --- a/src/DotNetOpenAuth/OpenId/Provider/StandardProviderApplicationStore.cs +++ b/src/DotNetOpenAuth/OpenId/Provider/StandardProviderApplicationStore.cs @@ -21,7 +21,7 @@ namespace DotNetOpenAuth.OpenId.Provider { /// <see cref="IProviderApplicationStore"/> interface to use instead of this /// class. /// </remarks> - public class StandardProviderApplicationStore : IProviderApplicationStore { + public class StandardProviderApplicationStore : ProviderAssociationHandleEncoder, IProviderApplicationStore { /// <summary> /// The nonce store to use. /// </summary> |