OAuth Tokens RRS feed

  • Question

  • hi team,

    I am facing authentication problem in OAuth 2.0.  First I have get production DeveloperToken  from my bing adword account.

    After registering application got application id, application secret and redirect URI is  specified as my project web root path.
    I have following Authorization code grant flow method.  So i have run the following code in web browser

    replaced CLIENT_ID and REDIRECTURI after run this url giving access bing account will redirected to my redirect uri specified in the app with code in the url.
     Where this code should specify in my code?

    I have downloaded bing ads api sample using php composer and the above generated credentials i have specified in the vendor\microsoft\bingads\samples\V12\AuthHelper.php file

        const DeveloperToken = '68*****'; // For sandbox use BBD37VB98
        const ApiEnvironment = ApiEnvironment::Production;
        const OAuthRefreshTokenPath = 'refresh.txt';
        const ClientId = '5c2b**********************'; 
        const ClientSecret = 'zjxB*******************';

     After running the vendor\microsoft\bingads\samples\V12\ReportRequests.php file  throws an error. The error is following
    You need to provide consent for the application to access your Bing Ads accounts. Copy and paste this authorization endpoint into a web browser and sign in with a Microsoft account with access to a Bing Ads account: https://login.live.com/oauth20_authorize.srf?scope=bingads.manage&client_id=5c2*********************&response_type=code&redirect_uri=https://login.live.com/oauth20_desktop.srf After you have granted consent in the web browser for the application to access your Bing Ads accounts, please enter the response URI that includes the authorization 'code' parameter: 

    After running this url will also get code. may be this code is used for 
    AuthenticationToken in the request header. Can you give me sample code of request header in the PHP? 
    Generated code in the redirect url will expire? If it is expire how to get a refresh token programatically?

    Saturday, May 19, 2018 7:53 AM


All replies

  • The message ("You need to provide consent...") does not indicate any error. The sample is asking you to copy and paste the auth endpoint into a web browser, and then return to the console and paste the resulting URI with code fragment. For details about managing tokens please see Authentication with OAuth and Authentication with the SDKs

    I hope this helps,


    Monday, May 21, 2018 5:34 PM
  • hi,

    Thanks for your reply, I followed the  Authentication with OAuth documentation and i get access_token and refresh token by calling this url in postman https://login.live.com/oauth20_token.srf
    My question is following
    Consider I am running the
    ReportRequests file in my local system

    where should i use this generated access_token? In your examples not specified request header in php samples.
    Can you explain me to use this access_token to request ReportRequests.php file

    Saturday, May 26, 2018 12:26 PM
  • hi,

    Please specify how can i set these global variables too

    $GLOBALS['AuthorizationData'] = null;
    $GLOBALS['Proxy'] = null;
    $GLOBALS['CampaignManagementProxy'] = null; 

    I am done by the following method

     $authentication = (new OAuthWebAuthCodeGrant())

    $authorizationData = (new AuthorizationData())

    $GLOBALS['AuthorizationData'] = $authorizationData;
    $GLOBALS['Proxy'] = null;
    $GLOBALS['CampaignManagementProxy'] = null; 

    But this still have error.

    Can you please guide me to set request header in php

    Thanks and Regards


    • Edited by sandeep.cv Sunday, May 27, 2018 6:16 AM contains sensitive information
    Sunday, May 27, 2018 5:52 AM
  • The sample assumes you are storing the refresh token somewhere e.g., refresh.txt. The account and customer ID headers for the ReportRequests sample are set in AuthHelper.php. I hope this helps!
    Sunday, May 27, 2018 1:44 PM