//-----------------------------------------------------------------------
//
// Copyright (c) Outercurve Foundation. All rights reserved.
//
//-----------------------------------------------------------------------
namespace DotNetOpenAuth.OpenId.Provider {
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DotNetOpenAuth.Messaging;
using DotNetOpenAuth.OpenId.Messages;
using DotNetOpenAuth.OpenId.Provider;
using Validation;
///
/// Utility methods for OpenID Providers.
///
internal static class OpenIdProviderUtilities {
///
/// Called to create the Association based on a request previously given by the Relying Party.
///
/// The prior request for an association.
/// The response.
/// The Provider's association store.
/// The security settings for the Provider. Should be null for Relying Parties.
///
/// The created association.
///
///
/// The response message is updated to include the details of the created association by this method.
/// This method is called by both the Provider and the Relying Party, but actually performs
/// quite different operations in either scenario.
///
internal static Association CreateAssociation(AssociateRequest request, IAssociateSuccessfulResponseProvider response, IProviderAssociationStore associationStore, ProviderSecuritySettings securitySettings) {
Requires.NotNull(request, "request");
Requires.NotNull(response, "response");
Requires.NotNull(securitySettings, "securitySettings");
// We need to initialize some common properties based on the created association.
var association = response.CreateAssociationAtProvider(request, associationStore, securitySettings);
response.ExpiresIn = association.SecondsTillExpiration;
response.AssociationHandle = association.Handle;
return association;
}
///
/// Determines whether the association with the specified handle is (still) valid.
///
/// The association store.
/// The OpenID message that referenced this association handle.
/// A value indicating whether a private association is expected.
/// The association handle.
///
/// true if the specified containing message is valid; otherwise, false.
///
internal static bool IsValid(this IProviderAssociationStore associationStore, IProtocolMessage containingMessage, bool isPrivateAssociation, string handle) {
Requires.NotNull(associationStore, "associationStore");
Requires.NotNull(containingMessage, "containingMessage");
Requires.NotNullOrEmpty(handle, "handle");
try {
return associationStore.Deserialize(containingMessage, isPrivateAssociation, handle) != null;
} catch (ProtocolException) {
return false;
}
}
}
}