//-----------------------------------------------------------------------
//
// Copyright (c) Outercurve Foundation. All rights reserved.
//
//-----------------------------------------------------------------------
namespace DotNetOpenAuth.OAuth2 {
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DotNetOpenAuth.Messaging;
using Validation;
///
/// A default implementation of the interface.
///
public class ClientDescription : IClientDescription {
///
/// The client's secret, if any.
///
private readonly string secret;
///
/// Initializes a new instance of the class.
///
/// The secret.
/// The default callback.
/// Type of the client.
public ClientDescription(string secret, Uri defaultCallback, ClientType clientType) {
this.secret = secret;
this.DefaultCallback = defaultCallback;
this.ClientType = clientType;
}
#region IClientDescription Members
///
/// Gets the callback to use when an individual authorization request
/// does not include an explicit callback URI.
///
///
/// An absolute URL; or null if none is registered.
///
public Uri DefaultCallback { get; private set; }
///
/// Gets the type of the client.
///
public ClientType ClientType { get; private set; }
///
/// Gets a value indicating whether a non-empty secret is registered for this client.
///
public virtual bool HasNonEmptySecret {
get { return !string.IsNullOrEmpty(this.secret); }
}
///
/// Determines whether a callback URI included in a client's authorization request
/// is among those allowed callbacks for the registered client.
///
/// The absolute URI the client has requested the authorization result be received at. Never null.
///
/// true if the callback URL is allowable for this client; otherwise, false.
///
///
/// This method may be overridden to allow for several callbacks to match.
///
public virtual bool IsCallbackAllowed(Uri callback) {
return EqualityComparer.Default.Equals(this.DefaultCallback, callback);
}
///
/// Checks whether the specified client secret is correct.
///
/// The secret obtained from the client.
/// true if the secret matches the one in the authorization server's record for the client; false otherwise.
///
/// All string equality checks, whether checking secrets or their hashes,
/// should be done using to mitigate timing attacks.
///
public virtual bool IsValidClientSecret(string secret) {
Requires.NotNullOrEmpty(secret, "secret");
return MessagingUtilities.EqualsConstantTime(secret, this.secret);
}
#endregion
}
}