lildude/phpSmug — Issue #14: I want to add Authorization Header while accesing the images
Author: praveen123
Created: 2011-10-09 15:36:19+00:00
State: open

Hi,

I am getting blank images when I try to access the images using $images = $f->images_get("AlbumID={$albums['0']['id']}", "AlbumKey={$albums['0']['Key']}", "Heavy=1"); and I am able to see the image url but it just displays the blank image and the same image url which is accessed through code can be accessible through browser.

When I approached the smugmug team they suggested to add the Authorization Header while accessing the images some thing like this

This is excerpt from Oauth 1.0 soecs regarding authorization header. You should include this header, with your values naturally, to the request for images.

5.4.1. Authorization Header

The OAuth Protocol Parameters are sent in the Authorization header the following way:

Parameter names and values are encoded per Parameter Encoding.
For each parameter, the name is immediately followed by an ‘=’ character (ASCII code 61), a ‘”’ character (ASCII code 34), the parameter value (MAY be empty), and another ‘”’ character (ASCII code 34).
Parameters are separated by a comma character (ASCII code 44) and OPTIONAL linear whitespace per [RFC2617].
The OPTIONAL realm parameter is added and interpreted per [RFC2617], section 1.2.

For example:

Authorization: OAuth realm="http://sp.example.com/",
oauth_consumer_key="0685bd9184jfhq22",
oauth_token="ad180jjd733klru7",
oauth_signature_method="HMAC-SHA1",
oauth_signature="wOJIO9A2W5mFwDgiDvZbTSMK%2FPY%3D",
oauth_timestamp="137131200",
oauth_nonce="4572616e48616d6d65724c61686176",
oauth_version="1.0"

I tried to add this my code as below and my idea is to access the images with header but it is not working. How best we can add the header

$albums = $f->albums_get('Heavy=false');
$sig = $f->generate_signature( 'Get', array( 'FileName' => $albums['0']['Key'] ) );
$f->setHeader( 'Authorization', 'OAuth realm="http://api.smugmug.com/",
oauth_consumer_key="'.$f->APIKey.'",
oauth_token="'.$f->oauth_token.'",
oauth_signature_method="'.$f->oauth_signature_method.'",
oauth_signature="'.urlencode( $sig ).'",
oauth_timestamp="'.$f->oauth_timestamp.'",
oauth_version="1.0",
oauth_nonce="'.$f->oauth_nonce.'"' );
// Get list of public images and other useful information
$images = $f->images_get("AlbumID={$albums['0']['id']}", "AlbumKey={$albums['0']['Key']}", "Heavy=1");