SlideShare ist ein Scribd-Unternehmen logo
1 von 42
Downloaden Sie, um offline zu lesen
AdWords API Workshops – All rights reserved
OAuth 2.0
Cristiano Breuel, Google, Inc.

AdWords API Workshops – All rights reserved
Agenda
1. O que é OAuth 2.0?

1
2

2. Preparação
3. Obtendo um Access Token

3

4. Detalhes do fluxo OAuth 2.0
5. Melhores Práticas

AdWords API Workshops – All rights reserved

4
5
O que é OAuth 2.0?

AdWords API Workshops – All rights reserved
O que é OAuth 2.0?
● Autorização para a API do AdWords
● Seguro
● Simples
● Padronizado

AdWords API Workshops – All rights reserved
A segurança do OAuth2
● Sem Nomes de usuário ou Senhas
● Só Tokens

● Controle de acesso Específico
● Escopo restrito
● Fácil de revogar

AdWords API Workshops – All rights reserved
A simplicidade do OAuth2

Obter Acesso
Pedir aprovação

Interagir com a API do AdWords

AdWords API Workshops – All rights reserved
O padrão do OAuth2
● Você já viu essa janela?
● Consentimento do Usuário
●

Aceitar

●

Cancelar

AdWords API Workshops – All rights reserved
O Fluxo OAuth2
Conceder Accesso
1) Construir URL

3) Troca de Código

Sua Aplicação

2) Aceitar Consentimento
Usuário da MCC
Servidores OAuth2
A API do AdWords
Servidores do Google
AdWords API Workshops – All rights reserved

Interagir com a API do AdWords
4) Fazer Requisição

5) Renovar Accesso
Acesso inclui 2 Tokens
● access_token

● refresh_token

● Para fazer requisições

● Atualiza o access_token

● Tempo de vida 60 minutos

● Tempo de vida indefinido
● Armazene!

AdWords API Workshops – All rights reserved
Acesso inclui 2 Tokens
● access_token

● refresh_token

● Para fazer requisições

● Atualiza o access_token

● Tempo de vida 60 minutos

● Tempo de vida indefinido
● Armazene!

AdWords API Workshops – All rights reserved
Acesso inclui 2 Tokens
● access_token

● refresh_token

● Para fazer requisições

● Atualiza o access_token

● Tempo de vida 60 minutos

● Tempo de vida indefinido
● Armazene!

AdWords API Workshops – All rights reserved
Preparação

AdWords API Workshops – All rights reserved
Registre sua aplicação
http://code.google.com/apis/console
● Obtenha uma identificação da aplicação
● client_id
● client_secret

AdWords API Workshops – All rights reserved
Crie um novo projeto na Google API
Console

AdWords API Workshops – All rights reserved
Crie um client ID OAuth 2.0

AdWords API Workshops – All rights reserved
Servidor web ou aplicação instalada?
Escolha Aplicação Instalada a menos que você tenha
várias contas de clientes que precisam de autorização.

Escolha Aplicação em Servidor Web quando usar várias
contas autorizadas separadamente.

AdWords API Workshops – All rights reserved
Escolha seu tipo de aplicação

Aplicação Instalada
AdWords API Workshops – All rights reserved
Agora, você tem um client_id e client_secret

AdWords API Workshops – All rights reserved
Obtendo Acesso
access_token & refresh_token

AdWords API Workshops – All rights reserved
Para que serve o Token de Acesso?

Obter Acesso & Renovar Tokens
Obter aprovação

AdWords API Workshops – All rights reserved
Com ou sem Client Libraries
● Com Client Libraries
● Sem Client Libraries

AdWords API Workshops – All rights reserved
Client Libraries podem ajudar
● Verifique os detalhes da sua library!
● Exemplo:
● Executar script
● Autorizar aplicação
● Adicionar refresh_token à configuração

AdWords API Workshops – All rights reserved
Como obter um Token de Acesso
1. Construir URL
2. Obter Consentimento
3. Receber Código de Autorização
4. Trocar Código por Token
5. Armazenar Credenciais
AdWords API Workshops – All rights reserved
1. Construir uma URL
https://accounts.google.com/o/oauth2/auth?
access_type=offline&
scope=https://adwords.google.com/api/adwords&
redirect_uri=urn:ietf:wg:oauth:2.0:oob&
response_type=code&
client_id=xxxxxxx.apps.googleusercontent.com

AdWords API Workshops – All rights reserved
2. Obter Consentimento
● Enviar Usuário
● Aceitar permissões

AdWords API Workshops – All rights reserved
3. Receber Código de Autorização

> Enter authorization code here:
4/v6xr77ewYqhvHSyW6UJ1w7jKwAzu

AdWords API Workshops – All rights reserved
4. Trocar Código por Token
HTML

POST /o/oauth2/token HTTP/1.1
Host: accounts.google.com
Content-Type: application/x-www-form-urlencoded

code=4/v6xr77ewYqhvHSyW6UJ1w7jKwAzu&
client_id=xxxxxxx.apps.googleusercontent.com&
client_secret={client_secret}&
redirect_uri=&
grant_type=authorization_code

AdWords API Workshops – All rights reserved
5. Armazenar Credenciais
{
"access_token" : "yaxx.xxxxxxxxxxxx",
"token_type" : "Bearer",
"expires_in" : 3600,
"refresh_token" : "1/xxxxxxxxxxxxxxxxxxxg"
}

AdWords API Workshops – All rights reserved
Tipos de Fluxos OAuth 2.0

AdWords API Workshops – All rights reserved
Fluxos OAuth 2.0 Suportados pelo Google
O Google suporta cenários OAuth 2.0 comuns
● Aplicações Instaladas
● Aplicações em Web Server
● Aplicações em devices com input limitado

AdWords API Workshops – All rights reserved
Diferenças entre fluxos
Registro no
Usar código de Client
Console de API Autenticação
Secret

Renovação Redirecionamento
de Token

Aplicações
Instaladas

Requerido

Sim

Requerido

Disponível

URL, Texto

Aplicações em
Web Server

Requerido

Sim

Requerido

Disponível

URL

Aplicações em
devices com
input limitado

Requerido

-

Requerido

Disponível

-

AdWords API Workshops – All rights reserved
Melhores Práticas

AdWords API Workshops – All rights reserved
Melhores Práticas
● Use tipo de acesso offline para obter um
refresh_token

● Armazene o refresh_token para obter um novo
access_token

● Use a estrutura da MCC
● Autorize a MCC de nível mais alto

AdWords API Workshops – All rights reserved
Armazenamento & Compartilhamento
● Armazene os Tokens de Acesso
● Armazene o timestamp e o tempo de validade do token de
acesso

● Compartilhe Tokens de Acesso entre Threads

AdWords API Workshops – All rights reserved
Informações Úteis sobre Erros
● AuthenticationError.OAUTH_TOKEN_INVALID
○ Quando: Token de Accesso expirado
○ Solução: obtenha um novo Token de Acesso com um Refresh
token

● AuthenticationError.INVALID_GRANT_ERROR
○ Quando: Refresh Token revogado
○ Solução: re-autentique a aplicação com consentimento do
usuário
AdWords API Workshops – All rights reserved
Apêndice

AdWords API Workshops – All rights reserved
Recursos

AdWords API Workshops – All rights reserved
Resources

Links:
https://developers.google.com/accounts/docs/OAuth2
https://developers.google.com/accounts/docs/OAuth2WebServer
https://developers.google.com/accounts/docs/OAuth2InstalledApp
https://developers.google.com/adwords/api/docs/authentication#oauth
https://code.google.com/apis/console
Perguntas?

AdWords API Workshops – All rights reserved
AdWords API Workshops – All rights reserved
Offline ou Online?
Escolha acesso offline quando suas aplicações
funcionam sem interação com o usuário
Acesso offline é bom para aplicações típicas da API do
AdWords que acessam servidores do Google para obter
dados e atribuir valores em background.

