Skip to content

API access on behalf of your clients (web flow)

Daniel Rodriguez edited this page Feb 16, 2023 · 3 revisions

This guide will walk you through how to setup OAuth2 for API access on behalf of your clients using web flow.

Step 1 - Creating OAuth2 credentials

Follow the steps for the product you're using to generate a client ID and secret, as well as callback URLs that can be handled by your web app, then come back to this page.

Step 2 - Setting up the client library

Under the authentication section of your ad_manager_api.yml file, insert your client ID and secret.

:oauth2_client_id: INSERT_OAUTH2_CLIENT_ID_HERE
:oauth2_client_secret: INSERT_OAUTH2_CLIENT_SECRET_HERE

Then handle the OAuth2 callback:

  1. Call the authorize method on the API object with an additional argument specifying the :oauth2_callback. This will bring the user to a consent screen.

Consent screen allow

  1. In your callback method, call authorize again with the callback url, and the :oauth2_verification_code from the response, after the user granted access. Example code:
api.authorize(
    {
        :oauth2_callback => login_callback_url,
        :oauth2_verification_code => params[:code]
    }
)
  1. Store the user's token along with their ID in your database so you can retrieve it the next time they login to your system, so they do not have to re-grant authorization each time.