PHP setAssertionCredentials

819 views
Skip to first unread message

spacewrench

unread,
Apr 14, 2012, 1:31:16 AM4/14/12
to oauth...@googlegroups.com
The PHP example code calls setAssertionCredentials() on an apiClient object. Only problem is, there is no such method (as far as grep & I can determine).  Searching the group for that function name only turns up one message (Python-related); surely I can't be the only person using PHP?

(I'd appreciate being warned off of this project if it won't work [yet]: JS on browser contacts server, gets customized OAuth2 URL, JS accesses URL to retrieve non-public document from Cloud Storage using CORS.  Any problems?)

Thanks!

myka

unread,
Apr 15, 2012, 11:29:53 PM4/15/12
to oauth2-dev
I am in the same position as you here, trying to figure out what to do
about the referenced setAssertionCredentials() call in the php sample.

Any hints or suggestions people have would be handy at this point.

myka

unread,
Apr 16, 2012, 1:06:14 AM4/16/12
to oauth...@googlegroups.com
I found an answer to my own question...


setAssertionCredentials() does exist in the SVN version of the php client library, but not in the tarball packaged download. the documentation has been updated without the packaged downloads being similarly updated, hence the confusion.


spacewrench

unread,
Apr 16, 2012, 1:40:01 AM4/16/12
to oauth2-dev
Glad you worked that out. I ended up following the instructions at
https://developers.google.com/storage/docs/accesscontrol#Signed-URLs
to create signed URLs from scratch -- I spent a little time looking
through the PHP libraries and didn't see anything that looked quite
right. It turned out to be pretty easy:

/*
* Create a signed URL to access the named resource at the cloud
* storage facility. Right now, this is Google Cloud Storage. The
* URL will be returned to the client, which uses Cross-Origin
Resource
* Sharing (CORS) to access the file directly.
*/
function storageURL( $id, $method = 'GET', $duration = 10 ) {
$expires = time( ) + $duration;

$content_type = ($method == 'PUT') ? 'application/x-www-form-
urlencoded' : '';

$to_sign = ($method . "\n" .
/* Content-MD5 */ "\n" .
$content_type . "\n" .
$expires . "\n" .
'/bucket-name/' . $id);

$signature = '*Put signature here*';

if (!openssl_sign( $to_sign, $signature, '--put-private-key-here--',
'sha256' )) {
error_log( 'openssl_sign failed!' );
$signature = '<failed>';
} else {
$signature = urlencode( base64_encode( $signature ) );
}

return ('https://bucket-name.commondatastorage.googleapis.com/' .
$id .
'?GoogleAccessId=' . '--put-email-id here--' .
'&Expires=' . $expires . '&Signature=' . $signature);
Reply all
Reply to author
Forward
0 new messages