Skip to content

Instantly share code, notes, and snippets.

@lvm
Created September 18, 2018 20:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lvm/9e32f8d3c4a44334706882edc7fca3d5 to your computer and use it in GitHub Desktop.
Save lvm/9e32f8d3c4a44334706882edc7fca3d5 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import requests
import threading
url = "http://127.0.0.1:8001/o/token/"
client = {
'id': "abc",
'secret': "def"
}
payload_token = "grant_type=password&username={}&password={}".format("user@example.com", "password")
payload_refresh = "grant_type=refresh_token&refresh_token={}"
headers = {
'Content-Type': "application/x-www-form-urlencoded",
'Cache-Control': "no-cache",
}
def request_token():
response = requests.request("POST", url,
data=payload_token,
headers=headers,
auth=(client.get('id'), client.get('secret'))
)
if int(response.status_code) == 200:
return response.json().get('refresh_token')
return None
def request_refresh():
response = requests.request("POST", url,
data=payload_refresh.format(token),
auth=(client.get('id'), client.get('secret')),
headers=headers)
print("refresh: {}".format(response.status_code))
print("response: {}".format(response.text.encode('utf-8')))
if __name__ == "__main__":
token = request_token()
t1 = threading.Thread(target=request_refresh)
t2 = threading.Thread(target=request_refresh)
t3 = threading.Thread(target=request_refresh)
t1.start()
t2.start()
t3.start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment