SlideShare a Scribd company logo
AdWords API & OAuth 2.0
Life after ClientLogin




                         Google Confidential and Proprietary
Ch-Ch-Ch-Changes




     Changes are coming for
authentication of your applications.




                             Google Confidential and Proprietary
How it works today:


1. Your app talks to authentication servers (blah blah blah)
   a. Your app gets an access token (AuthToken)

2. Your app talks to the AdWords API servers
   a. Passes in Developer Key and access token
   b. Your app has to periodically re-authenticate.

Today: blah blah blah is called ClientLogin



                                               Google Confidential and Proprietary
How it will work in the new world:


1. Your app talks to authentication servers (wah wah wah)
   a. Your app gets an access token.

2. Your app talks to the AdWords API servers
   a. Passes in Developer Key and access token
   b. Your app has to periodically re-authenticate.

New: wah wah wah is done with OAuth 2.0



                                              Google Confidential and Proprietary
DON'T PANIC!




● This shouldn't be a big deal for you.

● Will improve the security of your applications and data.




                                                       Google Confidential and Proprietary
What's wrong with ClientLogin?




● Exposes username/passwords for MCC and client
  accounts.

● AuthTokens duration 2 weeks
  ○ No way to revoke issued tokens

● Sunset by 2015
  ○ Might be sooner
  ○ Deprecated since last year



                                           Google Confidential and Proprietary
Why OAuth 2.0?

● OAuth 2.0 More secure
   ○ Does not expose password/username
   ○ Only exchange OAuth tokens
● More specific access control
   ○ Tokens can have restricted scope on data
   ○ Can easily revoke a token
   ○ Reduced impact if token compromised
● No CAPTCHA challenges.
● Have learned a lot from the mess of OAuth 1.0


                                                Google Confidential and Proprietary
Using OAuth 2.0

Your Key Steps


1. Registering the OAuth application

2. Authenticating to get access token (AuthToken) and refresh token.

3. Call the AdWords API with the access token.

4. Handle token expiration.




                                                      Google Confidential and Proprietary
Using OAuth 2.0

Step 1: Registering




                Go to:
 https://code.google.com/apis/console
             and create a new project




                                        Google Confidential and Proprietary
Google APIs Console




    Google Confidential and Proprietary
Google APIs Console




    Google Confidential and Proprietary
Google APIs Console




    Google Confidential and Proprietary
Google APIs Console




    Google Confidential and Proprietary
Google APIs Console




    Google Confidential and Proprietary
Using OAuth 2.0




Google Confidential and Proprietary
Using OAuth 2.0

Step 2: Coding for OAuth 2.0


● Are you using the client libraries?
   ● Most are already up to date
      ○ Ruby
      ○ Java (new)
      ○ .NET
      ○ Python
      ○ Perl
   ● Rest will be coming soon

                                        Google Confidential and Proprietary
Using OAuth 2.0

Step 2: Coding by Hand


1. Send a request to the Google Authorization Server, with:
    a.   what you want access to - https://adwords.google.
         com/api/adwords
    b.   and the client_id and the client_secret

2. Next step requires actual user interact with a Google webpage, that
   allows you to:
    a.   login with your MCC or client account credentials
    b.   authorize access to the given scope

3. This returns the accessToken and refreshToken to your app




                                                             Google Confidential and Proprietary
Step 2: How to use the tokens returned


       accessToken

● Access for ~ 1 hour

● Then expires




                                         Google Confidential and Proprietary
Step 2: How to use the tokens returned


       accessToken                 refreshToken

● Access for ~ 1 hour       ● Regenerates accessTokens
                            ● No user interaction required
● Then expires




                                            Google Confidential and Proprietary
Step 2: How to use the tokens returned


       accessToken                  refreshToken

● Access for ~ 1 hour       ● Regenerates accessTokens
                            ● No user interaction required
● Then expires
                            ● Be sure to store it




                                              Google Confidential and Proprietary
Step 2 (by hand): Let's look at some code




  (This code is available on the web, so don't worry if you
                   can't follow it all now.)
                     http://goo.gl/s6nmR




                                                Google Confidential and Proprietary
Sample code - authorize()
public Credential authorize() throws Exception {
  // set up file credential store to save/load tokens
  FileCredentialStore credentialStore =
      new FileCredentialStore(
         new File("~/Desktop/oauth.json"),JSON_FACTORY);
  // set up authorization code flow
  ...

    // actually authorize
    ...
}




                                          Google Confidential and Proprietary
Sample code - authorize()
public Credential authorize() throws Exception {
  // set up file credential store to save/load tokens
  FileCredentialStore credentialStore =
      new FileCredentialStore(
         new File("~/Desktop/oauth.json"),JSON_FACTORY);

    // set up authorization code flow
    GoogleAuthorizationCodeFlow flow = new
      GoogleAuthorizationCodeFlow
        .Builder(HTTP_TRANSPORT, JSON_FACTORY,
                  CLIENT_ID, CLIENT_SECRET, AWAPI_SCOPE)
        .setCredentialStore(credentialStore)
        .build();

    // actually authorize
    ...
}
                                             Google Confidential and Proprietary
Sample code - authorize()
public Credential authorize() throws Exception {
  // set up file credential store to save/load tokens
  ...

    // set up authorization code flow
    GoogleAuthorizationCodeFlow flow = new
      GoogleAuthorizationCodeFlow
        .Builder(HTTP_TRANSPORT, JSON_FACTORY,
                  CLIENT_ID, CLIENT_SECRET, AWAPI_SCOPE)
        .setCredentialStore(credentialStore)
        .build();

    // actually authorize
    return new AuthorizationCodeInstalledApp(
        flow, new LocalServerReceiver())
        .authorize("user");
}
                                             Google Confidential and Proprietary
Sample code - connect()
// Construct AdWordsSession object
AdWordsSession session =
  new AdWordsSession
   .Builder()
   .fromFile()
   .withOAuth2Credential(credential)
   .build();

// Construct AdWordsServices object
AdWordsServices adWordsServices = new AdWordsServices();




                                          Google Confidential and Proprietary
Futher Info

Authentication Flows: You've got choices


● Web Server Flow
   ○   Consent: Browser for consent
   ○   Response: Redirects user to callback endpoint



● Installed App Flow
   ○   Consent: URL provided - user pastes into browser
   ○   Response: Display code - user paste into app
                                  OR
   ○   Consent: URL Provided - in app browser
   ○   Response: Captures code - app returns to auth server

                                                 User Interaction | Programmatic

                                                           Google Confidential and Proprietary
Further Info

OAuth 2.0 Best Practices



● Use the refreshToken only on accessToken expiry

● Store the refreshToken for re-use
  ○ To reduce user interaction

● Officially clientCustomerId needed only for reports
   ○ Recommended for all



                                         Google Confidential and Proprietary
Coding by Hand: Handling Expired Tokens




● What? I need to handle token expirations?

● Theoretically, you should be able to restart requests
  today!
   ○ ClientLogin auth tokens can time out.
   ○ Server calls can fail in a way that suggest you should
      retry.




                                                 Google Confidential and Proprietary
Further Info

Coding by Hand: Error Handling


● Error: AuthenticationError.OAUTH_TOKEN_INVALID
   ○   On: accessToken expired
   ○   Resolution: use refreshToken



● Error: AuthenticationError.INVALID_GRANT_ERROR
   ○   On: accessToken revoked
   ○   Resolution: re-auth app with user consent




                                                   Google Confidential and Proprietary
Summary




● Change is coming

● Shouldn't be a big deal

   ○ Will actually improve your app security

● Client library users should be ready to go now or soon.




                                               Google Confidential and Proprietary
Q&A
Resources


Docs Links:

https://developers.google.com/accounts/docs/OAuth2

Register app, get client_id & client_secret:

https://code.google.com/apis/console

Java Sample Code:

http://goo.gl/s6nmR




                                                 Google Confidential and Proprietary

More Related Content

PDF
OAuth 2.0
PDF
AdWords API & OAuth 2.0, Advanced
PDF
AwReporting Tool
PDF
Exploring Google APIs 102: Cloud vs. non-GCP Google APIs
PPTX
SSO with Social Login Integration & FastAPI Simplified
PPTX
Oauth 2.0 Introduction and Flows with MuleSoft
PDF
Google auth dispelling the magic
PPTX
Google authentication
OAuth 2.0
AdWords API & OAuth 2.0, Advanced
AwReporting Tool
Exploring Google APIs 102: Cloud vs. non-GCP Google APIs
SSO with Social Login Integration & FastAPI Simplified
Oauth 2.0 Introduction and Flows with MuleSoft
Google auth dispelling the magic
Google authentication

Similar to AdWords API and OAuth 2.0 (20)

PDF
Securing a Web App with Security Keys
PPTX
OAuth and Open-id
PDF
The Many Flavors of OAuth - Understand Everything About OAuth2
PDF
Build an AI/ML-driven image archive processing workflow: Image archive, analy...
PPTX
Securing api with_o_auth2
PDF
OAuth 2.0 refresher Talk
PDF
Build an AI/ML-driven image archive processing workflow: Image archive, analy...
PDF
[APIdays INTERFACE 2021] The Evolution of API Security for Client-side Applic...
PDF
INTERFACE, by apidays - The Evolution of API Security by Johann Dilantha Nal...
PDF
Accessing APIs using OAuth on the federated (WordPress) web
PDF
Securing a Web App with Passwordless Web Authentication
PPTX
How to build Simple yet powerful API.pptx
PDF
CIS13: So, You Want to Be a Relying Party: Federated Login with Google Identi...
PDF
Introduction to the Globus Platform for Developers
PDF
The Glass Class - Tutorial 2 - Mirror API
PDF
Keeping Pace with OAuth’s Evolving Security Practices.pdf
PDF
Google+ Login - A Primer
PDF
Stateless Auth using OAuth2 & JWT
PDF
Google external login setup in ASP (1).pdf
PDF
Google auth - dispelling the magic
Securing a Web App with Security Keys
OAuth and Open-id
The Many Flavors of OAuth - Understand Everything About OAuth2
Build an AI/ML-driven image archive processing workflow: Image archive, analy...
Securing api with_o_auth2
OAuth 2.0 refresher Talk
Build an AI/ML-driven image archive processing workflow: Image archive, analy...
[APIdays INTERFACE 2021] The Evolution of API Security for Client-side Applic...
INTERFACE, by apidays - The Evolution of API Security by Johann Dilantha Nal...
Accessing APIs using OAuth on the federated (WordPress) web
Securing a Web App with Passwordless Web Authentication
How to build Simple yet powerful API.pptx
CIS13: So, You Want to Be a Relying Party: Federated Login with Google Identi...
Introduction to the Globus Platform for Developers
The Glass Class - Tutorial 2 - Mirror API
Keeping Pace with OAuth’s Evolving Security Practices.pdf
Google+ Login - A Primer
Stateless Auth using OAuth2 & JWT
Google external login setup in ASP (1).pdf
Google auth - dispelling the magic
Ad

More from marcwan (20)

PDF
Mcc scripts deck (日本語)
PDF
Getting started with Google Analytics and the AdWords API
PDF
Bid Estimation with the AdWords API (v2)
PDF
Opportunity Analysis with Kratu (v2)
PDF
Opportunity Analysis with Kratu
PDF
07. feeds update
PDF
AdWords Scripts and MCC Scripting
PDF
AwReporting Update
PDF
Getting Started with AdWords API and Google Analytics
PDF
Shopping Campaigns and AdWords API
PDF
API Updates for v201402
PDF
AdWords API Targeting Options
PDF
Reporting Tips and Tricks (Spanish)
PDF
Rate limits and performance (Spanish)
PDF
OAuth 2.0 (Spanish)
PDF
End to-end how to build a platform (Spanish)
PDF
AwReporting tool introduction (Spanish)
PDF
Api update rundown (Spanish)
PDF
AdWords Scripts (Spanish)
PDF
Mobile landing pages (Spanish)
Mcc scripts deck (日本語)
Getting started with Google Analytics and the AdWords API
Bid Estimation with the AdWords API (v2)
Opportunity Analysis with Kratu (v2)
Opportunity Analysis with Kratu
07. feeds update
AdWords Scripts and MCC Scripting
AwReporting Update
Getting Started with AdWords API and Google Analytics
Shopping Campaigns and AdWords API
API Updates for v201402
AdWords API Targeting Options
Reporting Tips and Tricks (Spanish)
Rate limits and performance (Spanish)
OAuth 2.0 (Spanish)
End to-end how to build a platform (Spanish)
AwReporting tool introduction (Spanish)
Api update rundown (Spanish)
AdWords Scripts (Spanish)
Mobile landing pages (Spanish)
Ad

Recently uploaded (20)

PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Approach and Philosophy of On baking technology
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Machine learning based COVID-19 study performance prediction
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PPTX
Cloud computing and distributed systems.
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Approach and Philosophy of On baking technology
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Machine learning based COVID-19 study performance prediction
“AI and Expert System Decision Support & Business Intelligence Systems”
Per capita expenditure prediction using model stacking based on satellite ima...
Mobile App Security Testing_ A Comprehensive Guide.pdf
Chapter 3 Spatial Domain Image Processing.pdf
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Spectral efficient network and resource selection model in 5G networks
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
MYSQL Presentation for SQL database connectivity
Unlocking AI with Model Context Protocol (MCP)
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Cloud computing and distributed systems.
Review of recent advances in non-invasive hemoglobin estimation
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Building Integrated photovoltaic BIPV_UPV.pdf
Agricultural_Statistics_at_a_Glance_2022_0.pdf

AdWords API and OAuth 2.0

  • 1. AdWords API & OAuth 2.0 Life after ClientLogin Google Confidential and Proprietary
  • 2. Ch-Ch-Ch-Changes Changes are coming for authentication of your applications. Google Confidential and Proprietary
  • 3. How it works today: 1. Your app talks to authentication servers (blah blah blah) a. Your app gets an access token (AuthToken) 2. Your app talks to the AdWords API servers a. Passes in Developer Key and access token b. Your app has to periodically re-authenticate. Today: blah blah blah is called ClientLogin Google Confidential and Proprietary
  • 4. How it will work in the new world: 1. Your app talks to authentication servers (wah wah wah) a. Your app gets an access token. 2. Your app talks to the AdWords API servers a. Passes in Developer Key and access token b. Your app has to periodically re-authenticate. New: wah wah wah is done with OAuth 2.0 Google Confidential and Proprietary
  • 5. DON'T PANIC! ● This shouldn't be a big deal for you. ● Will improve the security of your applications and data. Google Confidential and Proprietary
  • 6. What's wrong with ClientLogin? ● Exposes username/passwords for MCC and client accounts. ● AuthTokens duration 2 weeks ○ No way to revoke issued tokens ● Sunset by 2015 ○ Might be sooner ○ Deprecated since last year Google Confidential and Proprietary
  • 7. Why OAuth 2.0? ● OAuth 2.0 More secure ○ Does not expose password/username ○ Only exchange OAuth tokens ● More specific access control ○ Tokens can have restricted scope on data ○ Can easily revoke a token ○ Reduced impact if token compromised ● No CAPTCHA challenges. ● Have learned a lot from the mess of OAuth 1.0 Google Confidential and Proprietary
  • 8. Using OAuth 2.0 Your Key Steps 1. Registering the OAuth application 2. Authenticating to get access token (AuthToken) and refresh token. 3. Call the AdWords API with the access token. 4. Handle token expiration. Google Confidential and Proprietary
  • 9. Using OAuth 2.0 Step 1: Registering Go to: https://code.google.com/apis/console and create a new project Google Confidential and Proprietary
  • 10. Google APIs Console Google Confidential and Proprietary
  • 11. Google APIs Console Google Confidential and Proprietary
  • 12. Google APIs Console Google Confidential and Proprietary
  • 13. Google APIs Console Google Confidential and Proprietary
  • 14. Google APIs Console Google Confidential and Proprietary
  • 15. Using OAuth 2.0 Google Confidential and Proprietary
  • 16. Using OAuth 2.0 Step 2: Coding for OAuth 2.0 ● Are you using the client libraries? ● Most are already up to date ○ Ruby ○ Java (new) ○ .NET ○ Python ○ Perl ● Rest will be coming soon Google Confidential and Proprietary
  • 17. Using OAuth 2.0 Step 2: Coding by Hand 1. Send a request to the Google Authorization Server, with: a. what you want access to - https://adwords.google. com/api/adwords b. and the client_id and the client_secret 2. Next step requires actual user interact with a Google webpage, that allows you to: a. login with your MCC or client account credentials b. authorize access to the given scope 3. This returns the accessToken and refreshToken to your app Google Confidential and Proprietary
  • 18. Step 2: How to use the tokens returned accessToken ● Access for ~ 1 hour ● Then expires Google Confidential and Proprietary
  • 19. Step 2: How to use the tokens returned accessToken refreshToken ● Access for ~ 1 hour ● Regenerates accessTokens ● No user interaction required ● Then expires Google Confidential and Proprietary
  • 20. Step 2: How to use the tokens returned accessToken refreshToken ● Access for ~ 1 hour ● Regenerates accessTokens ● No user interaction required ● Then expires ● Be sure to store it Google Confidential and Proprietary
  • 21. Step 2 (by hand): Let's look at some code (This code is available on the web, so don't worry if you can't follow it all now.) http://goo.gl/s6nmR Google Confidential and Proprietary
  • 22. Sample code - authorize() public Credential authorize() throws Exception { // set up file credential store to save/load tokens FileCredentialStore credentialStore = new FileCredentialStore( new File("~/Desktop/oauth.json"),JSON_FACTORY); // set up authorization code flow ... // actually authorize ... } Google Confidential and Proprietary
  • 23. Sample code - authorize() public Credential authorize() throws Exception { // set up file credential store to save/load tokens FileCredentialStore credentialStore = new FileCredentialStore( new File("~/Desktop/oauth.json"),JSON_FACTORY); // set up authorization code flow GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow .Builder(HTTP_TRANSPORT, JSON_FACTORY, CLIENT_ID, CLIENT_SECRET, AWAPI_SCOPE) .setCredentialStore(credentialStore) .build(); // actually authorize ... } Google Confidential and Proprietary
  • 24. Sample code - authorize() public Credential authorize() throws Exception { // set up file credential store to save/load tokens ... // set up authorization code flow GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow .Builder(HTTP_TRANSPORT, JSON_FACTORY, CLIENT_ID, CLIENT_SECRET, AWAPI_SCOPE) .setCredentialStore(credentialStore) .build(); // actually authorize return new AuthorizationCodeInstalledApp( flow, new LocalServerReceiver()) .authorize("user"); } Google Confidential and Proprietary
  • 25. Sample code - connect() // Construct AdWordsSession object AdWordsSession session = new AdWordsSession .Builder() .fromFile() .withOAuth2Credential(credential) .build(); // Construct AdWordsServices object AdWordsServices adWordsServices = new AdWordsServices(); Google Confidential and Proprietary
  • 26. Futher Info Authentication Flows: You've got choices ● Web Server Flow ○ Consent: Browser for consent ○ Response: Redirects user to callback endpoint ● Installed App Flow ○ Consent: URL provided - user pastes into browser ○ Response: Display code - user paste into app OR ○ Consent: URL Provided - in app browser ○ Response: Captures code - app returns to auth server User Interaction | Programmatic Google Confidential and Proprietary
  • 27. Further Info OAuth 2.0 Best Practices ● Use the refreshToken only on accessToken expiry ● Store the refreshToken for re-use ○ To reduce user interaction ● Officially clientCustomerId needed only for reports ○ Recommended for all Google Confidential and Proprietary
  • 28. Coding by Hand: Handling Expired Tokens ● What? I need to handle token expirations? ● Theoretically, you should be able to restart requests today! ○ ClientLogin auth tokens can time out. ○ Server calls can fail in a way that suggest you should retry. Google Confidential and Proprietary
  • 29. Further Info Coding by Hand: Error Handling ● Error: AuthenticationError.OAUTH_TOKEN_INVALID ○ On: accessToken expired ○ Resolution: use refreshToken ● Error: AuthenticationError.INVALID_GRANT_ERROR ○ On: accessToken revoked ○ Resolution: re-auth app with user consent Google Confidential and Proprietary
  • 30. Summary ● Change is coming ● Shouldn't be a big deal ○ Will actually improve your app security ● Client library users should be ready to go now or soon. Google Confidential and Proprietary
  • 31. Q&A
  • 32. Resources Docs Links: https://developers.google.com/accounts/docs/OAuth2 Register app, get client_id & client_secret: https://code.google.com/apis/console Java Sample Code: http://goo.gl/s6nmR Google Confidential and Proprietary