Skip to content
This repository was archived by the owner on Mar 20, 2019. It is now read-only.

Commit f4f3295

Browse files
committed
Fixed error message generated in exception thrown for bad access token requests.
1 parent 6c29eba commit f4f3295

5 files changed

Lines changed: 23 additions & 12 deletions

File tree

src/DotNetOpenAuth.Core/Messaging/DataBagFormatterBase.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,15 +190,22 @@ public string Serialize(T message) {
190190
/// <summary>
191191
/// Deserializes a <see cref="DataBag"/>, including decompression, decryption, signature and nonce validation where applicable.
192192
/// </summary>
193-
/// <param name="containingMessage">The message that contains the <see cref="DataBag"/> serialized value. Must not be nulll.</param>
193+
/// <param name="containingMessage">The message that contains the <see cref="DataBag"/> serialized value. Must not be null.</param>
194194
/// <param name="value">The serialized form of the <see cref="DataBag"/> to deserialize. Must not be null or empty.</param>
195-
/// <returns>The deserialized value. Never null.</returns>
195+
/// <param name="messagePartName">The name of the parameter whose value is to be deserialized. Used for error message generation.</param>
196+
/// <returns>
197+
/// The deserialized value. Never null.
198+
/// </returns>
196199
[SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Justification = "No apparent problem. False positive?")]
197-
public T Deserialize(IProtocolMessage containingMessage, string value) {
200+
public T Deserialize(IProtocolMessage containingMessage, string value, string messagePartName) {
201+
Requires.NotNull(containingMessage, "containingMessage");
202+
Requires.NotNullOrEmpty(value, "value");
203+
Requires.NotNullOrEmpty(messagePartName, "messagePartName");
204+
198205
string symmetricSecretHandle = null;
199206
if (this.encrypted && this.cryptoKeyStore != null) {
200207
string valueWithoutHandle;
201-
MessagingUtilities.ExtractKeyHandleAndPayload(containingMessage, "<TODO>", value, out symmetricSecretHandle, out valueWithoutHandle);
208+
MessagingUtilities.ExtractKeyHandleAndPayload(containingMessage, messagePartName, value, out symmetricSecretHandle, out valueWithoutHandle);
202209
value = valueWithoutHandle;
203210
}
204211

src/DotNetOpenAuth.Core/Messaging/IDataBagFormatter.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,13 @@ namespace DotNetOpenAuth.Messaging {
2424
/// <summary>
2525
/// Deserializes a <see cref="DataBag"/>.
2626
/// </summary>
27-
/// <param name="containingMessage">The message that contains the <see cref="DataBag"/> serialized value. Must not be nulll.</param>
27+
/// <param name="containingMessage">The message that contains the <see cref="DataBag"/> serialized value. Must not be null.</param>
2828
/// <param name="data">The serialized form of the <see cref="DataBag"/> to deserialize. Must not be null or empty.</param>
29-
/// <returns>The deserialized value. Never null.</returns>
30-
T Deserialize(IProtocolMessage containingMessage, string data);
29+
/// <param name="messagePartName">The name of the parameter whose value is to be deserialized. Used for error message generation.</param>
30+
/// <returns>
31+
/// The deserialized value. Never null.
32+
/// </returns>
33+
T Deserialize(IProtocolMessage containingMessage, string data, string messagePartName);
3134
}
3235

3336
/// <summary>
@@ -62,9 +65,10 @@ string IDataBagFormatter<T>.Serialize(T message) {
6265
/// <param name="containingMessage">The message that contains the <see cref="DataBag"/> serialized value. Must not be nulll.</param>
6366
/// <param name="data">The serialized form of the <see cref="DataBag"/> to deserialize. Must not be null or empty.</param>
6467
/// <returns>The deserialized value. Never null.</returns>
65-
T IDataBagFormatter<T>.Deserialize(IProtocolMessage containingMessage, string data) {
68+
T IDataBagFormatter<T>.Deserialize(IProtocolMessage containingMessage, string data, string messagePartName) {
6669
Requires.NotNull(containingMessage, "containingMessage");
6770
Requires.NotNullOrEmpty(data, "data");
71+
Requires.NotNullOrEmpty(messagePartName, "messagePartName");
6872
Contract.Ensures(Contract.Result<T>() != null);
6973

7074
throw new System.NotImplementedException();

src/DotNetOpenAuth.OAuth2/OAuth2/ChannelElements/AccessRequestBindingElement.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,11 @@ public override MessageProtections Protection {
118118
var clientCredentialOnly = message as AccessTokenClientCredentialsRequest;
119119
if (authCodeCarrier != null) {
120120
var authorizationCodeFormatter = AuthorizationCode.CreateFormatter(this.AuthorizationServer);
121-
var authorizationCode = authorizationCodeFormatter.Deserialize(message, authCodeCarrier.Code);
121+
var authorizationCode = authorizationCodeFormatter.Deserialize(message, authCodeCarrier.Code, Protocol.code);
122122
authCodeCarrier.AuthorizationDescription = authorizationCode;
123123
} else if (refreshTokenCarrier != null) {
124124
var refreshTokenFormatter = RefreshToken.CreateFormatter(this.AuthorizationServer.CryptoKeyStore);
125-
var refreshToken = refreshTokenFormatter.Deserialize(message, refreshTokenCarrier.RefreshToken);
125+
var refreshToken = refreshTokenFormatter.Deserialize(message, refreshTokenCarrier.RefreshToken, Protocol.refresh_token);
126126
refreshTokenCarrier.AuthorizationDescription = refreshToken;
127127
} else if (resourceOwnerPasswordCarrier != null) {
128128
try {

src/DotNetOpenAuth.OAuth2/OAuth2/StandardAccessTokenAnalyzer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public StandardAccessTokenAnalyzer(RSACryptoServiceProvider authorizationServerP
5757
/// </remarks>
5858
public virtual bool TryValidateAccessToken(IDirectedProtocolMessage message, string accessToken, out string user, out HashSet<string> scope) {
5959
var accessTokenFormatter = AccessToken.CreateFormatter(this.AuthorizationServerPublicSigningKey, this.ResourceServerPrivateEncryptionKey);
60-
var token = accessTokenFormatter.Deserialize(message, accessToken);
60+
var token = accessTokenFormatter.Deserialize(message, accessToken, Protocol.access_token);
6161
user = token.User;
6262
scope = new HashSet<string>(token.Scope, OAuthUtilities.ScopeStringComparer);
6363
return true;

src/DotNetOpenAuth.OpenId.Provider/OpenId/Provider/ProviderAssociationHandleEncoder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public Association Deserialize(IProtocolMessage containingMessage, bool privateA
7070
var formatter = AssociationDataBag.CreateFormatter(this.cryptoKeyStore, AssociationHandleEncodingSecretBucket);
7171
AssociationDataBag bag;
7272
try {
73-
bag = formatter.Deserialize(containingMessage, handle);
73+
bag = formatter.Deserialize(containingMessage, handle, Protocol.Default.openid.assoc_handle);
7474
} catch (ProtocolException ex) {
7575
Logger.OpenId.Error("Rejecting an association because deserialization of the encoded handle failed.", ex);
7676
return null;

0 commit comments

Comments
 (0)