Problem with creating a signature #41

Closed
keithslater opened this Issue Feb 27, 2015 · 7 comments

Comments

Projects
None yet
3 participants
@keithslater

I just started using Glide and I am attempting to set up signatures for the images. I believe I'm about 99% there but I'm having a problem with it.

I am doing this -

$urlBuilder = UrlBuilderFactory::create($url, 'key');

$url = $urlBuilder->getUrl('image.php', ['image' => $path, 'w' => $width, 'h' => $height]);

When doing this, the result of $parts['path'] inside the getUrl method is /image.php.

However when doing this -

SignatureFactory::create('key')->validateRequest($request);

The output of $request->getPathInfo() in validateRequest() method is just a /.

Because of this, the signatures don't match. Any idea how I can fix this?

@renege

This comment has been minimized.

Show comment
Hide comment
@renege

renege Mar 1, 2015

Same here. Maybe someone can make a good example? Will be usable for everyone, looks like from the docs it's a create feature.

renege commented Mar 1, 2015

Same here. Maybe someone can make a good example? Will be usable for everyone, looks like from the docs it's a create feature.

@reinink

This comment has been minimized.

Show comment
Hide comment
@reinink

reinink Mar 2, 2015

Member

@keithslater Hmm, I'll have to take a closer look at this to understand what's going wrong. Are you able to provide me example URLs that you're working with?

Member

reinink commented Mar 2, 2015

@keithslater Hmm, I'll have to take a closer look at this to understand what's going wrong. Are you able to provide me example URLs that you're working with?

@keithslater

This comment has been minimized.

Show comment
Hide comment
@keithslater

keithslater Mar 2, 2015

Sure, I'm doing something like this - http://www.domain.com/image.php?image=company_logos/original/1.png&w=250&h=100

Then when I call it, I'm doing this -

$url = $urlBuilder->getUrl('image.php', ['image' => $path, 'w' => $width, 'h' => $height]);

Path would be - company_logos/original/1.png

Sure, I'm doing something like this - http://www.domain.com/image.php?image=company_logos/original/1.png&w=250&h=100

Then when I call it, I'm doing this -

$url = $urlBuilder->getUrl('image.php', ['image' => $path, 'w' => $width, 'h' => $height]);

Path would be - company_logos/original/1.png

@reinink

This comment has been minimized.

Show comment
Hide comment
@reinink

reinink May 22, 2015

Member

Okay, so I think i see what's going wrong here. Glide is designed for URLs that work like this:

http://www.domain.com/img/company_logos/original/1.png&w=250&h=100

And then you would create a route within your app to accept those image requests, something like this:

get('/img/{path}', function ($path) {
    $glide->outputImage($path, $_GET);
});

The reason that URL isn't working for you is because image.php?image=company_logos/original/1.png&w=250&h=100 should resolve to /image.php when getPathInfo() is called.

To make a path like /img/company_logos/original/1.png work, you would have to setup URL rewriting, which is pretty standard on modern PHP projects.

Having said that, it would probably be helpful to offer something like this as well with Glide, instead of having to use the HttpFoundation request object for HTTP signatures:

SignatureFactory::create('key')->validateRequest($path, $_GET);

I'll add that to my to-do list.

Member

reinink commented May 22, 2015

Okay, so I think i see what's going wrong here. Glide is designed for URLs that work like this:

http://www.domain.com/img/company_logos/original/1.png&w=250&h=100

And then you would create a route within your app to accept those image requests, something like this:

get('/img/{path}', function ($path) {
    $glide->outputImage($path, $_GET);
});

The reason that URL isn't working for you is because image.php?image=company_logos/original/1.png&w=250&h=100 should resolve to /image.php when getPathInfo() is called.

To make a path like /img/company_logos/original/1.png work, you would have to setup URL rewriting, which is pretty standard on modern PHP projects.

Having said that, it would probably be helpful to offer something like this as well with Glide, instead of having to use the HttpFoundation request object for HTTP signatures:

SignatureFactory::create('key')->validateRequest($path, $_GET);

I'll add that to my to-do list.

@reinink

This comment has been minimized.

Show comment
Hide comment
@reinink

reinink May 22, 2015

Member

As promised: 615861a

I'll get this tagged as soon as possible.

Member

reinink commented May 22, 2015

As promised: 615861a

I'll get this tagged as soon as possible.

@reinink reinink closed this May 22, 2015

@renege

This comment has been minimized.

Show comment
Hide comment
@renege

renege May 22, 2015

promising! can you please update docs also with a good example to use this signature-feature?

renege commented May 22, 2015

promising! can you please update docs also with a good example to use this signature-feature?

@keithslater

This comment has been minimized.

Show comment
Hide comment
@keithslater

keithslater May 22, 2015

Awesome, thanks.

Awesome, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment