summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/DotNetOpenAuth.Test/DotNetOpenAuth.Test.csproj2
-rw-r--r--src/DotNetOpenAuth.Test/OAuthWrap/OAuthWrapChannelTests.cs34
-rw-r--r--src/DotNetOpenAuth.Test/OAuthWrap/OAuthWrapTestBase.cs15
-rw-r--r--src/DotNetOpenAuth/DotNetOpenAuth.csproj1
-rw-r--r--src/DotNetOpenAuth/Messaging/Channel.cs5
-rw-r--r--src/DotNetOpenAuth/OAuthWrap/ChannelElements/OAuthWrapChannel.cs77
-rw-r--r--src/DotNetOpenAuth/OAuthWrap/ChannelElements/OAuthWrapMessageFactory.cs99
-rw-r--r--src/DotNetOpenAuth/OAuthWrap/Messages/WebApp/WebAppRequest.cs2
8 files changed, 130 insertions, 105 deletions
diff --git a/src/DotNetOpenAuth.Test/DotNetOpenAuth.Test.csproj b/src/DotNetOpenAuth.Test/DotNetOpenAuth.Test.csproj
index a0c849a..93d222f 100644
--- a/src/DotNetOpenAuth.Test/DotNetOpenAuth.Test.csproj
+++ b/src/DotNetOpenAuth.Test/DotNetOpenAuth.Test.csproj
@@ -222,6 +222,8 @@
<Compile Include="Mocks\TestChannel.cs" />
<Compile Include="Mocks\TestMessage.cs" />
<Compile Include="Mocks\TestMessageFactory.cs" />
+ <Compile Include="OAuthWrap\OAuthWrapChannelTests.cs" />
+ <Compile Include="OAuthWrap\OAuthWrapTestBase.cs" />
<Compile Include="OAuth\ChannelElements\HmacSha1SigningBindingElementTests.cs" />
<Compile Include="OAuth\ChannelElements\OAuthChannelTests.cs" />
<Compile Include="OAuth\ChannelElements\PlaintextSigningBindingElementTest.cs" />
diff --git a/src/DotNetOpenAuth.Test/OAuthWrap/OAuthWrapChannelTests.cs b/src/DotNetOpenAuth.Test/OAuthWrap/OAuthWrapChannelTests.cs
new file mode 100644
index 0000000..1f76e8f
--- /dev/null
+++ b/src/DotNetOpenAuth.Test/OAuthWrap/OAuthWrapChannelTests.cs
@@ -0,0 +1,34 @@
+//-----------------------------------------------------------------------
+// <copyright file="OAuthWrapChannelTests.cs" company="Andrew Arnott">
+// Copyright (c) Andrew Arnott. All rights reserved.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace DotNetOpenAuth.Test.OAuthWrap {
+ using System;
+ using System.Collections.Generic;
+ using System.Linq;
+ using System.Text;
+ using DotNetOpenAuth.Messaging;
+ using DotNetOpenAuth.OAuthWrap.ChannelElements;
+ using NUnit.Framework;
+
+ [TestFixture]
+ public class OAuthWrapChannelTests : OAuthWrapTestBase {
+ private OAuthWrapChannel channel;
+
+ public override void SetUp() {
+ base.SetUp();
+
+ this.channel = new OAuthWrapChannel();
+ }
+
+ /// <summary>
+ /// Verifies that the WRAP message types are initialized.
+ /// </summary>
+ [TestCase]
+ public void MessageFactory() {
+ // TODO: code here
+ }
+ }
+}
diff --git a/src/DotNetOpenAuth.Test/OAuthWrap/OAuthWrapTestBase.cs b/src/DotNetOpenAuth.Test/OAuthWrap/OAuthWrapTestBase.cs
new file mode 100644
index 0000000..08c9da6
--- /dev/null
+++ b/src/DotNetOpenAuth.Test/OAuthWrap/OAuthWrapTestBase.cs
@@ -0,0 +1,15 @@
+//-----------------------------------------------------------------------
+// <copyright file="OAuthWrapTestBase.cs" company="Andrew Arnott">
+// Copyright (c) Andrew Arnott. All rights reserved.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace DotNetOpenAuth.Test.OAuthWrap {
+ using System;
+ using System.Collections.Generic;
+ using System.Linq;
+ using System.Text;
+
+ public class OAuthWrapTestBase : TestBase {
+ }
+}
diff --git a/src/DotNetOpenAuth/DotNetOpenAuth.csproj b/src/DotNetOpenAuth/DotNetOpenAuth.csproj
index 669863c..70f4ecc 100644
--- a/src/DotNetOpenAuth/DotNetOpenAuth.csproj
+++ b/src/DotNetOpenAuth/DotNetOpenAuth.csproj
@@ -611,7 +611,6 @@ http://opensource.org/licenses/ms-pl.html
<Compile Include="Messaging\MessageReceivingEndpoint.cs" />
<Compile Include="Reporting.cs" />
<Compile Include="OAuthWrap\ChannelElements\OAuthWrapChannel.cs" />
- <Compile Include="OAuthWrap\ChannelElements\OAuthWrapMessageFactory.cs" />
<Compile Include="OAuthWrap\ClientBase.cs" />
<Compile Include="OAuthWrap\Messages\WebApp\WebAppAccessTokenSuccessResponse.cs" />
<Compile Include="OAuthWrap\Messages\MessageBase.cs" />
diff --git a/src/DotNetOpenAuth/Messaging/Channel.cs b/src/DotNetOpenAuth/Messaging/Channel.cs
index 7198c78..df17dcb 100644
--- a/src/DotNetOpenAuth/Messaging/Channel.cs
+++ b/src/DotNetOpenAuth/Messaging/Channel.cs
@@ -151,7 +151,7 @@ namespace DotNetOpenAuth.Messaging {
/// <summary>
/// Gets or sets the message descriptions.
/// </summary>
- internal MessageDescriptionCollection MessageDescriptions {
+ internal virtual MessageDescriptionCollection MessageDescriptions {
get {
return this.messageDescriptions;
}
@@ -201,11 +201,12 @@ namespace DotNetOpenAuth.Messaging {
protected internal bool IsDisposed { get; set; }
/// <summary>
- /// Gets a tool that can figure out what kind of message is being received
+ /// Gets or sets a tool that can figure out what kind of message is being received
/// so it can be deserialized.
/// </summary>
protected IMessageFactory MessageFactory {
get { return this.messageTypeProvider; }
+ set { this.messageTypeProvider = value; }
}
/// <summary>
diff --git a/src/DotNetOpenAuth/OAuthWrap/ChannelElements/OAuthWrapChannel.cs b/src/DotNetOpenAuth/OAuthWrap/ChannelElements/OAuthWrapChannel.cs
index 3c2065f..01ef028 100644
--- a/src/DotNetOpenAuth/OAuthWrap/ChannelElements/OAuthWrapChannel.cs
+++ b/src/DotNetOpenAuth/OAuthWrap/ChannelElements/OAuthWrapChannel.cs
@@ -7,9 +7,11 @@
namespace DotNetOpenAuth.OAuthWrap.ChannelElements {
using System;
using System.Collections.Generic;
+ using System.Diagnostics.Contracts;
using System.Linq;
using System.Text;
using DotNetOpenAuth.Messaging;
+ using DotNetOpenAuth.Messaging.Reflection;
/// <summary>
/// The channel for the OAuth WRAP protocol.
@@ -18,8 +20,27 @@ namespace DotNetOpenAuth.OAuthWrap.ChannelElements {
/// <summary>
/// Initializes a new instance of the <see cref="OAuthWrapChannel"/> class.
/// </summary>
- internal OAuthWrapChannel()
- : base(new OAuthWrapMessageFactory()) {
+ protected internal OAuthWrapChannel()
+ : base(new StandardMessageFactory()) {
+ ((StandardMessageFactory)this.MessageFactory).AddMessageTypes(GetWrapMessageDescriptions(this.MessageDescriptions));
+ }
+
+ /// <summary>
+ /// Gets or sets the message descriptions.
+ /// </summary>
+ internal override MessageDescriptionCollection MessageDescriptions {
+ get {
+ return base.MessageDescriptions;
+ }
+
+ set {
+ base.MessageDescriptions = value;
+
+ // We must reinitialize the message factory so it can use the new message descriptions.
+ var factory = new StandardMessageFactory();
+ factory.AddMessageTypes(GetWrapMessageDescriptions(value));
+ this.MessageFactory = factory;
+ }
}
/// <summary>
@@ -48,5 +69,57 @@ namespace DotNetOpenAuth.OAuthWrap.ChannelElements {
protected override OutgoingWebResponse PrepareDirectResponse(IProtocolMessage response) {
throw new NotImplementedException();
}
+
+ /// <summary>
+ /// Gets the message types that come standard with OAuth WRAP.
+ /// </summary>
+ /// <param name="descriptionsCache">The descriptions cache from which to draw.</param>
+ /// <returns>A collection of WRAP message types.</returns>
+ private static IEnumerable<MessageDescription> GetWrapMessageDescriptions(MessageDescriptionCollection descriptionsCache) {
+ Contract.Requires<ArgumentNullException>(descriptionsCache != null);
+ Contract.Ensures(Contract.Result<IEnumerable<MessageDescription>>() != null);
+
+ var messageTypes = new Type[] {
+ typeof(Messages.RefreshAccessTokenRequest),
+ typeof(Messages.RefreshAccessTokenSuccessResponse),
+ typeof(Messages.RefreshAccessTokenFailedResponse),
+ typeof(Messages.UnauthorizedResponse),
+ typeof(Messages.AssertionRequest),
+ typeof(Messages.AssertionSuccessResponse),
+ typeof(Messages.AssertionFailedResponse),
+ typeof(Messages.ClientAccountUsernamePasswordRequest),
+ typeof(Messages.ClientAccountUsernamePasswordSuccessResponse),
+ typeof(Messages.ClientAccountUsernamePasswordFailedResponse),
+ typeof(Messages.RichAppRequest),
+ typeof(Messages.RichAppResponse),
+ typeof(Messages.RichAppAccessTokenRequest),
+ typeof(Messages.RichAppAccessTokenSuccessResponse),
+ typeof(Messages.RichAppAccessTokenFailedResponse),
+ typeof(Messages.UserNamePasswordRequest),
+ typeof(Messages.UserNamePasswordSuccessResponse),
+ typeof(Messages.UserNamePasswordVerificationResponse),
+ typeof(Messages.UserNamePasswordFailedResponse),
+ typeof(Messages.UsernamePasswordCaptchaResponse),
+ typeof(Messages.WebAppRequest),
+ typeof(Messages.WebAppSuccessResponse),
+ typeof(Messages.WebAppFailedResponse),
+ typeof(Messages.WebAppAccessTokenRequest),
+ typeof(Messages.WebAppAccessTokenSuccessResponse),
+ typeof(Messages.WebAppAccessTokenBadClientResponse),
+ typeof(Messages.WebAppAccessTokenFailedResponse),
+ };
+
+ // Get all the MessageDescription objects through the standard cache,
+ // so that perhaps it will be a quick lookup, or at least it will be
+ // stored there for a quick lookup later.
+ var messageDescriptions = new List<MessageDescription>(messageTypes.Length * Protocol.AllVersions.Count);
+ foreach (Protocol protocol in Protocol.AllVersions) {
+ foreach (Type messageType in messageTypes) {
+ messageDescriptions.Add(descriptionsCache.Get(messageType, protocol.Version));
+ }
+ }
+
+ return messageDescriptions;
+ }
}
}
diff --git a/src/DotNetOpenAuth/OAuthWrap/ChannelElements/OAuthWrapMessageFactory.cs b/src/DotNetOpenAuth/OAuthWrap/ChannelElements/OAuthWrapMessageFactory.cs
deleted file mode 100644
index b3b9abb..0000000
--- a/src/DotNetOpenAuth/OAuthWrap/ChannelElements/OAuthWrapMessageFactory.cs
+++ /dev/null
@@ -1,99 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="OAuthWrapMessageFactory.cs" company="Andrew Arnott">
-// Copyright (c) Andrew Arnott. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace DotNetOpenAuth.OAuthWrap.ChannelElements {
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using DotNetOpenAuth.Messaging;
- using DotNetOpenAuth.OAuthWrap.Messages;
-
- /// <summary>
- /// The message factory for OAuth WRAP messages.
- /// </summary>
- internal class OAuthWrapMessageFactory : IMessageFactory {
- /// <summary>
- /// Initializes a new instance of the <see cref="OAuthWrapMessageFactory"/> class.
- /// </summary>
- internal OAuthWrapMessageFactory() {
- }
-
- #region IMessageFactory Members
-
- /// <summary>
- /// Analyzes an incoming request message payload to discover what kind of
- /// message is embedded in it and returns the type, or null if no match is found.
- /// </summary>
- /// <param name="recipient">The intended or actual recipient of the request message.</param>
- /// <param name="fields">The name/value pairs that make up the message payload.</param>
- /// <returns>
- /// A newly instantiated <see cref="IProtocolMessage"/>-derived object that this message can
- /// deserialize to. Null if the request isn't recognized as a valid protocol message.
- /// </returns>
- public IDirectedProtocolMessage GetNewRequestMessage(MessageReceivingEndpoint recipient, IDictionary<string, string> fields) {
- Version version = Protocol.DefaultVersion;
-
- if (fields.ContainsKey(Protocol.wrap_client_id) && fields.ContainsKey(Protocol.wrap_callback)) {
- return new WebAppRequest(recipient.Location, version);
- }
-
- if (fields.ContainsKey(Protocol.wrap_client_id) && fields.ContainsKey(Protocol.wrap_verification_code)) {
- return new WebAppAccessTokenRequest(recipient.Location, version);
- }
-
- if (fields.ContainsKey(Protocol.wrap_name)) {
- return new ClientAccountUsernamePasswordRequest(recipient.Location, version);
- }
-
- if (fields.ContainsKey(Protocol.wrap_username)) {
- return new UserNamePasswordRequest(recipient.Location, version);
- }
-
- if (fields.ContainsKey(Protocol.wrap_verification_code)) {
- return new WebAppSuccessResponse(recipient.Location, version);
- }
-
- return null;
- }
-
- /// <summary>
- /// Analyzes an incoming request message payload to discover what kind of
- /// message is embedded in it and returns the type, or null if no match is found.
- /// </summary>
- /// <param name="request">The message that was sent as a request that resulted in the response.</param>
- /// <param name="fields">The name/value pairs that make up the message payload.</param>
- /// <returns>
- /// A newly instantiated <see cref="IProtocolMessage"/>-derived object that this message can
- /// deserialize to. Null if the request isn't recognized as a valid protocol message.
- /// </returns>
- public IDirectResponseProtocolMessage GetNewResponseMessage(IDirectedProtocolMessage request, IDictionary<string, string> fields) {
- Version version = Protocol.DefaultVersion;
-
- var accessTokenRequest = request as WebAppAccessTokenRequest;
- if (accessTokenRequest != null) {
- if (fields.ContainsKey(Protocol.wrap_access_token)) {
- return new WebAppAccessTokenSuccessResponse(accessTokenRequest);
- } else {
- //return new AccessTokenWithVerificationCodeFailedResponse(accessTokenRequest);
- }
- }
-
- var userAuthorization = request as UserNamePasswordRequest;
- if (userAuthorization != null) {
- if (fields.ContainsKey(Protocol.wrap_verification_code)) {
- return new UserNamePasswordSuccessResponse(userAuthorization);
- } else {
- //return new UserAuthorizationViaUsernamePasswordFailedResponse(userAuthorization);
- }
- }
-
- return null;
- }
-
- #endregion
- }
-}
diff --git a/src/DotNetOpenAuth/OAuthWrap/Messages/WebApp/WebAppRequest.cs b/src/DotNetOpenAuth/OAuthWrap/Messages/WebApp/WebAppRequest.cs
index b0da9aa..229ebd4 100644
--- a/src/DotNetOpenAuth/OAuthWrap/Messages/WebApp/WebAppRequest.cs
+++ b/src/DotNetOpenAuth/OAuthWrap/Messages/WebApp/WebAppRequest.cs
@@ -15,7 +15,7 @@ namespace DotNetOpenAuth.OAuthWrap.Messages {
/// via the user agent to obtain authorization from the user and prepare
/// to issue an access token to the Consumer if permission is granted.
/// </summary>
- internal class WebAppRequest : MessageBase, IMessageWithClientState {
+ public class WebAppRequest : MessageBase, IMessageWithClientState {
/// <summary>
/// Initializes a new instance of the <see cref="WebAppRequest"/> class.
/// </summary>