-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrocketauth.py
44 lines (38 loc) · 1.15 KB
/
rocketauth.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from requests import get, post
import json
import getpass
#set tokens from file
def get_tokens():
tokenf = input('token file: ')
f = open(tokenf)
lines = f.read().split('\n')
f.close()
auth = lines[0].split(',')[1]
uid = lines[1].split(',')[1]
return { 'X-User-Id' : uid, 'X-Auth-Token' : auth, 'type': 'file'}
def auth_login():
name = input("Enter username: ")
passw = getpass.getpass()
data = { 'user' : name, 'password': passw }
r = post('http://localhost:3000/api/v1/login', data = json.dumps(data))
data = r.json()['data']
return { 'X-User-Id' : data['userId'], 'X-Auth-Token' : data['authToken'], 'type': 'login'}
def auth_logout( token ):
r = post('http://localhost:3000/api/v1/logout', headers = token)
print(r.text)
def auth_choice():
menu = """
0: Authenticate with name/password
1: Autheticate with token file
(default 0): """
choice = input(menu)
if choice == '1':
token = get_tokens()
else:
token = auth_login()
return token
if __name__ == '__main__':
token = auth_choice()
print(token)
if token['type'] == 'login':
auth_logout(token)