Question

I have the following code in php:

define("TOKEN_URL", "https://wamsprodglobal001acs.accesscontrol.windows.net/v2/OAuth2-13");



 $arrData = array(
                'grant_type=client_credentials',
                'client_id='.CLIENT_ID,
                'client_secret='.urlencode(ACCESS_KEY),
                'scope=urn%3aWindowsAzureMediaServices'
            );


            $arrHeader = array(
                'Content-length:'.strlen($this->generateData($arrData))
            );

            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, TOKEN_URL);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $this->generateData($arrData));
            curl_setopt($ch, CURLOPT_HTTPHEADER, $arrHeader);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            $data = curl_exec($ch);
            curl_close($ch);
            $arrToken = json_decode($data);

I am unable to get the token code. Please can anyone check what could be wrong?

Was it helpful?

Solution

There could be a few issues:

  1. You could simplify a few things and use http_build_query():

    $data = http_build_query(array(
        'grant_type' => 'client_credentials',
        'client_id' => CLIENT_ID,
        'client_secret' => ACCESS_KEY,
        'scope' => 'urn:WindowsAzureMediaServices',
    ));
    $ch = curl_init(TOKEN_URL);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    if (($res = curl_exec($ch)) === false) {
        die(curl_error($ch));
    }
    $arrToken = json_decode($res);
    
  2. If there's an error, the first thing to make sure is whether you have an updated list of CA certificates.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top