-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgetuser.py
73 lines (54 loc) · 1.98 KB
/
getuser.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
"""getuser.py"""
import json
import argparse
from pathlib import Path
from os import environ as env
from dotenv import load_dotenv
from auth0.v3.authentication import GetToken
from auth0.v3.management import Auth0
import constants
def connect_to_auth0():
"""Connect to Auth0 using Client Credentials flow. Credentials are stored
in .env"""
env_path = Path('.') / '.env'
load_dotenv(dotenv_path=env_path)
auth0_client_id = env[constants.AUTH0_CLIENT_ID]
auth0_client_secret = env[constants.AUTH0_CLIENT_SECRET]
auth0_domain = env[constants.AUTH0_DOMAIN]
mgmt_api_url = 'https://'+auth0_domain+'/api/v2/'
get_token = GetToken(auth0_domain)
token = get_token.client_credentials(auth0_client_id,
auth0_client_secret,
mgmt_api_url)
mgmt_api_token = token['access_token']
return Auth0(auth0_domain, mgmt_api_token)
def get_args():
"""Processes command line arguments"""
parser = argparse.ArgumentParser(description='Dumps one specifed user ' +
'or all users as JSON.')
parser.add_argument('-c', '--connection')
group = parser.add_mutually_exclusive_group(required=True)
group.add_argument('-i', '--user_id',
help='Search by Auth0 user_id attribute.')
group.add_argument('-e', '--email',
help='Search by email address.')
group.add_argument('-u', '--username',
help='Search by username.')
return parser.parse_args()
def main():
"""main"""
args = get_args()
auth0 = connect_to_auth0()
if args.user_id:
print(json.dumps(auth0.users.get(args.user_id),
sort_keys=True, indent=4, separators=(',', ':')))
elif args.email:
pass
elif args.username:
pass
else:
print(args.print_help())
if __name__ == '__main__':
main()