Skip to content

OAuth signature does not match in some cases #34

@hissy

Description

@hissy

Hi, I'm trying to retrieve posts with authentication required parameters. I'm using Zend_OAuth library, and already succeeded to get access token and get authentication required data. However, with some parameters, I got "OAuth signature does not match" error (code: json_oauth1_signature_mismatch). Here is my code. Very normal.

$token = new Zend_Oauth_Token_Access;
$token->setParams(array(
    Zend_Oauth_Token_Access::TOKEN_PARAM_KEY => $oauth_token,
    Zend_Oauth_Token_Access::TOKEN_SECRET_PARAM_KEY => $oauth_token_secret
));
$client = $token->getHttpClient(array(
    'consumerKey' => $oauth_key,
    'consumerSecret' => $oauth_secret
));
$client->setUri( $wp_rest_api_url . '/posts' );
$client->setParameterGet( 'filter[posts_per_page]', $num );
$client->setMethod( Zend_Http_Client::GET );
$res = $client->request();

The problem is the filter[posts_per_page] key.

In ZendFramework, encode each parameter key and values first, then build query string, finally urlencode it again.
https://github.com/zendframework/ZendOAuth/blob/c0eca2ca6e930a5464a6a76ac1eb293237304d2a/library/ZendOAuth/Signature/AbstractSignature.php#L115

In WP-API/OAuth1, each parameter key and values are not encoded.

$string = $param_key . '=' . $param_value; // join with equals sign

So, which way is correct? IMHO, ZF way.
3.4.1.3.2. Parameters Normalization http://tools.ietf.org/html/rfc5849#section-3.4.1.3.2

But unfortunately, I don't have any experience of other OAuth provider, so I'd like to hear others opinion.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions