//----------------------------------------------------------------------- // // 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 /// to represent a confidential client (one that has an authenticating secret.) /// /// The secret. /// The default callback. public ClientDescription(string secret, Uri defaultCallback) { Requires.NotNullOrEmpty(secret, "secret"); Requires.NotNull(defaultCallback, "defaultCallback"); this.secret = secret; this.DefaultCallback = defaultCallback; this.ClientType = ClientType.Confidential; } /// /// Initializes a new instance of the class /// to represent a public client (one that does not have an authenticating secret.) /// /// The default callback. public ClientDescription(Uri defaultCallback) { Requires.NotNull(defaultCallback, "defaultCallback"); this.DefaultCallback = defaultCallback; this.ClientType = ClientType.Public; } /// /// Initializes a new instance of the class. /// protected ClientDescription() { } #region IClientDescription Members /// /// Gets or sets 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; protected set; } /// /// Gets or sets the type of the client. /// public ClientType ClientType { get; protected 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 } }