locked
Authentication Error using Python SDK RRS feed

  • Question

  • Attempting to authenticate via the Python SDK. My code looks like this:

    from bingads.v13.reporting import *
    from bingads import *
    from auth_helper import *
    import os

    oauth = OAuthWebAuthCodeGrant(client_id = 'client_id goes here',
                                  client_secret = 'client_secret goes here',
                                  redirection_uri = 'https://login.microsoftonline.com/common/oauth2/nativeclient')

    authorization_data=AuthorizationData(
        account_id=00000000,
        customer_id=00000000,
        developer_token='dev token',
        authentication='OAuthWebAuthCodeGrant')

    authenticate_with_oauth(authorization_data)

    I'm redirected to a blank page and copy the URI with the authorization code. However, when I submit the uri & code, I get the following error: 

    OAuthTokenRequestException: error_code: invalid_client, error_description: AADSTS7000218: The request body must contain the following parameter: 'client_assertion' or 'client_secret'.
    Trace ID: 0c625a8a-7574-4e55-87a0-a548d6ebc000
    Correlation ID: b9864d19-f56e-4f7e-9551-dbd9fe4541e1
    Timestamp: 2019-10-15 17:08:32Z

    Can anybody identify where I'm going wrong?

    Tuesday, October 15, 2019 5:27 PM

Answers

  • I suggest if you are leveraging the samples and auth_helper.py please use OAuthDesktopMobileAuthCodeGrant as a baseline. The current samples package assumes you are using all dependencies and set CLIENT_ID here. For example this works for me without any other modifications:

    # Required
    
    DEVELOPER_TOKEN=MyDevToken 
    ENVIRONMENT='production' 
    
    # The CLIENT_ID is required and CLIENT_STATE is recommended.
    # The REFRESH_TOKEN should always be in a secure location.
    
    CLIENT_ID='6731de76-14a6-49ae-97bc-6eba6914391e'
    CLIENT_STATE='ClientStateGoesHere'
    REFRESH_TOKEN="refresh.txt"

    I am using the Bing Ads Python SDK version 12.13.6.

    If you prefer to start with a web app and then modify it for reporting, I suggest starting here:

    https://docs.microsoft.com/en-us/advertising/guides/walkthrough-web-application-python?view=bingads-13#create-a-project-environment-for-django

    Does this help?

    Wednesday, October 16, 2019 11:02 PM

All replies

  • Please try "authentication=oauth)" instead of "authentication='OAuthWebAuthCodeGrant')" shown above. Also note you should not need to set the redirection_uri unless you have a custom URI e.g., localhost or contoso.com/callback. 

    I hope this helps,

    Eric

    Wednesday, October 16, 2019 12:14 PM
  • Thank you for the reply, Eric. I switched to "authentication = oauth". OAuthWebAuthCodeGrant requires redirect_uri as a positional argument... Having tried a number of solutions, including 'None', I am still getting the same error as above.

    Why might I be getting this error when the client secret is stored in my 'oauth' object?

    Wednesday, October 16, 2019 4:14 PM
  • OK. So if you are not using a web redirect how about use OAuthDesktopMobileAuthCodeGrant as shown here: https://docs.microsoft.com/en-us/advertising/guides/walkthrough-desktop-application-python?view=bingads-13

    In case there is an issue with how the app was registered, have you tried the public example client ID documented here? You can also try your client ID with the powershell script here

    Thanks,

    Eric

    Wednesday, October 16, 2019 4:24 PM
  • Thanks, Eric. Both OAuthDesktopMobileAuthCodeGrant and public example client ID solutions are throwing the same error at the authentication step.
    Wednesday, October 16, 2019 8:30 PM
  • I suggest if you are leveraging the samples and auth_helper.py please use OAuthDesktopMobileAuthCodeGrant as a baseline. The current samples package assumes you are using all dependencies and set CLIENT_ID here. For example this works for me without any other modifications:

    # Required
    
    DEVELOPER_TOKEN=MyDevToken 
    ENVIRONMENT='production' 
    
    # The CLIENT_ID is required and CLIENT_STATE is recommended.
    # The REFRESH_TOKEN should always be in a secure location.
    
    CLIENT_ID='6731de76-14a6-49ae-97bc-6eba6914391e'
    CLIENT_STATE='ClientStateGoesHere'
    REFRESH_TOKEN="refresh.txt"

    I am using the Bing Ads Python SDK version 12.13.6.

    If you prefer to start with a web app and then modify it for reporting, I suggest starting here:

    https://docs.microsoft.com/en-us/advertising/guides/walkthrough-web-application-python?view=bingads-13#create-a-project-environment-for-django

    Does this help?

    Wednesday, October 16, 2019 11:02 PM