BingAds / BingAds-Python-SDK

Other
117 stars 162 forks source link

How can I automatically generate a new refresh_token after expiration using Bing python SDK? #89

Closed aj07mm closed 6 years ago

aj07mm commented 6 years ago

The example on the repo only does in a manual way coping and pasting the redirect uri on the terminal: https://github.com/BingAds/BingAds-Python-SDK/blob/06c2125ebf25b524a384a29c217752738280eabb/examples/BingAdsPythonConsoleExamples/BingAdsPythonConsoleExamples/v12/auth_helper.py#L90

eric-urban commented 6 years ago

@aj07mm consent is required at least once as shown in the example. Thereafter you can call request_oauth_tokens_by_refresh_token without manual interaction. As noted in this doc:

Refresh tokens are, and always will be, completely opaque to your application. They are long-lived e.g., 90 days for public clients, but the app should not be written to expect that a refresh token will last for any period of time. Refresh tokens can be invalidated at any moment, and the only way for an app to know if a refresh token is valid is to attempt to redeem it by making a token request. Even if you continuously refresh the token on the same device with the most recent refresh token, you should expect to start again from Step 1 and request user consent if, for example you signed the user out, the Microsoft Account user changed their password, removed a device from their list of trusted devices, or removed permissions for your application to authenticate on their behalf. At any time without prior warning Microsoft may determine that user consent should again be granted. In that case, the authorization service would return an invalid grant error.

I hope this helps!