Instantly share code, notes, and snippets.

@MolicnikZ /redirect.py Secret
Last active Jul 23, 2018

Embed
What would you like to do?
from chalice import Chalice
import requests
app = Chalice(app_name='redirect_url')
app.debug = True
TOKEN_URL = "https://redirect.com/v0/token"
TARGET_URL = "https://target.com/v0/endpoint"
USERNAME = 'email@email.com'
PASSWORD = 'Password01021'
@app.route('/redirect_url', methods=['POST'])
def get_payload():
update_payload = app.current_request.json_body
print(update_payload)
def fetch_auth_token():
username = USERNAME
password = PASSWORD
data = {
"grant_type": "password",
"username": username,
"password": password
}
response = requests.post(TOKEN_URL, data=data)
token = response.json()
print(token)
def send_request():
token = fetch_auth_token()
data = get_payload()
headers = {
"Authorization": "Bearer {}".format(token)
}
return requests.post(url=TARGET_URL, headers=headers, data=json.dumps(data))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment