English 中文(简体)
How do I get secure AuthSub session tokens in PHP?
原标题:

I am using the Google/YouTube APIs to develop web application which needs access to a users YouTube account.

Normal unsecure requests work fine and I can upgrade one time tokens to session tokens without any hassle. The problem comes when I try and upgrade a secure token to a session token, I get:

ERROR - Token upgrade for CIzF3546351vmq_P____834654G failed : Token upgrade failed. Reason: Invalid AuthSub signature.

i use this:

    function updateAuthSubToken($singleUseToken)
    {
        try {
        $client = new Zend_Gdata_HttpClient();
        $client->setAuthSubPrivateKeyFile( /home/myrsakey.pem , null, true);
        $sessionToken = Zend_Gdata_AuthSub::getAuthSubSessionToken($singleUseToken, $client);
        $sessionToken = Zend_Gdata_AuthSub::getAuthSubSessionToken(trim($singleUseToken), $client);  
        //$client->setAuthSubToken($sessionToken); 
        } catch (Zend_Gdata_App_Exception $e) {
            print  ERROR - Token upgrade for   . $singleUseToken
                .   failed :   . $e->getMessage();
            return;
        }
        $_SESSION[ sessionToken ] = $sessionToken;
        $date = gmdate("M d Y H:i:s", mktime(0, 0, 0, 1, 1, 1998));
        header( Authorization: AuthSub token=" .$_SESSION[ sessionToken ]. " data="GET 
    https://www.youtube.com/auth_sub_request  .$date.  15948652339726849410"  . 
     sig="MIICXAIBAAKBgQDLJn/sr7TrmQpsEaL312k9dEpikVGFHbE+FjNg7/lfagkTZXf3 .
     t96omgSEyZat2RcckVAGs9dU5kbGLJxEaW2ChQplzCKDi+20HZZo7C1QCluaMJ6b .
    ...
     0pj+zWPy4T04PH3elN6EkhQ5Vxy5wbBkugqIDqfOKuM="  .
     sigalg="rsa-sha1" );
        }

i don t understand what is: nonce: a random 64-bit, unsigned number encoded as an ASCII string in decimal! i must put is after $date (... .$date. 15948652339726849410" ... )

问题回答

I believe the call you want is:

$sessionToken = Zend_Gdata_AuthSub::getAuthSubSessionToken($singleUseToken, $client);

Calling Zend_Gdata_AuthSub::AuthSubRevokeToken() will revoke your single use token. There s a great tip here that demonstrates the full secure AuthSub flow.

There is way to do this without the client library elaborated here:http://codershelpingcoders.com/

Have a look if you want to.





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签