AdWords API Workshops – All rights reserved

Weitere ähnliche Inhalte

Ähnlich wie OAuth 2.0 refresher

TDC 2015 - Segurança em Recursos RESTful com OAuth2
TDC 2015 - Segurança em Recursos RESTful com OAuth2TDC 2015 - Segurança em Recursos RESTful com OAuth2
TDC 2015 - Segurança em Recursos RESTful com OAuth2Rodrigo Cândido da Silva
 
TDC2016SP - Unificando a autenticação e controlando acesso a API com Identity...
TDC2016SP - Unificando a autenticação e controlando acesso a API com Identity...TDC2016SP - Unificando a autenticação e controlando acesso a API com Identity...
TDC2016SP - Unificando a autenticação e controlando acesso a API com Identity...tdc-globalcode
 
Audit¢rio 11 desenvolvimento de um app ao vivo - pablo moretti
Audit¢rio 11   desenvolvimento de um app ao vivo - pablo morettiAudit¢rio 11   desenvolvimento de um app ao vivo - pablo moretti
Audit¢rio 11 desenvolvimento de um app ao vivo - pablo morettifsolari
 
AwReporting Tool
AwReporting ToolAwReporting Tool
AwReporting Toolmarcwan
 
Construindo APIs com Amazon API Gateway e AWS Lambda
Construindo APIs com Amazon API Gateway e AWS LambdaConstruindo APIs com Amazon API Gateway e AWS Lambda
Construindo APIs com Amazon API Gateway e AWS LambdaAmazon Web Services LATAM
 
Construindo APIs com Amazon API Gateway e AWS Lambda
Construindo APIs com Amazon API Gateway e AWS LambdaConstruindo APIs com Amazon API Gateway e AWS Lambda
Construindo APIs com Amazon API Gateway e AWS LambdaAmazon Web Services LATAM
 
Construindo APIs com Amazon API Gateway e AWS Lambda
Construindo APIs com Amazon API Gateway e AWS LambdaConstruindo APIs com Amazon API Gateway e AWS Lambda
Construindo APIs com Amazon API Gateway e AWS LambdaAmazon Web Services LATAM
 
Rate limits and performance
Rate limits and performanceRate limits and performance
Rate limits and performancemarcwan
 
Explorando mecanismos autenticacao na web
Explorando mecanismos autenticacao na webExplorando mecanismos autenticacao na web
Explorando mecanismos autenticacao na webEduardo Cesar
 
AdWords Scripts
AdWords ScriptsAdWords Scripts
AdWords Scriptsmarcwan
 
Palestra Joomla Day Brasil 2014 - Extensão de Webservice para Joomla 3
Palestra Joomla Day Brasil 2014 - Extensão de Webservice para Joomla 3Palestra Joomla Day Brasil 2014 - Extensão de Webservice para Joomla 3
Palestra Joomla Day Brasil 2014 - Extensão de Webservice para Joomla 3Johnny Salazar Reidel
 
Oracle - Identity Manager
Oracle - Identity ManagerOracle - Identity Manager
Oracle - Identity ManagerThiago Gutierri
 
Introdução a plataforma de aplicativos Redu
Introdução a plataforma de aplicativos ReduIntrodução a plataforma de aplicativos Redu
Introdução a plataforma de aplicativos ReduGuilherme
 
Ask the Trainer - Treinamentos e Certificações da AWS
Ask the Trainer - Treinamentos e Certificações da AWSAsk the Trainer - Treinamentos e Certificações da AWS
Ask the Trainer - Treinamentos e Certificações da AWSAmazon Web Services LATAM
 
Spring Security e Spring Boot Aula - 2018
Spring Security e Spring Boot Aula - 2018Spring Security e Spring Boot Aula - 2018
Spring Security e Spring Boot Aula - 2018André Luiz Forchesatto
 
