• Resolved jodiplannes

    (@jodiplannes)


    Hi!

    The problem:
    I am having trouble with requesting an Access Token for the Management API.

    My attempt (inpired from your guide here):

    
    $domain     = WP_Auth0_Options::Instance()->get('domain');
        $client_id  = WP_Auth0_Options::Instance()->get('client_id');
        $client_secret  = WP_Auth0_Options::Instance()->get('client_secret');
    
        $curl = curl_init();
        
        curl_setopt_array($curl, [
        CURLOPT_URL =>  "https://" . $domain . "/oauth/token",
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_ENCODING => "",
        CURLOPT_MAXREDIRS => 10,
        CURLOPT_TIMEOUT => 30,
        CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
        CURLOPT_CUSTOMREQUEST => "POST",
        CURLOPT_POSTFIELDS => "grant_type=client_credentials&client_id=" . $client_id . "&client_secret=" . $client_secret . "&audience=https://" . $domain . "/api/v2/",
        CURLOPT_HTTPHEADER => [
            "content-type: application/x-www-form-urlencoded"
        ],
        ]);
    
        $response = curl_exec($curl);
        $err = curl_error($curl); 
    
        curl_close($curl);
    
        if ($err) {
        echo "cURL Error #:" . $err;
        } else {
        echo 'response' . $response;
        }

    Response: 404, Not Found

    I do not understand why it does not work. Domain, client_id and client_secret seem to contain the correct values.

    My questions:

    1. Is there something wrong with the code above, and how do i fix it?
    2. Is there a better way of doing this? (i.e. a built in function in the plugin I could use)

    Bonus:
    What I am trying to accomplish is updating metadata-fields for the current user in a plugin. I have got it working with javascript, but would prefer to do it using php instead. This leads me to a bonus question:

    • Is there a simple, built in (or just simple) function to update the metadata of a user?
    • This topic was modified 5 years, 4 months ago by jodiplannes.

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
  • Thread Starter jodiplannes

    (@jodiplannes)

    It turned out that the code was fine.
    The problem was running the wrong piece of code
    (The function for making calls after the token has been retrieved).

    If you think this might help someone out you can leave it up, but otherwise I can remove it

Viewing 1 replies (of 1 total)

The topic ‘Management API token endpoint return 404’ is closed to new replies.