Skip to content

Commit da9e554

Browse files
committed
Fixes the OAuthServiceProvider sample issue with recognizing protected resource requests:
Expected message DotNetOpenAuth.OAuth.Messages.AccessProtectedResourceRequest but received DotNetOpenAuth.OAuth.Messages.UserAuthorizationRequest instead. The issue was that in converting a WCF message to an HttpRequestMessage, the Authorization header was truncated (sort of), but in a way we could reassemble the original message.
1 parent ef21fed commit da9e554

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

src/DotNetOpenAuth.Core/Messaging/MessagingUtilities.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1535,6 +1535,24 @@ internal static void AddExtraParameters(this MessageDictionary messageDictionary
15351535
}
15361536
}
15371537

1538+
/// <summary>
1539+
/// Reassembles multiple values in an HTTP request header as a comma-delimited list.
1540+
/// </summary>
1541+
/// <param name="headers">The headers from which to read a header.</param>
1542+
/// <param name="headerName">Name of the header to read.</param>
1543+
/// <returns>A comma-delimited list of values for the named header, or <c>null</c> if no header was included in the collection by the specified name.</returns>
1544+
internal static string GetJointValues(this System.Net.Http.Headers.HttpRequestHeaders headers, string headerName) {
1545+
Requires.NotNull(headers, "headers");
1546+
Requires.NotNullOrEmpty(headerName, "headerName");
1547+
1548+
IEnumerable<string> values;
1549+
if (headers.TryGetValues(headerName, out values)) {
1550+
return string.Join(",", values);
1551+
}
1552+
1553+
return null;
1554+
}
1555+
15381556
/// <summary>
15391557
/// Gets the URI that contains the entire payload that would be sent by the browser for the specified redirect-based request message.
15401558
/// </summary>

src/DotNetOpenAuth.OAuth/OAuth/ChannelElements/OAuthChannel.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ protected static List<IChannelBindingElement> InitializeBindingElements(ITamperP
120120
/// <returns>The deserialized message, if one is found. Null otherwise.</returns>
121121
protected override async Task<IDirectedProtocolMessage> ReadFromRequestCoreAsync(HttpRequestMessage request, CancellationToken cancellationToken) {
122122
// First search the Authorization header.
123-
var authorization = request.Headers.Authorization;
123+
AuthenticationHeaderValue authorization;
124+
AuthenticationHeaderValue.TryParse(request.Headers.GetJointValues("Authorization"), out authorization);
124125
var fields = MessagingUtilities.ParseAuthorizationHeader(Protocol.AuthorizationHeaderScheme, authorization).ToDictionary();
125126
fields.Remove("realm"); // ignore the realm parameter, since we don't use it, and it must be omitted from signature base string.
126127

0 commit comments

Comments
 (0)