Autenticação e Autorização (in portuguese)
Autenticação e Autorização (in portuguese)Autenticação e Autorização (in portuguese)
Autenticação e Autorização (in portuguese)Bruno Pedro
 
WSO2 - Visão Geral de Negócios
WSO2 - Visão Geral de NegóciosWSO2 - Visão Geral de Negócios
WSO2 - Visão Geral de NegóciosEdgar Silva
 
Restful APIs com Spring 3
Restful APIs com Spring 3Restful APIs com Spring 3
Restful APIs com Spring 3Alex Miranda
 
Construindo APIs com Amazon API Gateway e AWS Lambda
Construindo APIs com Amazon API Gateway e AWS LambdaConstruindo APIs com Amazon API Gateway e AWS Lambda
Construindo APIs com Amazon API Gateway e AWS LambdaAmazon Web Services LATAM
 

Ähnlich wie OAuth 2.0 refresher (20)

TDC 2015 - Segurança em Recursos RESTful com OAuth2
TDC 2015 - Segurança em Recursos RESTful com OAuth2TDC 2015 - Segurança em Recursos RESTful com OAuth2
TDC 2015 - Segurança em Recursos RESTful com OAuth2
 
TDC2016SP - Unificando a autenticação e controlando acesso a API com Identity...
TDC2016SP - Unificando a autenticação e controlando acesso a API com Identity...TDC2016SP - Unificando a autenticação e controlando acesso a API com Identity...
TDC2016SP - Unificando a autenticação e controlando acesso a API com Identity...
 
Audit¢rio 11 desenvolvimento de um app ao vivo - pablo moretti
Audit¢rio 11   desenvolvimento de um app ao vivo - pablo morettiAudit¢rio 11   desenvolvimento de um app ao vivo - pablo moretti
Audit¢rio 11 desenvolvimento de um app ao vivo - pablo moretti
 
AwReporting Tool
AwReporting ToolAwReporting Tool
AwReporting Tool
 
Design de APIs REST
Design de APIs RESTDesign de APIs REST
Design de APIs REST
 
Construindo APIs com Amazon API Gateway e AWS Lambda
Construindo APIs com Amazon API Gateway e AWS LambdaConstruindo APIs com Amazon API Gateway e AWS Lambda
Construindo APIs com Amazon API Gateway e AWS Lambda
 
Construindo APIs com Amazon API Gateway e AWS Lambda
Construindo APIs com Amazon API Gateway e AWS LambdaConstruindo APIs com Amazon API Gateway e AWS Lambda
Construindo APIs com Amazon API Gateway e AWS Lambda
 
Construindo APIs com Amazon API Gateway e AWS Lambda
Construindo APIs com Amazon API Gateway e AWS LambdaConstruindo APIs com Amazon API Gateway e AWS Lambda
Construindo APIs com Amazon API Gateway e AWS Lambda
 
Rate limits and performance
Rate limits and performanceRate limits and performance
Rate limits and performance
 
Explorando mecanismos autenticacao na web
Explorando mecanismos autenticacao na webExplorando mecanismos autenticacao na web
Explorando mecanismos autenticacao na web
 
AdWords Scripts
AdWords ScriptsAdWords Scripts
AdWords Scripts
 
Palestra Joomla Day Brasil 2014 - Extensão de Webservice para Joomla 3
Palestra Joomla Day Brasil 2014 - Extensão de Webservice para Joomla 3Palestra Joomla Day Brasil 2014 - Extensão de Webservice para Joomla 3
Palestra Joomla Day Brasil 2014 - Extensão de Webservice para Joomla 3
 
Oracle - Identity Manager
Oracle - Identity ManagerOracle - Identity Manager
Oracle - Identity Manager
 
Introdução a plataforma de aplicativos Redu
Introdução a plataforma de aplicativos ReduIntrodução a plataforma de aplicativos Redu
Introdução a plataforma de aplicativos Redu
 
