Skip to content

Commit 4c1383e

Browse files
committed
Resolves smartstore#807 Web-API: Update API client to support URL encoded filter strings
1 parent d5bf53d commit 4c1383e

5 files changed

Lines changed: 42 additions & 14 deletions

File tree

src/Presentation/SmartStore.Web.Framework/WebApi/Security/HmacAuthentication.cs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Globalization;
33
using System.Security.Cryptography;
44
using System.Text;
5+
using System.Web;
56

67
namespace SmartStore.Web.Framework.WebApi.Security
78
{
@@ -79,19 +80,32 @@ public string CreateSignature(string secretKey, string messageRepresentation)
7980
/// ISO-8601 UTC timestamp including milliseconds (e.g. 2013-09-23T09:24:43.5395441Z)\n
8081
/// Public-Key
8182
/// </summary>
82-
public string CreateMessageRepresentation(WebApiRequestContext context, string contentMd5Hash, string timestamp)
83+
public string CreateMessageRepresentation(WebApiRequestContext context, string contentMd5Hash, string timestamp, bool queryStringDecode = false)
8384
{
8485
if (context == null || !context.IsValid)
8586
return null;
8687

87-
string result = string.Join(_delimiterRepresentation,
88+
var url = context.Url;
89+
90+
if (queryStringDecode)
91+
{
92+
var uri = new Uri(url);
93+
94+
if (uri.Query != null && uri.Query.Length > 0)
95+
{
96+
url = string.Concat(uri.GetLeftPart(UriPartial.Path), HttpUtility.UrlDecode(uri.Query));
97+
}
98+
}
99+
100+
var result = string.Join(_delimiterRepresentation,
88101
context.HttpMethod.ToLower(),
89102
contentMd5Hash ?? "",
90103
context.HttpAcceptType.ToLower(),
91-
context.Url.ToLower(),
104+
url.ToLower(),
92105
timestamp,
93106
context.PublicKey.ToLower()
94107
);
108+
95109
return result;
96110
}
97111

src/Tools/SmartStore.WebApi.Client/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ namespace SmartStoreNetWebApiClient
55
{
66
static class Program
77
{
8-
public static string AppName { get { return "SmartStore.Net Web API Client v.1.1"; } }
9-
public static string ConsumerName { get { return "My shopping data consumer v.1.1"; } }
8+
public static string AppName { get { return "SmartStore.Net Web API Client v.1.2"; } }
9+
public static string ConsumerName { get { return "My shopping data consumer v.1.2"; } }
1010

1111
/// <summary>
1212
/// Der Haupteinstiegspunkt für die Anwendung.

src/Tools/SmartStore.WebApi.Client/Properties/AssemblyInfo.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
[assembly: AssemblyConfiguration("")]
1111
[assembly: AssemblyCompany("")]
1212
[assembly: AssemblyProduct("SmartStoreNetWebApiClient")]
13-
[assembly: AssemblyCopyright("Copyright © SmartStore AG 2013")]
13+
[assembly: AssemblyCopyright("Copyright © SmartStore AG 2015")]
1414
[assembly: AssemblyTrademark("")]
1515
[assembly: AssemblyCulture("")]
1616

@@ -32,5 +32,5 @@
3232
// Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern
3333
// übernehmen, indem Sie "*" eingeben:
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("1.0.0.0")]
36-
[assembly: AssemblyFileVersion("1.0.0.0")]
35+
[assembly: AssemblyVersion("1.2.0.0")]
36+
[assembly: AssemblyFileVersion("1.2.0.0")]

src/Tools/SmartStore.WebApi.Client/WebApi/HmacAuthentication.cs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
using System;
2-
using System.Text;
3-
using System.Security.Cryptography;
42
using System.Globalization;
3+
using System.Security.Cryptography;
4+
using System.Text;
5+
using System.Web;
56

67
namespace SmartStore.Net.WebApi
78
{
@@ -79,19 +80,32 @@ public string CreateSignature(string secretKey, string messageRepresentation)
7980
/// ISO-8601 UTC timestamp including milliseconds (e.g. 2013-09-23T09:24:43.5395441Z)\n
8081
/// Public-Key
8182
/// </summary>
82-
public string CreateMessageRepresentation(WebApiRequestContext context, string contentMd5Hash, string timestamp)
83+
public string CreateMessageRepresentation(WebApiRequestContext context, string contentMd5Hash, string timestamp, bool queryStringDecode = false)
8384
{
8485
if (context == null || !context.IsValid)
8586
return null;
8687

87-
string result = string.Join(_delimiterRepresentation,
88+
var url = context.Url;
89+
90+
if (queryStringDecode)
91+
{
92+
var uri = new Uri(url);
93+
94+
if (uri.Query != null && uri.Query.Length > 0)
95+
{
96+
url = string.Concat(uri.GetLeftPart(UriPartial.Path), HttpUtility.UrlDecode(uri.Query));
97+
}
98+
}
99+
100+
var result = string.Join(_delimiterRepresentation,
88101
context.HttpMethod.ToLower(),
89102
contentMd5Hash ?? "",
90103
context.HttpAcceptType.ToLower(),
91-
context.Url.ToLower(),
104+
url.ToLower(),
92105
timestamp,
93106
context.PublicKey.ToLower()
94107
);
108+
95109
return result;
96110
}
97111

src/Tools/SmartStore.WebApi.Client/WebApi/WebApiConsumer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ public HttpWebRequest StartRequest(WebApiRequestContext context, string content,
215215
request.Headers.Add(HttpRequestHeader.ContentMd5, contentMd5Hash);
216216
}
217217

218-
string messageRepresentation = CreateMessageRepresentation(context, contentMd5Hash, timestamp);
218+
string messageRepresentation = CreateMessageRepresentation(context, contentMd5Hash, timestamp, true);
219219
//Debug.WriteLine(messageRepresentation);
220220
string signature = CreateSignature(context.SecretKey, messageRepresentation);
221221

0 commit comments

Comments
 (0)