Created
September 18, 2018 20:05
-
-
Save lvm/9e32f8d3c4a44334706882edc7fca3d5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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("[email protected]", "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