Ask the Trainer - Treinamentos e Certificações da AWS
Ask the Trainer - Treinamentos e Certificações da AWSAsk the Trainer - Treinamentos e Certificações da AWS
Ask the Trainer - Treinamentos e Certificações da AWS
 
Spring Security e Spring Boot Aula - 2018
Spring Security e Spring Boot Aula - 2018Spring Security e Spring Boot Aula - 2018
Spring Security e Spring Boot Aula - 2018
 
Autenticação e Autorização (in portuguese)
Autenticação e Autorização (in portuguese)Autenticação e Autorização (in portuguese)
Autenticação e Autorização (in portuguese)
 
WSO2 - Visão Geral de Negócios
WSO2 - Visão Geral de NegóciosWSO2 - Visão Geral de Negócios
WSO2 - Visão Geral de Negócios
 
Restful APIs com Spring 3
Restful APIs com Spring 3Restful APIs com Spring 3
Restful APIs com Spring 3
 
Construindo APIs com Amazon API Gateway e AWS Lambda
Construindo APIs com Amazon API Gateway e AWS LambdaConstruindo APIs com Amazon API Gateway e AWS Lambda
Construindo APIs com Amazon API Gateway e AWS Lambda
 

Mehr von marcwan

Mcc scripts deck (日本語)
Mcc scripts deck (日本語)Mcc scripts deck (日本語)
Mcc scripts deck (日本語)marcwan
 
Getting started with Google Analytics and the AdWords API
Getting started with Google Analytics and the AdWords APIGetting started with Google Analytics and the AdWords API
Getting started with Google Analytics and the AdWords APImarcwan
 
Bid Estimation with the AdWords API (v2)
Bid Estimation with the AdWords API (v2)Bid Estimation with the AdWords API (v2)
Bid Estimation with the AdWords API (v2)marcwan
 
Opportunity Analysis with Kratu (v2)
Opportunity Analysis with Kratu (v2)Opportunity Analysis with Kratu (v2)
Opportunity Analysis with Kratu (v2)marcwan
 
Opportunity Analysis with Kratu
Opportunity Analysis with KratuOpportunity Analysis with Kratu
Opportunity Analysis with Kratumarcwan
 
07. feeds update
07. feeds update07. feeds update
07. feeds updatemarcwan
 
AdWords API & OAuth 2.0, Advanced
AdWords API & OAuth 2.0, Advanced AdWords API & OAuth 2.0, Advanced
AdWords API & OAuth 2.0, Advanced marcwan
 
AdWords Scripts and MCC Scripting
AdWords Scripts and MCC ScriptingAdWords Scripts and MCC Scripting
AdWords Scripts and MCC Scriptingmarcwan
 
AwReporting Update
AwReporting UpdateAwReporting Update
AwReporting Updatemarcwan
 
Getting Started with AdWords API and Google Analytics
Getting Started with AdWords API and Google AnalyticsGetting Started with AdWords API and Google Analytics
Getting Started with AdWords API and Google Analyticsmarcwan
 
Shopping Campaigns and AdWords API
Shopping Campaigns and AdWords APIShopping Campaigns and AdWords API
Shopping Campaigns and AdWords APImarcwan
 
API Updates for v201402
API Updates for v201402API Updates for v201402
API Updates for v201402marcwan
 
AdWords API Targeting Options
AdWords API Targeting OptionsAdWords API Targeting Options
AdWords API Targeting Optionsmarcwan
 
Reporting Tips and Tricks (Spanish)
Reporting Tips and Tricks (Spanish)Reporting Tips and Tricks (Spanish)
Reporting Tips and Tricks (Spanish)marcwan
 
Rate limits and performance (Spanish)
Rate limits and performance (Spanish)Rate limits and performance (Spanish)
Rate limits and performance (Spanish)marcwan
 
OAuth 2.0 (Spanish)
OAuth 2.0 (Spanish)OAuth 2.0 (Spanish)
OAuth 2.0 (Spanish)marcwan
 
End to-end how to build a platform (Spanish)
End to-end how to build a platform (Spanish)End to-end how to build a platform (Spanish)
End to-end how to build a platform (Spanish)marcwan
 
AwReporting tool introduction (Spanish)
AwReporting tool introduction (Spanish)AwReporting tool introduction (Spanish)
AwReporting tool introduction (Spanish)marcwan
 
Api update rundown (Spanish)
Api update rundown (Spanish)Api update rundown (Spanish)
Api update rundown (Spanish)marcwan
 
AdWords Scripts (Spanish)
AdWords Scripts (Spanish)AdWords Scripts (Spanish)
AdWords Scripts (Spanish)marcwan
 

Mehr von marcwan (20)

Mcc scripts deck (日本語)
Mcc scripts deck (日本語)Mcc scripts deck (日本語)
Mcc scripts deck (日本語)
 
Getting started with Google Analytics and the AdWords API
Getting started with Google Analytics and the AdWords APIGetting started with Google Analytics and the AdWords API
Getting started with Google Analytics and the AdWords API
 
Bid Estimation with the AdWords API (v2)
Bid Estimation with the AdWords API (v2)Bid Estimation with the AdWords API (v2)
Bid Estimation with the AdWords API (v2)
 
Opportunity Analysis with Kratu (v2)
Opportunity Analysis with Kratu (v2)Opportunity Analysis with Kratu (v2)
Opportunity Analysis with Kratu (v2)
 
Opportunity Analysis with Kratu
Opportunity Analysis with KratuOpportunity Analysis with Kratu
Opportunity Analysis with Kratu
 
07. feeds update
07. feeds update07. feeds update
07. feeds update
 
AdWords API & OAuth 2.0, Advanced
AdWords API & OAuth 2.0, Advanced AdWords API & OAuth 2.0, Advanced
AdWords API & OAuth 2.0, Advanced
 
AdWords Scripts and MCC Scripting
AdWords Scripts and MCC ScriptingAdWords Scripts and MCC Scripting
AdWords Scripts and MCC Scripting
 
AwReporting Update
AwReporting UpdateAwReporting Update
AwReporting Update
 
Getting Started with AdWords API and Google Analytics
Getting Started with AdWords API and Google AnalyticsGetting Started with AdWords API and Google Analytics
Getting Started with AdWords API and Google Analytics
 
Shopping Campaigns and AdWords API
Shopping Campaigns and AdWords APIShopping Campaigns and AdWords API
Shopping Campaigns and AdWords API
 
API Updates for v201402
API Updates for v201402API Updates for v201402
API Updates for v201402
 
AdWords API Targeting Options
AdWords API Targeting OptionsAdWords API Targeting Options
AdWords API Targeting Options
 
Reporting Tips and Tricks (Spanish)
Reporting Tips and Tricks (Spanish)Reporting Tips and Tricks (Spanish)
Reporting Tips and Tricks (Spanish)
 
Rate limits and performance (Spanish)
Rate limits and performance (Spanish)Rate limits and performance (Spanish)
Rate limits and performance (Spanish)
 
OAuth 2.0 (Spanish)
OAuth 2.0 (Spanish)OAuth 2.0 (Spanish)
OAuth 2.0 (Spanish)
 
End to-end how to build a platform (Spanish)
End to-end how to build a platform (Spanish)End to-end how to build a platform (Spanish)
End to-end how to build a platform (Spanish)
 
AwReporting tool introduction (Spanish)
AwReporting tool introduction (Spanish)AwReporting tool introduction (Spanish)
AwReporting tool introduction (Spanish)
 
Api update rundown (Spanish)
Api update rundown (Spanish)Api update rundown (Spanish)
Api update rundown (Spanish)
 
AdWords Scripts (Spanish)
AdWords Scripts (Spanish)AdWords Scripts (Spanish)
AdWords Scripts (Spanish)
 

OAuth 2.0 refresher

  • 1. AdWords API Workshops – All rights reserved
  • 2. OAuth 2.0 Cristiano Breuel, Google, Inc. AdWords API Workshops – All rights reserved
  • 3. Agenda 1. O que é OAuth 2.0? 1 2 2. Preparação 3. Obtendo um Access Token 3 4. Detalhes do fluxo OAuth 2.0 5. Melhores Práticas AdWords API Workshops – All rights reserved 4 5
  • 4. O que é OAuth 2.0? AdWords API Workshops – All rights reserved
  • 5. O que é OAuth 2.0? ● Autorização para a API do AdWords ● Seguro ● Simples ● Padronizado AdWords API Workshops – All rights reserved
  • 6. A segurança do OAuth2 ● Sem Nomes de usuário ou Senhas ● Só Tokens ● Controle de acesso Específico ● Escopo restrito ● Fácil de revogar AdWords API Workshops – All rights reserved
  • 7. A simplicidade do OAuth2 Obter Acesso Pedir aprovação Interagir com a API do AdWords AdWords API Workshops – All rights reserved
  • 8. O padrão do OAuth2 ● Você já viu essa janela? ● Consentimento do Usuário ● Aceitar ● Cancelar AdWords API Workshops – All rights reserved
  • 9. O Fluxo OAuth2 Conceder Accesso 1) Construir URL 3) Troca de Código Sua Aplicação 2) Aceitar Consentimento Usuário da MCC Servidores OAuth2 A API do AdWords Servidores do Google AdWords API Workshops – All rights reserved Interagir com a API do AdWords 4) Fazer Requisição 5) Renovar Accesso
  • 10. Acesso inclui 2 Tokens ● access_token ● refresh_token ● Para fazer requisições ● Atualiza o access_token ● Tempo de vida 60 minutos ● Tempo de vida indefinido ● Armazene! AdWords API Workshops – All rights reserved
  • 11. Acesso inclui 2 Tokens ● access_token ● refresh_token ● Para fazer requisições ● Atualiza o access_token ● Tempo de vida 60 minutos ● Tempo de vida indefinido ● Armazene! AdWords API Workshops – All rights reserved
  • 12. Acesso inclui 2 Tokens ● access_token ● refresh_token ● Para fazer requisições ● Atualiza o access_token ● Tempo de vida 60 minutos ● Tempo de vida indefinido ● Armazene! AdWords API Workshops – All rights reserved
  • 13. Preparação AdWords API Workshops – All rights reserved
  • 14. Registre sua aplicação http://code.google.com/apis/console ● Obtenha uma identificação da aplicação ● client_id ● client_secret AdWords API Workshops – All rights reserved
  • 15. Crie um novo projeto na Google API Console AdWords API Workshops – All rights reserved
  • 16. Crie um client ID OAuth 2.0 AdWords API Workshops – All rights reserved
  • 17. Servidor web ou aplicação instalada? Escolha Aplicação Instalada a menos que você tenha várias contas de clientes que precisam de autorização. Escolha Aplicação em Servidor Web quando usar várias contas autorizadas separadamente. AdWords API Workshops – All rights reserved
  • 18. Escolha seu tipo de aplicação Aplicação Instalada AdWords API Workshops – All rights reserved
  • 19. Agora, você tem um client_id e client_secret AdWords API Workshops – All rights reserved
  • 20. Obtendo Acesso access_token & refresh_token AdWords API Workshops – All rights reserved
  • 21. Para que serve o Token de Acesso? Obter Acesso & Renovar Tokens Obter aprovação AdWords API Workshops – All rights reserved
  • 22. Com ou sem Client Libraries ● Com Client Libraries ● Sem Client Libraries AdWords API Workshops – All rights reserved
  • 23. Client Libraries podem ajudar ● Verifique os detalhes da sua library! ● Exemplo: ● Executar script ● Autorizar aplicação ● Adicionar refresh_token à configuração AdWords API Workshops – All rights reserved
  • 24. Como obter um Token de Acesso 1. Construir URL 2. Obter Consentimento 3. Receber Código de Autorização 4. Trocar Código por Token 5. Armazenar Credenciais AdWords API Workshops – All rights reserved
  • 25. 1. Construir uma URL https://accounts.google.com/o/oauth2/auth? access_type=offline& scope=https://adwords.google.com/api/adwords& redirect_uri=urn:ietf:wg:oauth:2.0:oob& response_type=code& client_id=xxxxxxx.apps.googleusercontent.com AdWords API Workshops – All rights reserved
  • 26. 2. Obter Consentimento ● Enviar Usuário ● Aceitar permissões AdWords API Workshops – All rights reserved
  • 27. 3. Receber Código de Autorização > Enter authorization code here: 4/v6xr77ewYqhvHSyW6UJ1w7jKwAzu AdWords API Workshops – All rights reserved
  • 28. 4. Trocar Código por Token HTML POST /o/oauth2/token HTTP/1.1 Host: accounts.google.com Content-Type: application/x-www-form-urlencoded code=4/v6xr77ewYqhvHSyW6UJ1w7jKwAzu& client_id=xxxxxxx.apps.googleusercontent.com& client_secret={client_secret}& redirect_uri=& grant_type=authorization_code AdWords API Workshops – All rights reserved
  • 29. 5. Armazenar Credenciais { "access_token" : "yaxx.xxxxxxxxxxxx", "token_type" : "Bearer", "expires_in" : 3600, "refresh_token" : "1/xxxxxxxxxxxxxxxxxxxg" } AdWords API Workshops – All rights reserved
  • 30. Tipos de Fluxos OAuth 2.0 AdWords API Workshops – All rights reserved
  • 31. Fluxos OAuth 2.0 Suportados pelo Google O Google suporta cenários OAuth 2.0 comuns ● Aplicações Instaladas ● Aplicações em Web Server ● Aplicações em devices com input limitado AdWords API Workshops – All rights reserved
  • 32. Diferenças entre fluxos Registro no Usar código de Client Console de API Autenticação Secret Renovação Redirecionamento de Token Aplicações Instaladas Requerido Sim Requerido Disponível URL, Texto Aplicações em Web Server Requerido Sim Requerido Disponível URL Aplicações em devices com input limitado Requerido - Requerido Disponível - AdWords API Workshops – All rights reserved
  • 33. Melhores Práticas AdWords API Workshops – All rights reserved
  • 34. Melhores Práticas ● Use tipo de acesso offline para obter um refresh_token ● Armazene o refresh_token para obter um novo access_token ● Use a estrutura da MCC ● Autorize a MCC de nível mais alto AdWords API Workshops – All rights reserved
  • 35. Armazenamento & Compartilhamento ● Armazene os Tokens de Acesso ● Armazene o timestamp e o tempo de validade do token de acesso ● Compartilhe Tokens de Acesso entre Threads AdWords API Workshops – All rights reserved
  • 36. Informações Úteis sobre Erros ● AuthenticationError.OAUTH_TOKEN_INVALID ○ Quando: Token de Accesso expirado ○ Solução: obtenha um novo Token de Acesso com um Refresh token ● AuthenticationError.INVALID_GRANT_ERROR ○ Quando: Refresh Token revogado ○ Solução: re-autentique a aplicação com consentimento do usuário AdWords API Workshops – All rights reserved
  • 37. Apêndice AdWords API Workshops – All rights reserved
  • 38. Recursos AdWords API Workshops – All rights reserved
  • 40. Perguntas? AdWords API Workshops – All rights reserved
  • 41. AdWords API Workshops – All rights reserved
  • 42. Offline ou Online? Escolha acesso offline quando suas aplicações funcionam sem interação com o usuário Acesso offline é bom para aplicações típicas da API do AdWords que acessam servidores do Google para obter dados e atribuir valores em background. AdWords API Workshops – All rights reserved