imgix / imgix-csharp

A C# client library for generating image URLs with imgix
https://www.imgix.com
MIT License
15 stars 8 forks source link

Imgix Proxy with Signed Key failing #7

Closed BenjaminGibbs closed 8 years ago

BenjaminGibbs commented 8 years ago

I appear to be running in to a problem, where I trying to use a proxy with a signed key.

If I create a URL via the tool in the web portal it works fine, if I do it via the api it gives an error about the signed key being wrong.

The library works fine for me if have a web folder setup, but I have a scenario where I needed to use the proxy, does anyone have any ideas what I am doing wrong? - I can't see any tests in the library for testing the proxy combination with a signed key.

My Test Code:

Dim l As New List(Of String)
l.Add("DOMAIN")
Dim urlBuilder = New UrlBuilder(l.ToArray, True)
urlBuilder.SignKey = "KEY"
Console.WriteLine(urlBuilder.BuildUrl("URL"))
paulstraw commented 8 years ago

This should be working, according to this test: https://github.com/raynjamin/Imgix-CSharp/blob/master/Imgix-CSharp-Tests/ImgixBlueprintTests.cs#L65

Can you send through the output URLs you get from the web tool and this library?

BenjaminGibbs commented 8 years ago

This is the output I get from signing using a proxy setup;

Input/Request:

GET https://osc-proxy.imgix.net/https:%2F%2Fs-media-cache-ak0.pinimg.com%2Foriginals%2F36%2F70%2Fb6%2F3670b61e7e8e43d68626c0d0347b73b9.jpg?s=ebc1d9aa6cd2df5c71b9f8bf19293008 HTTP/1.1
Host: osc-proxy.imgix.net
Connection: keep-alive
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Encoding: gzip, deflate, sdch, br
Accept-Language: en-US,en;q=0.8

Output/Response:

HTTP/1.1 401 Unauthorized
Server: imgix-fe
Cache-Control: max-age=300
Fastly-Debug-Digest: 1d0bcd8664dd47b31c079909f719b294a394a9b3eeadec8c528276adf83447b7
Content-Length: 26
Accept-Ranges: bytes
Date: Mon, 07 Nov 2016 04:15:12 GMT
Age: 22
Connection: keep-alive
Content-Type: image/jpeg
X-Imgix-Request-ID: 7c53387b70458b17ac87377b36f1fb287d07bc5d
X-Content-Type-Options: nosniff
X-Served-By: cache-lax8634-LAX, cache-lhr6349-LHR
X-Cache: MISS, HIT
X-Cache-Hits: 0, 1

URI signature match failed
paulstraw commented 8 years ago

@BenjaminGibbs sorry for the miscommunication, could you send through the URL you're passing to the library to get https://osc-proxy.imgix.net/https:%2F%2Fs-media-cache-ak0.pinimg.com%2Foriginals%2F36%2F70%2Fb6%2F3670b61e7e8e43d68626c0d0347b73b9.jpg?s=ebc1d9aa6cd2df5c71b9f8bf19293008 as output?

paulstraw commented 8 years ago

The error is being caused by the unencoded : in the https://. If that's encoded properly, it works as expected: https://osc-proxy.imgix.net/https%3A%2F%2Fs-media-cache-ak0.pinimg.com%2Foriginals%2F36%2F70%2Fb6%2F3670b61e7e8e43d68626c0d0347b73b9.jpg?s=ebc1d9aa6cd2df5c71b9f8bf19293008

BenjaminGibbs commented 8 years ago

So this is my code:

Dim l As New List(Of String)
l.Add("osc-proxy.imgix.net")
Dim urlBuilder = New UrlBuilder(l.ToArray, True)
urlBuilder.SignKey = "xxx"
Console.WriteLine(urlBuilder.BuildUrl("https://s-media-cache-ak0.pinimg.com/originals/36/70/b6/3670b61e7e8e43d68626c0d0347b73b9.jpg"))

However great spot with the URL being wrong, the error appears to be with visual studio. I was using the console.writeline as per above, when I clicked on the URL in the output window VS transformed it from

https://osc-proxy.imgix.net/https%3A%2F%2Fs-media-cache-ak0.pinimg.com%2Foriginals%2F36%2F70%2Fb6%2F3670b61e7e8e43d68626c0d0347b73b9.jpg?s=ebc1d9aa6cd2df5c71b9f8bf19293008

to

https://osc-proxy.imgix.net/https:%2F%2Fs-media-cache-ak0.pinimg.com%2Foriginals%2F36%2F70%2Fb6%2F3670b61e7e8e43d68626c0d0347b73b9.jpg?s=ebc1d9aa6cd2df5c71b9f8bf19293008

If I copied and paste it directly it works fine, thanks for your help - sorry for taking up your time.

paulstraw commented 8 years ago

Oh, awesome! Glad it's actually working. It's funny how our most useful tools can sometimes be our worst enemies, too!