summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAndrew Arnott <andrewarnott@gmail.com>2010-05-30 17:38:37 -0700
committerAndrew Arnott <andrewarnott@gmail.com>2010-05-30 17:38:37 -0700
commit52a77983f11cfbb948a574585ba8069dcbcbd89b (patch)
tree7d2b68315b852bc9e139fbc2d735fb4da772aa45 /src
parenta35e28f356b324484111bed4c041c23ffe26c3eb (diff)
downloadDotNetOpenAuth-52a77983f11cfbb948a574585ba8069dcbcbd89b.zip
DotNetOpenAuth-52a77983f11cfbb948a574585ba8069dcbcbd89b.tar.gz
DotNetOpenAuth-52a77983f11cfbb948a574585ba8069dcbcbd89b.tar.bz2
Fixed StandardMessageFactory message ordering a bit more.
Diffstat (limited to 'src')
-rw-r--r--src/DotNetOpenAuth/Messaging/StandardMessageFactory.cs20
-rw-r--r--src/DotNetOpenAuth/OAuthWrap/WebAppClient.cs3
2 files changed, 20 insertions, 3 deletions
diff --git a/src/DotNetOpenAuth/Messaging/StandardMessageFactory.cs b/src/DotNetOpenAuth/Messaging/StandardMessageFactory.cs
index 40f2d5d..abf3359 100644
--- a/src/DotNetOpenAuth/Messaging/StandardMessageFactory.cs
+++ b/src/DotNetOpenAuth/Messaging/StandardMessageFactory.cs
@@ -179,8 +179,9 @@ namespace DotNetOpenAuth.Messaging {
where message.CheckMessagePartsPassBasicValidation(fields)
let ctors = this.FindMatchingResponseConstructors(message, request.GetType())
where ctors.Any()
- orderby GetDerivationDistance(ctors.First().GetParameters()[0].ParameterType, request.GetType())
- orderby message.Mapping.Count descending
+ orderby GetDerivationDistance(ctors.First().GetParameters()[0].ParameterType, request.GetType()) ,
+ CountInCommon(message.Mapping.Keys, fields.Keys) descending ,
+ message.Mapping.Count descending
select message).CacheGeneratedResults();
var match = matches.FirstOrDefault();
if (match != null) {
@@ -265,5 +266,20 @@ namespace DotNetOpenAuth.Messaging {
return this.responseMessageTypes[messageDescription].Where(pair => pair.Key.IsAssignableFrom(requestType)).Select(pair => pair.Value);
}
+
+ /// <summary>
+ /// Counts how many strings are in the intersection of two collections.
+ /// </summary>
+ /// <param name="collection1">The first collection.</param>
+ /// <param name="collection2">The second collection.</param>
+ /// <param name="comparison">The string comparison method to use.</param>
+ /// <returns>A non-negative integer no greater than the count of elements in the smallest collection.</returns>
+ private int CountInCommon(ICollection<string> collection1, ICollection<string> collection2, StringComparison comparison = StringComparison.Ordinal) {
+ Contract.Requires<ArgumentNullException>(collection1 != null, "collection1");
+ Contract.Requires<ArgumentNullException>(collection2 != null, "collection2");
+ Contract.Ensures(Contract.Result<int>() >= 0 && Contract.Result<int>() <= Math.Min(collection1.Count, collection2.Count));
+
+ return collection1.Count(value1 => collection2.Any(value2 => string.Equals(value1, value2, comparison)));
+ }
}
}
diff --git a/src/DotNetOpenAuth/OAuthWrap/WebAppClient.cs b/src/DotNetOpenAuth/OAuthWrap/WebAppClient.cs
index 8df71b9..4ac1430 100644
--- a/src/DotNetOpenAuth/OAuthWrap/WebAppClient.cs
+++ b/src/DotNetOpenAuth/OAuthWrap/WebAppClient.cs
@@ -100,7 +100,8 @@ namespace DotNetOpenAuth.OAuthWrap {
authorizationState.SaveChanges();
} else {
authorizationState.Delete();
- ErrorUtilities.ThrowProtocol(OAuthWrapStrings.CannotObtainAccessTokenWithReason, failedAccessTokenResponse.Error);
+ string error = failedAccessTokenResponse != null ? failedAccessTokenResponse.Error : "(unknown)";
+ ErrorUtilities.ThrowProtocol(OAuthWrapStrings.CannotObtainAccessTokenWithReason, error);
}
} else { // failure
Logger.Wrap.Info("User refused to grant the requested authorization at the Authorization Server.");