summaryrefslogtreecommitdiffstats
path: root/src/DotNetOpenAuth.OAuth2.AuthorizationServer/OAuth2/ClientDescription.cs
diff options
context:
space:
mode:
authorAndrew Arnott <andrewarnott@gmail.com>2012-04-01 08:14:30 -0700
committerAndrew Arnott <andrewarnott@gmail.com>2012-04-01 08:14:48 -0700
commitcc78ccd887b76df0587a47a2c126c541cdce4d7d (patch)
tree33664471fc550bb7e9f58e8679bbba8fdbc7bbfc /src/DotNetOpenAuth.OAuth2.AuthorizationServer/OAuth2/ClientDescription.cs
parent03bc5770d091ec2e96d49bb0f7dcaa77d8f1a170 (diff)
downloadDotNetOpenAuth-cc78ccd887b76df0587a47a2c126c541cdce4d7d.zip
DotNetOpenAuth-cc78ccd887b76df0587a47a2c126c541cdce4d7d.tar.gz
DotNetOpenAuth-cc78ccd887b76df0587a47a2c126c541cdce4d7d.tar.bz2
Allows the authorization server to store merely the hashes of client secrets.
Fixes #92
Diffstat (limited to 'src/DotNetOpenAuth.OAuth2.AuthorizationServer/OAuth2/ClientDescription.cs')
-rw-r--r--src/DotNetOpenAuth.OAuth2.AuthorizationServer/OAuth2/ClientDescription.cs39
1 files changed, 33 insertions, 6 deletions
diff --git a/src/DotNetOpenAuth.OAuth2.AuthorizationServer/OAuth2/ClientDescription.cs b/src/DotNetOpenAuth.OAuth2.AuthorizationServer/OAuth2/ClientDescription.cs
index 76c3ea6..1ec9789 100644
--- a/src/DotNetOpenAuth.OAuth2.AuthorizationServer/OAuth2/ClientDescription.cs
+++ b/src/DotNetOpenAuth.OAuth2.AuthorizationServer/OAuth2/ClientDescription.cs
@@ -9,6 +9,7 @@ namespace DotNetOpenAuth.OAuth2 {
using System.Collections.Generic;
using System.Linq;
using System.Text;
+ using DotNetOpenAuth.Messaging;
/// <summary>
/// A default implementation of the <see cref="IClientDescription"/> interface.
@@ -20,6 +21,11 @@ namespace DotNetOpenAuth.OAuth2 {
private readonly Func<Uri, bool> isCallbackAllowed;
/// <summary>
+ /// The client's secret, if any.
+ /// </summary>
+ private readonly string secret;
+
+ /// <summary>
/// Initializes a new instance of the <see cref="ClientDescription"/> class.
/// </summary>
/// <param name="secret">The secret.</param>
@@ -27,18 +33,13 @@ namespace DotNetOpenAuth.OAuth2 {
/// <param name="clientType">Type of the client.</param>
/// <param name="isCallbackAllowed">A delegate that determines whether the callback is allowed.</param>
public ClientDescription(string secret, Uri defaultCallback, ClientType clientType, Func<Uri, bool> isCallbackAllowed = null) {
- this.Secret = secret;
+ this.secret = secret;
this.DefaultCallback = defaultCallback;
this.ClientType = clientType;
this.isCallbackAllowed = isCallbackAllowed;
}
/// <summary>
- /// Gets the client secret.
- /// </summary>
- public string Secret { get; private set; }
-
- /// <summary>
/// Gets the callback to use when an individual authorization request
/// does not include an explicit callback URI.
/// </summary>
@@ -53,6 +54,13 @@ namespace DotNetOpenAuth.OAuth2 {
public ClientType ClientType { get; private set; }
/// <summary>
+ /// Gets a value indicating whether a non-empty secret is registered for this client.
+ /// </summary>
+ public bool HasNonEmptySecret {
+ get { return !string.IsNullOrEmpty(this.secret); }
+ }
+
+ /// <summary>
/// Determines whether a callback URI included in a client's authorization request
/// is among those allowed callbacks for the registered client.
/// </summary>
@@ -67,5 +75,24 @@ namespace DotNetOpenAuth.OAuth2 {
return EqualityComparer<Uri>.Default.Equals(this.DefaultCallback, callback);
}
+
+ #region IClientDescription Members
+
+ /// <summary>
+ /// Checks whether the specified client secret is correct.
+ /// </summary>
+ /// <param name="secret">The secret obtained from the client.</param>
+ /// <returns><c>true</c> if the secret matches the one in the authorization server's record for the client; <c>false</c> otherwise.</returns>
+ /// <remarks>
+ /// All string equality checks, whether checking secrets or their hashes,
+ /// should be done using <see cref="MessagingUtilites.EqualsConstantTime"/> to mitigate timing attacks.
+ /// </remarks>
+ public bool IsValidClientSecret(string secret) {
+ Requires.NotNullOrEmpty(secret, "secret");
+
+ return MessagingUtilities.EqualsConstantTime(secret, this.secret);
+ }
+
+ #endregion
}
}