-
-
Notifications
You must be signed in to change notification settings - Fork 313
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot pass MVC5 Request.QueryString or Request.Headers to Auth service methods. #164
Comments
Great work around. I was able to do this work-around by doing the following as well. :)
|
I have this can work too :D public static IEnumerable<KeyValuePair<string, StringValues>> ToKVPairs(this NameValueCollection collection)
{
if (collection == null)
{
throw new ArgumentNullException(nameof(collection));
}
return collection.Cast<string>().Select(key => new KeyValuePair<string, StringValues>(key, collection[key]));
} |
I've added a couple additional overloads to |
A querystring can contain multiple items with the same key - for example It would also be better to avoid using LINQ for something this simple. And since you only need an public static IEnumerable<KeyValuePair<string, StringValues>> ToKvps(this NameValueCollection source)
{
if (source is null) throw new ArgumentNullException(nameof(source));
return Iterator(source);
IEnumerable<KeyValuePair<string, StringValues>> Iterator(NameValueCollection qs)
{
foreach (string key in qs.Keys)
{
string[] values = qs.GetValues(key);
yield return new KeyValuePair<string, StringValues>(key, values);
}
}
} |
In ASP.NET MVC5 the
Request.QueryString
andRequest.Headers
objects are of typeSystem.Collections.Specialized.NameValueCollection
- a type that does not exist in .NET Standard 1.4. In the guides I've written, and even in the ShopifySharp documentation, we tell users to pass those objects to the variousAuthorizationService.IsValidX
functions, but in v4+ those functions now expect a list ofKeyValuePair<string, StringValues>
.For those reading this issue wondering how to get around this, for now you can create this extension method and then call
Request.QueryString.ToKvps()
orRequest.Headers.ToKvps()
and pass the result to the auth methods:I'd like to explore fixing this in the package without adding an extra dependency. I'm not sure that's possible though, because even including the above extension method in ShopifySharp would require a reference to the type which simply isn't available.
The text was updated successfully, but these errors were encountered: