Skip to content

Instantly share code, notes, and snippets.

@sandromello
Created July 4, 2016 12:20
Show Gist options
  • Save sandromello/12d847284f444729ab4a999928f4d649 to your computer and use it in GitHub Desktop.
Save sandromello/12d847284f444729ab4a999928f4d649 to your computer and use it in GitHub Desktop.
Autenticação Loja
import urlparse
import requests
AUTH_URL = 'https://{}/public/login?integrandose=true'.format('app.lojaintegrada-staging.com.br')
form_data = {
'email': STORE_USER,
'senha': STORE_USER_PASSWD
}
headers = {'Content-Type': 'application/x-www-form-urlencoded'}
r = requests.post(AUTH_URL, data=form_data, headers=headers, allow_redirects=False, verify=False)
# Pegar o token da query string
query_string = urlparse.urlparse(r.headers['location']).query
auth_token = urlparse.parse_qs(query_string)['auth_token'][0]
REQUEST_HEADERS = {
'Content-Type': 'application/json',
'Authorization': ''
}
REQUEST_HEADERS['Authorization'] = 'Bearer {}'.format(auth_token)
API_V2_URL = 'https://{}/v2/themes'.format('api-staging.awsli.com.br')
r = requests.get(API_V2_URL, headers=REQUEST_HEADERS)
print r.json()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment