summaryrefslogtreecommitdiffstats
path: root/src/DotNetOAuth/OAuthMessageTypeProvider.cs
diff options
context:
space:
mode:
authorAndrew Arnott <andrewarnott@gmail.com>2008-09-21 12:51:12 -0700
committerAndrew <andrewarnott@gmail.com>2008-09-21 12:51:12 -0700
commit59295037cd02c6fb995db248e0a6fc5bed125daf (patch)
tree628aa3e1d82714ec2ea9181f21c6de840214a203 /src/DotNetOAuth/OAuthMessageTypeProvider.cs
parent76c4a164c8af4b5239834934bfa8915a60678ed5 (diff)
downloadDotNetOpenAuth-59295037cd02c6fb995db248e0a6fc5bed125daf.zip
DotNetOpenAuth-59295037cd02c6fb995db248e0a6fc5bed125daf.tar.gz
DotNetOpenAuth-59295037cd02c6fb995db248e0a6fc5bed125daf.tar.bz2
Added the 7 OAuth message types.
Diffstat (limited to 'src/DotNetOAuth/OAuthMessageTypeProvider.cs')
-rw-r--r--src/DotNetOAuth/OAuthMessageTypeProvider.cs68
1 files changed, 64 insertions, 4 deletions
diff --git a/src/DotNetOAuth/OAuthMessageTypeProvider.cs b/src/DotNetOAuth/OAuthMessageTypeProvider.cs
index 7d4dbcd..6f6d8b6 100644
--- a/src/DotNetOAuth/OAuthMessageTypeProvider.cs
+++ b/src/DotNetOAuth/OAuthMessageTypeProvider.cs
@@ -7,8 +7,7 @@
namespace DotNetOAuth {
using System;
using System.Collections.Generic;
- using System.Linq;
- using System.Text;
+ using DotNetOAuth.Messages;
using DotNetOAuth.Messaging;
/// <summary>
@@ -23,12 +22,40 @@ namespace DotNetOAuth {
/// message is embedded in it and returns the type, or null if no match is found.
/// </summary>
/// <param name="fields">The name/value pairs that make up the message payload.</param>
+ /// <remarks>
+ /// The request messages are:
+ /// RequestTokenMessage
+ /// RequestAccessTokenMessage
+ /// DirectUserToServiceProviderMessage
+ /// AccessProtectedResourcesMessage
+ /// </remarks>
/// <returns>
/// The <see cref="IProtocolMessage"/>-derived concrete class that this message can
/// deserialize to. Null if the request isn't recognized as a valid protocol message.
/// </returns>
public Type GetRequestMessageType(IDictionary<string, string> fields) {
- throw new NotImplementedException();
+ if (fields == null) {
+ throw new ArgumentNullException("fields");
+ }
+
+ if (fields.ContainsKey("oauth_consumer_key") &&
+ !fields.ContainsKey("oauth_token")) {
+ return typeof(RequestTokenMessage);
+ }
+
+ if (fields.ContainsKey("oauth_consumer_key") &&
+ fields.ContainsKey("oauth_token")) {
+ // Discern between RequestAccessToken and AccessProtectedResources,
+ // which have all the same parameters, by figuring out what type of token
+ // is in the token parameter.
+ bool tokenTypeIsAccessToken = false; // TODO
+
+ return tokenTypeIsAccessToken ? typeof(AccessProtectedResourcesMessage) :
+ typeof(RequestAccessTokenMessage);
+ }
+
+ // fail over to the message with no required fields at all.
+ return typeof(DirectUserToServiceProviderMessage);
}
/// <summary>
@@ -37,14 +64,47 @@ namespace DotNetOAuth {
/// </summary>
/// <param name="request">
/// The message that was sent as a request that resulted in the response.
+ /// Null on a Consumer site that is receiving an indirect message from the Service Provider.
/// </param>
/// <param name="fields">The name/value pairs that make up the message payload.</param>
/// <returns>
/// The <see cref="IProtocolMessage"/>-derived concrete class that this message can
/// deserialize to. Null if the request isn't recognized as a valid protocol message.
/// </returns>
+ /// <remarks>
+ /// The response messages are:
+ /// UnauthorizedRequestTookenMessage
+ /// DirectUserToConsumerMessage
+ /// GrantAccessTokenMessage
+ /// </remarks>
public Type GetResponseMessageType(IProtocolMessage request, IDictionary<string, string> fields) {
- throw new NotImplementedException();
+ if (fields == null) {
+ throw new ArgumentNullException("fields");
+ }
+
+ // All response messages have the oauth_token field.
+ if (!fields.ContainsKey("oauth_token")) {
+ return null;
+ }
+
+ if (request == null) {
+ return typeof(DirectUserToConsumerMessage);
+ }
+
+ // All direct message responses should haev the oauth_token_secret field.
+ if (!fields.ContainsKey("oauth_token_secret")) {
+ Logger.Error("An OAuth message was expected to contain an oauth_token_secret but didn't.");
+ return null;
+ }
+
+ if (request is RequestTokenMessage) {
+ return typeof(UnauthorizedRequestTokenMessage);
+ } else if (request is RequestAccessTokenMessage) {
+ return typeof(GrantAccessTokenMessage);
+ } else {
+ Logger.ErrorFormat("Unexpected response message given the request type {0}", request.GetType().Name);
+ throw new ProtocolException(Strings.InvalidIncomingMessage);
+ }
}
#endregion