summaryrefslogtreecommitdiffstats
path: root/src/DotNetOpenAuth.OAuth2/OAuth2
diff options
context:
space:
mode:
Diffstat (limited to 'src/DotNetOpenAuth.OAuth2/OAuth2')
-rw-r--r--src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/AuthServerBindingElementBase.cs15
-rw-r--r--src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/AuthorizationCode.cs5
-rw-r--r--src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/IOAuth2ChannelWithAuthorizationServer.cs19
-rw-r--r--src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/OAuth2AuthorizationServerChannel.cs2
-rw-r--r--src/DotNetOpenAuth.OAuth2/OAuth2/ClientDescription.cs71
-rw-r--r--src/DotNetOpenAuth.OAuth2/OAuth2/IAuthorizationServer.cs2
-rw-r--r--src/DotNetOpenAuth.OAuth2/OAuth2/OAuthStrings.Designer.cs9
-rw-r--r--src/DotNetOpenAuth.OAuth2/OAuth2/OAuthStrings.resx3
-rw-r--r--src/DotNetOpenAuth.OAuth2/OAuth2/OAuthUtilities.cs4
9 files changed, 113 insertions, 17 deletions
diff --git a/src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/AuthServerBindingElementBase.cs b/src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/AuthServerBindingElementBase.cs
index 6d24d38..49f820d 100644
--- a/src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/AuthServerBindingElementBase.cs
+++ b/src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/AuthServerBindingElementBase.cs
@@ -18,8 +18,7 @@ namespace DotNetOpenAuth.OAuth2.ChannelElements {
/// <summary>
/// Initializes a new instance of the <see cref="AuthServerBindingElementBase"/> class.
/// </summary>
- protected AuthServerBindingElementBase()
- {
+ protected AuthServerBindingElementBase() {
}
/// <summary>
@@ -39,21 +38,11 @@ namespace DotNetOpenAuth.OAuth2.ChannelElements {
public abstract MessageProtections Protection { get; }
/// <summary>
- /// Gets the channel that this binding element belongs to.
- /// </summary>
- /// <remarks>
- /// This property is set by the channel when it is first constructed.
- /// </remarks>
- protected OAuth2AuthorizationServerChannel OAuthChannel {
- get { return (OAuth2AuthorizationServerChannel)this.Channel; }
- }
-
- /// <summary>
/// Gets the authorization server hosting this channel.
/// </summary>
/// <value>The authorization server.</value>
protected IAuthorizationServer AuthorizationServer {
- get { return this.OAuthChannel.AuthorizationServer; }
+ get { return ((IOAuth2ChannelWithAuthorizationServer)this.Channel).AuthorizationServer; }
}
/// <summary>
diff --git a/src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/AuthorizationCode.cs b/src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/AuthorizationCode.cs
index 6199178..111c007 100644
--- a/src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/AuthorizationCode.cs
+++ b/src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/AuthorizationCode.cs
@@ -61,8 +61,11 @@ namespace DotNetOpenAuth.OAuth2.ChannelElements {
Requires.NotNull(authorizationServer, "authorizationServer");
Contract.Ensures(Contract.Result<IDataBagFormatter<AuthorizationCode>>() != null);
+ var cryptoStore = authorizationServer.CryptoKeyStore;
+ ErrorUtilities.VerifyHost(cryptoStore != null, OAuthStrings.ResultShouldNotBeNull, authorizationServer.GetType(), "CryptoKeyStore");
+
return new UriStyleMessageFormatter<AuthorizationCode>(
- authorizationServer.CryptoKeyStore,
+ cryptoStore,
AuthorizationCodeKeyBucket,
signed: true,
encrypted: true,
diff --git a/src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/IOAuth2ChannelWithAuthorizationServer.cs b/src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/IOAuth2ChannelWithAuthorizationServer.cs
new file mode 100644
index 0000000..5fc73ce
--- /dev/null
+++ b/src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/IOAuth2ChannelWithAuthorizationServer.cs
@@ -0,0 +1,19 @@
+//-----------------------------------------------------------------------
+// <copyright file="IOAuth2ChannelWithAuthorizationServer.cs" company="Outercurve Foundation">
+// Copyright (c) Outercurve Foundation. All rights reserved.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace DotNetOpenAuth.OAuth2.ChannelElements {
+ /// <summary>
+ /// An interface on an OAuth 2 Authorization Server channel
+ /// to expose the host provided authorization server object.
+ /// </summary>
+ internal interface IOAuth2ChannelWithAuthorizationServer {
+ /// <summary>
+ /// Gets the authorization server.
+ /// </summary>
+ /// <value>The authorization server.</value>
+ IAuthorizationServer AuthorizationServer { get; }
+ }
+}
diff --git a/src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/OAuth2AuthorizationServerChannel.cs b/src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/OAuth2AuthorizationServerChannel.cs
index 295ee86..3375328 100644
--- a/src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/OAuth2AuthorizationServerChannel.cs
+++ b/src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/OAuth2AuthorizationServerChannel.cs
@@ -15,7 +15,7 @@ namespace DotNetOpenAuth.OAuth2.ChannelElements {
/// <summary>
/// The channel for the OAuth protocol.
/// </summary>
- internal class OAuth2AuthorizationServerChannel : OAuth2ChannelBase {
+ internal class OAuth2AuthorizationServerChannel : OAuth2ChannelBase, IOAuth2ChannelWithAuthorizationServer {
/// <summary>
/// Initializes a new instance of the <see cref="OAuth2AuthorizationServerChannel"/> class.
/// </summary>
diff --git a/src/DotNetOpenAuth.OAuth2/OAuth2/ClientDescription.cs b/src/DotNetOpenAuth.OAuth2/OAuth2/ClientDescription.cs
new file mode 100644
index 0000000..76c3ea6
--- /dev/null
+++ b/src/DotNetOpenAuth.OAuth2/OAuth2/ClientDescription.cs
@@ -0,0 +1,71 @@
+//-----------------------------------------------------------------------
+// <copyright file="ClientDescription.cs" company="Outercurve Foundation">
+// Copyright (c) Outercurve Foundation. All rights reserved.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace DotNetOpenAuth.OAuth2 {
+ using System;
+ using System.Collections.Generic;
+ using System.Linq;
+ using System.Text;
+
+ /// <summary>
+ /// A default implementation of the <see cref="IClientDescription"/> interface.
+ /// </summary>
+ public class ClientDescription : IClientDescription {
+ /// <summary>
+ /// A delegate that determines whether the callback is allowed.
+ /// </summary>
+ private readonly Func<Uri, bool> isCallbackAllowed;
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="ClientDescription"/> class.
+ /// </summary>
+ /// <param name="secret">The secret.</param>
+ /// <param name="defaultCallback">The default callback.</param>
+ /// <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.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>
+ /// <value>
+ /// An absolute URL; or <c>null</c> if none is registered.
+ /// </value>
+ public Uri DefaultCallback { get; private set; }
+
+ /// <summary>
+ /// Gets the type of the client.
+ /// </summary>
+ public ClientType ClientType { get; private set; }
+
+ /// <summary>
+ /// Determines whether a callback URI included in a client's authorization request
+ /// is among those allowed callbacks for the registered client.
+ /// </summary>
+ /// <param name="callback">The absolute URI the client has requested the authorization result be received at.</param>
+ /// <returns>
+ /// <c>true</c> if the callback URL is allowable for this client; otherwise, <c>false</c>.
+ /// </returns>
+ public bool IsCallbackAllowed(Uri callback) {
+ if (this.isCallbackAllowed != null) {
+ return this.isCallbackAllowed(callback);
+ }
+
+ return EqualityComparer<Uri>.Default.Equals(this.DefaultCallback, callback);
+ }
+ }
+}
diff --git a/src/DotNetOpenAuth.OAuth2/OAuth2/IAuthorizationServer.cs b/src/DotNetOpenAuth.OAuth2/OAuth2/IAuthorizationServer.cs
index 9c2888f..1732003 100644
--- a/src/DotNetOpenAuth.OAuth2/OAuth2/IAuthorizationServer.cs
+++ b/src/DotNetOpenAuth.OAuth2/OAuth2/IAuthorizationServer.cs
@@ -22,7 +22,7 @@ namespace DotNetOpenAuth.OAuth2 {
[ContractClass(typeof(IAuthorizationServerContract))]
public interface IAuthorizationServer {
/// <summary>
- /// Gets the store for storeing crypto keys used to symmetrically encrypt and sign authorization codes and refresh tokens.
+ /// Gets the store for storing crypto keys used to symmetrically encrypt and sign authorization codes and refresh tokens.
/// </summary>
/// <remarks>
/// This store should be kept strictly confidential in the authorization server(s)
diff --git a/src/DotNetOpenAuth.OAuth2/OAuth2/OAuthStrings.Designer.cs b/src/DotNetOpenAuth.OAuth2/OAuth2/OAuthStrings.Designer.cs
index 2167b5f..6ce3b53 100644
--- a/src/DotNetOpenAuth.OAuth2/OAuth2/OAuthStrings.Designer.cs
+++ b/src/DotNetOpenAuth.OAuth2/OAuth2/OAuthStrings.Designer.cs
@@ -169,6 +169,15 @@ namespace DotNetOpenAuth.OAuth2 {
}
/// <summary>
+ /// Looks up a localized string similar to The return value of {0}.{1} should never be null..
+ /// </summary>
+ internal static string ResultShouldNotBeNull {
+ get {
+ return ResourceManager.GetString("ResultShouldNotBeNull", resourceCulture);
+ }
+ }
+
+ /// <summary>
/// Looks up a localized string similar to Individual scopes may not contain spaces..
/// </summary>
internal static string ScopesMayNotContainSpaces {
diff --git a/src/DotNetOpenAuth.OAuth2/OAuth2/OAuthStrings.resx b/src/DotNetOpenAuth.OAuth2/OAuth2/OAuthStrings.resx
index 6fad914..af1a955 100644
--- a/src/DotNetOpenAuth.OAuth2/OAuth2/OAuthStrings.resx
+++ b/src/DotNetOpenAuth.OAuth2/OAuth2/OAuthStrings.resx
@@ -153,6 +153,9 @@
<data name="RefreshTokenInappropriateForRequestType" xml:space="preserve">
<value>The request message type {0} should not be responded to with a refresh token.</value>
</data>
+ <data name="ResultShouldNotBeNull" xml:space="preserve">
+ <value>The return value of {0}.{1} should never be null.</value>
+ </data>
<data name="ScopesMayNotContainSpaces" xml:space="preserve">
<value>Individual scopes may not contain spaces.</value>
</data>
diff --git a/src/DotNetOpenAuth.OAuth2/OAuth2/OAuthUtilities.cs b/src/DotNetOpenAuth.OAuth2/OAuth2/OAuthUtilities.cs
index 245779a..68ccc1d 100644
--- a/src/DotNetOpenAuth.OAuth2/OAuth2/OAuthUtilities.cs
+++ b/src/DotNetOpenAuth.OAuth2/OAuth2/OAuthUtilities.cs
@@ -141,7 +141,9 @@ namespace DotNetOpenAuth.OAuth2 {
Contract.Ensures(Contract.Result<IClientDescription>() != null);
try {
- return authorizationServer.GetClient(clientIdentifier);
+ var result = authorizationServer.GetClient(clientIdentifier);
+ ErrorUtilities.VerifyHost(result != null, OAuthStrings.ResultShouldNotBeNull, authorizationServer.GetType().FullName, "GetClient(string)");
+ return result;
} catch (KeyNotFoundException ex) {
throw ErrorUtilities.Wrap(ex, OAuthStrings.ClientOrTokenSecretNotFound);
} catch (ArgumentException ex) {