BingAds / BingAds-PHP-SDK

Other
56 stars 46 forks source link

oAuth Example #112

Closed chiragvels closed 4 years ago

chiragvels commented 5 years ago

Hi,

Does Library example for oAuth2callback.php is supported for Microsoft identity platform endpoint?

Please suggest PHP documentation for same.

How I can use prompt=login with MSIdentityV2 platform?

Thanks,

chiragvels commented 5 years ago

It is giving me error after getting code Microsoft\BingAds\Auth\OAuthTokenRequestException in /var/www/html/bingads/vendor/microsoft/bingads/src/Auth/UriOAuthService.php:106 Stack trace: #0 /var/www/html/bingads/vendor/microsoft/bingads/src/Auth/OAuthWithAuthorizationCode.php(100): Microsoft\BingAds\Auth\UriOAuthService->GetAccessTokens(Object(Microsoft\BingAds\Auth\OAuthRequestParameters), 'Production', false) #1 /var/www/html/bingads/vendor/microsoft/bingads/samples/WebAuthentication/OAuth2Callback.php(64): Microsoft\BingAds\Auth\OAuthWithAuthorizationCode->RequestOAuthTokensByResponseUri('localhost/...') #2 {main}

eric-urban commented 5 years ago

@chiragvels I'll investigate and get back to you. Thanks!

chiragvels commented 5 years ago

Thanks @eric-urban , I think this works with MSIdentityV2 platform, but not finding option to add consent screen.

I wanted to ask user to authenticate and give consent every time when they try to authenticate.

Thanks,

eric-urban commented 5 years ago

@chiragvels have you tried implicit grant flow via OAuthDesktopMobileImplicitGrant? Otherwise the authorization URL can be updated for example with 'prompt=login' or 'prompt=consent'.

chiragvels commented 5 years ago

Yes, I was trying OAuthDesktopMobileImplicitGrant, but let me add 'prompt=login' or 'prompt=consent' this at end of Forming Authorization Url.

eric-urban commented 5 years ago

@chiragvels you can append the login and/or consent prompt to the SDK authorization endpoint. For example I appended "&prompt=login%20consent" below.

static function RequestUserConsent()
{
    print "You need to provide consent for the application to access your Microsoft Advertising accounts. " .
            "Copy and paste this authorization endpoint into a web browser and sign in with a Microsoft account " . 
            "with access to a Microsoft Advertising account: \n\n" . $GLOBALS['AuthorizationData']->Authentication->GetAuthorizationEndpoint() .
            "&prompt=login%20consent". "\n\nAfter you have granted consent in the web browser for the application to access your Microsoft Advertising accounts, " .
            "please enter the response URI that includes the authorization 'code' parameter: \n\n";

    $responseUri = fgets(STDIN);
    print "\n";

    $GLOBALS['AuthorizationData']->Authentication->RequestOAuthTokensByResponseUri(trim($responseUri));
    AuthHelper::WriteOAuthRefreshToken($GLOBALS['AuthorizationData']->Authentication->OAuthTokens->RefreshToken);
}

Note, the original RequestUserConsent sample is available in AuthHelper.php.

Will this work for you?

chiragvels commented 4 years ago

Hi @eric-urban ,

I was recently facing issue with this line.

Here I am not getting any values. An simply throws me error.

Can I know exact reason for same?

Does this example or API will not work if we have old credentials? and not Microsoft identity platform?

Thanks,