Yahoo DSP API Authentication Error: Access Token

414 Views Asked by At

I have been following the guide to obtain an Access Token for Yahoo DSP API through: https://developer.yahooinc.com/dsp/api/docs/authentication/vmdn-auth-overview.html

I get to the part Generate a JWT Access Token, and request an access token (with all the headers and paramenters). When posting a request, I get an error: 'Internal Server error', which in the error codes in the documents says: Try Again Later (without further explanations). I am assuming the request went through and there is something wrong on their side.

Yahoo has no user help suppport. If anyone could please shine some light other than "Try Again Later".

Thank you

#flurry

1

There are 1 best solutions below

0
cicokire On

Unfortunately, Yahoo DSP API docs isn't the most intuitive and straightforward docs there is and it requires a little effort to find and do the right thing.

Although, this collection helped me out when trying to obtain an Access Token from Yahoo DSP API (check the pre-request script):

https://www.postman.com/postman/workspace/postman-team-collections/request/4630964-df7c0fff-babc-420d-ad45-e9e731d5c50f

Not sure in which programming language are you doing the integration for Yahoo DSP API, but if you need a PHP code sample, here's what I used:

    $response = $this->httpClient->request(
        'POST',
        'https://id.b2b.yahooinc.com/identity/oauth2/access_token',
        [
            'form_params' => [
                'grant_type' => 'client_credentials',
                'client_assertion_type' => 'urn:ietf:params:oauth:client-assertion-type:jwt-bearer',
                'client_assertion' => $this->prepareSignedJWT(),
                'scope' => 'dsp-api-access',
                'realm' => 'dsp'
            ],
            'headers' => [
                'Accept' => 'application/json',
                'Content-Type' => 'application/x-www-form-urlencoded',
            ]
        ]
    );

Where prepareSignedJWT being:

private function prepareSignedJWT()
{
    $header = [
        'typ' => 'JWT',
        'alg' => 'HS256'
    ];

    $body = [
        'aud' => 'https://id.b2b.yahooinc.com/identity/oauth2/access_token?realm=dsp',
        'iss' => $this->config->getClientId(),
        'sub' => $this->config->getClientId(),
        'iat' => time(),
        'exp' => time() + 600, // 10 min from time of creation
    ];

    $encodedHeader = base64_encode(json_encode($header));
    $encodedBody = base64_encode(str_replace('\/', "/", json_encode($body)));

    $token = $encodedHeader . '.' . $encodedBody;

    $signature = hash_hmac('sha256', $token, $this->config->getClientSecret(), true);
    $encodedSignature = base64_encode($signature);

    return $token . '.' . $encodedSignature;
}

And $this->config is just an config object I use in the code.

Hope you find this answer useful, Cheers.