Last active
August 29, 2015 14:20
-
-
Save laxathom/56eed584ec87c913eee4 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 python | |
import requests | |
import json | |
from itsdangerous import JSONWebSignatureSerializer | |
from getpass import getpass | |
FAS_URL = str('http://0.0.0.0:6543/api') | |
HEADERS = {'content-type': 'application/json'} | |
get_people = '/people' | |
get_person = '/people/username/laxathom' | |
API_TOKEN = {'apikey': u'e533af492c7dfdf0d74f6eaabc3c6db63f50669f'} | |
SECRET = str('98ec5a06feb7d7333ee90619e59a9ec6e2220cf9') | |
if __name__ == '__main__': | |
secure_data = JSONWebSignatureSerializer(SECRET) | |
username = raw_input('Enter your FAS login: ') | |
password = getpass(prompt='Enter your password: ') | |
# Set up user's credentials to request login | |
credentials = {'login': username, 'password': password} | |
payload = {'credentials': secure_data.dumps(credentials)} | |
rq = requests.post( | |
FAS_URL + '/request-login', | |
data=json.dumps(payload), | |
headers=HEADERS, | |
params=API_TOKEN | |
) | |
# print(rq.text) | |
if rq.status_code == 200: | |
rsl = rq.json() | |
rsl = rsl['RequestResult'] | |
# 0 Stands for LOGIN_SUCCEED | |
if rsl['LoginStatus'] == 0: | |
# Grab returned auth token | |
auth = secure_data.loads(rsl['Data']) | |
HEADERS['Cookie'] = auth['auth_token'] | |
# Set up client's ID to regsiter it to FAS server. | |
# token will be generated from Ipsilon (OAuth way) | |
app = { | |
'name': 'GNOME Online Account Client 2.1', | |
'token': '23092iu3329120di30932id0932i2109id3d' | |
} | |
# Serialize and sign above ID before sending it to server | |
payload = {'credentials': secure_data.dumps(app)} | |
nrq = requests.post( | |
FAS_URL + '/request-perm/org.fedoraproject.fas.user.info', | |
data=json.dumps(payload), | |
headers=HEADERS, | |
params=API_TOKEN | |
) | |
print(nrq.text) | |
# Now it's up to the auth provider to pass to the client valid token. | |
else: | |
print('Oh, snap! Something bad happened:\n%s' % rq.text) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment