Bing Ads sdk V12: Error code 105, Invalid Credential (Customer Management)

788 views Asked by At

I have a problem about the error code 105 (Message: "Authentication failed. Either supplied credentials are invalid or the account is inactive") when performing a "GetUser" request. I've already understand that it's because of an incorrect access token (AuthenticationToken header element) or developer token for the target environment. So it must be about the way I set my credentials (or my credentials). Here is my code:

public function getAuthorization()
{
    $result = AuthController::getRefreshToken(); //get The refresh token, update it if necessary
    AuthController::WriteOAuthRefreshToken($result); //stock the refresh token

    $authentication = (new OAuthWebAuthCodeGrant())
            ->withEnvironment(AuthController::ApiEnvironment) //production
            ->withClientSecret(AuthController::ClientSecret)
            ->withClientId(AuthController::ClientId)
            ->withOAuthTokens(
    (new OAuthTokens())
            ->withAccessToken(json_decode($result, true)["access_token"])
            ->withRefreshToken(json_decode($result, true)["refresh_token"])
            ->withAccessTokenExpiresInSeconds(3600))
        ->withRedirectUri(AuthController::RedirectUri)
        ->withState(rand(0,999999999));

    $GLOBALS['AuthorizationData'] = (new AuthorizationData())
        ->withAuthentication($authentication)
        ->withDeveloperToken(AuthController::DeveloperToken);

    AuthController::Authenticate();
}

And here is the function to Authenticate which call the getUser Function ()

static function Authenticate()
{
    // Authenticate for Bing Ads services with a Microsoft Account. Perform a $GLOBALS['AuthorizationData']->Authentication->RequestOAuthTokensByRefreshToken($refreshToken);
    AuthController::AuthenticateWithOAuth();

    $GLOBALS['CustomerManagementProxy'] = new ServiceClient(
        ServiceClientType::CustomerManagementVersion12,
        $GLOBALS['AuthorizationData'],
        AuthController::ApiEnvironment);
    $GLOBALS['CustomerManagementProxy']->SetAuthorizationData($GLOBALS['AuthorizationData']);

    // Here is the problem
    $user = AuthController::GetUser(null, true)->User;
}

The getUser function I currently use is the same as the one in the PHP "Code Syntax" part in the documentation. I'm using the production environment with my own credentials. I've already checked my developer token and all the corresponding rights (which seems correct). I update my tokens each time I'm trying to do that request. Is there any problems about the way I set the request? If the problem is about the tokens, is there a way to check if it's correct? I precise I've tried also with the getAccount function with the same result.

Any ideas? Thanks for your time.

1

There are 1 answers

2
Eric Urban On BEST ANSWER

Here are a few ideas to explore:

  1. Can you login to the Bing Ads web application with these credentials i.e., does this user have access to a Bing Ads account?
  2. Is the OAuthTokens->AccessToken set or empty e.g., try var_dump($authentication).
  3. Try refreshing the token directly in the auth object e.g., see this sample.
  4. Log the SOAP request and response to see if AuthenticationToken was set in the GetUser call e.g., immediately after the GetUser call print the last request/response:

    print $GLOBALS['Proxy']->GetService()->__getLastRequest()."\n";
    print $GLOBALS['Proxy']->GetService()->__getLastResponse()."\n";
    

Otherwise to confirm credentials you might want to contact Bing Ads support directly.

I hope this helps!