-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest.py
49 lines (35 loc) · 1.32 KB
/
test.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
#! /usr/bin/env python
# -*- coding: utf-8 -*-
"""test.py - test connection to Auth0 using credentials in .env"""
import json
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 credentials 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 test_auth0_connection(auth0):
"""Tests connection to Auth0."""
return json.dumps(auth0.connections.all(),
sort_keys=True,
indent=2,
separators=(',', ':'))
def main():
"""main"""
print(test_auth0_connection(connect_to_auth0()))
if __name__ == '__main__':
main()