Skip to content

get_parameters() is ignoring data params sent as application/json #95

@kosso

Description

@kosso

get_parameters() is still ignoring extra post data parameters sent as application/json.
Is this on purpose?

When merging all $_GET and $_POST parameters, along with Authorization headers, since PHP 5.6 data sent as application/json is ignored in $_POST, so we need to also collect parameters from posted JSON data using php://input

After line 93 of class-wp-json-authentication-oauth1.php

// ... 
        $params = array_merge( $_GET, $_POST );
        $params = wp_unslash( $params );

        if($_SERVER['CONTENT_TYPE']=='application/json'){
            $raw_post_data_params = json_decode(file_get_contents('php://input'), true);
            if ( ! empty( $raw_post_data_params ) ) {
                $raw_post_data_params = wp_unslash( $raw_post_data_params );
                $params = array_merge( $params, $raw_post_data_params );
                ksort($params);
            }
        }

// .....

This fixed my Missing OAuth parameter oauth_verifier error.

Now, I can finally connect a client to my server and get an access_token for its user, since my OAuth client was sending the oauth_verifier as application/json. (And likely to interact with the API in this way for all other POST requests).

I have also successfully tested creating a new post with my newly acquired access_token/secret after making these changes, when sending the data as application/json.

One thing, however... the OAuth1.0a signing requests spec does state:

The request parameters are collected, sorted and concatenated into a normalized string:
Parameters in the OAuth HTTP Authorization header excluding the realm parameter.
Parameters in the HTTP POST request body (with a content-type of application/x-www-form-urlencoded).
HTTP GET parameters added to the URLs in the query part (as defined by [RFC3986] section 3).

note: "(with a content-type of application/x-www-form-urlencoded)"

but this ignores the PHP5.6+ issue when sending applicaton/json formatted data.

also note: When I tested uploading a media file, I found I needed to use : multipart/form-data (in a PHP cUrl request)

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