Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get_consumer() meta_query not returning the correct consumer application. #94

Closed
kosso opened this issue Nov 22, 2015 · 2 comments
Closed
Labels

Comments

@kosso
Copy link
Contributor

kosso commented Nov 22, 2015

This was an issue a while ago which seems to still be present.

If you have more than one client app (consumer) set up, you might find some apps getting signature mismatches.

After spending some time debugging the Authorization signature and headers being sent by a test client, and also looking deeply at the server signature generation, I discovered that the signature mismatch was due to get_consumer() (in class-wp-json-authentication.php) returning the wrong consumer.

The current master has this query :

$query = new WP_Query();
$consumers = $query->query( array(
    'post_type' => 'json_consumer',
    'post_status' => 'any',
    'meta_query' => array(
        array(
            'meta_key' => 'key',
            'meta_value' => $key,
        ),
        array(
            'meta_key' => 'type',
            'meta_value' => $this->type,
        ),
    ),
) );

But this is returning an array of all consumers/registered applications. Not the one based on its key meta_value.

I can't seem to form the correct meta_query to give back the consumer I expect.

So, changing the query to this has fixed is for me :


$consumers = $query->query( 
    array(
        'post_type' => 'json_consumer',
        'post_status' => 'any',
        'meta_key' => 'key',
        'meta_value' => $key
    )
);

Which returns the correct consumer, and thus, the correct key to use when creating the signature to compare.


WP : beta nightlies 4.4-beta4-35724
WP-API/WP-API - WP-API-2.0-beta7
WP-API/OAuth1 - master as of today

@kosso
Copy link
Contributor Author

kosso commented Nov 22, 2015

Update to this: I figured out how the meta_query should be properly constructed :

$consumers = $query->query( array(
    'post_type' => 'json_consumer',
    'post_status' => 'any',
    'meta_query' => array(
        array(
            'key' => 'key',
            'value' => $key,
        ),
        array(
            'key' => 'type',
            'value' => $this->type,
        ),
    ),
));

Replace meta_key and meta_value with key and value in the meta_query array.

@rmccue
Copy link
Member

rmccue commented Nov 22, 2015

Hmm, thanks for this, I'll take a look!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants