#9 | initial api auth implementation
This commit is contained in:
parent
7a5c7faf91
commit
20bac4eedf
37
main/apiauth.py
Normal file
37
main/apiauth.py
Normal file
@ -0,0 +1,37 @@
|
||||
import os
|
||||
|
||||
from zenpy import Zenpy
|
||||
|
||||
|
||||
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 is not None:
|
||||
credentials['token'] = token
|
||||
else:
|
||||
if password is None:
|
||||
raise ValueError('access_controller token or password not in env')
|
||||
credentials['password'] = password
|
||||
|
||||
zenpy_client = Zenpy(**credentials)
|
||||
zenpy_user = 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