Merge branch 'develop' into feature/documentation
This commit is contained in:
commit
aec21260e6
38
main/apiauth.py
Normal file
38
main/apiauth.py
Normal file
@ -0,0 +1,38 @@
|
||||
import os
|
||||
|
||||
from zenpy import Zenpy
|
||||
from zenpy.lib.api_objects import User as ZenpyUser
|
||||
|
||||
|
||||
def api_auth():
|
||||
credentials = {
|
||||
'subdomain': 'ngenix1612197338'
|
||||
}
|
||||
email = os.getenv('ACCESS_CONTROLLER_API_EMAIL')
|
||||
token = os.getenv('ACCESS_CONTROLLER_API_TOKEN')
|
||||
password = os.getenv('ACCESS_CONTROLLER_API_PASSWORD')
|
||||
|
||||
if email is None:
|
||||
raise ValueError('access_controller email not in env')
|
||||
credentials['email'] = os.getenv('ACCESS_CONTROLLER_API_EMAIL')
|
||||
|
||||
# prefer token, use password if token not provided
|
||||
if token:
|
||||
credentials['token'] = token
|
||||
elif password:
|
||||
credentials['password'] = password
|
||||
else:
|
||||
raise ValueError('access_controller token or password not in env')
|
||||
|
||||
zenpy_client = Zenpy(**credentials)
|
||||
zenpy_user: ZenpyUser = zenpy_client.users.search(email).values[0]
|
||||
|
||||
user = {
|
||||
'id': zenpy_user.id,
|
||||
'name': zenpy_user.name, # Zendesk doesn't have separate first and last name fields
|
||||
'email': zenpy_user.email,
|
||||
'role': zenpy_user.role, # str like 'admin' or 'agent', not id
|
||||
'photo': zenpy_user.photo['content_url'] if zenpy_user.photo is not None else None,
|
||||
}
|
||||
|
||||
return user
|
Loading…
x
Reference in New Issue
Block a user