Problème avec certificat SSL pour s'authentifier auprès du tenant

Bonjour Sylvain, merci pour ton aide !
Je débute dans l’exploitation de l’API… C’est vrai qu’après avoir lu ton commentaire, ça paraît bien plus logique… et minimaliste :wink:

Pour le module wazo-auth-client, je me suis basé sur le repo associé sur github

Le script que j’ai fait hier :

from wazo_auth_client import Client
from dotenv import load_dotenv
import os
import paramiko
import ssl

# Load env
load_dotenv()

# Path creation for getting .pem certificates
cert_name   = 'server.crt'
remote_path = '/usr/share/xivo-certs/'
local_path  = './keys/'
os.makedirs(local_path, exist_ok=True)
os.chmod(local_path, 755)

# Getting .pem keys
ssh = paramiko.SSHClient()
ssh.load_host_keys(os.path.expanduser(os.path.join("~", ".ssh", "known_hosts")))
ssh.connect(os.getenv('STK'), username=os.getenv('STK_USERNAME'), password=os.getenv('STK_PASSWORD'))
sftp = ssh.open_sftp()
sftp.get(os.path.join(remote_path, cert_name), os.path.join(local_path, cert_name))
sftp.close()
ssh.close()

# Download certificates 'letsencrypt'
# files = sftp.listdir(remote_path)
# certs = []
# for file in files:
#     certs.append(file)
#     sftp.get(os.path.join(remote_path, file), os.path.join(local_path, file))
#     pass

# Getting Wazo token data while checking if cert is valid
ssl.match_hostname = lambda cert, hostname: True
c = Client(os.getenv('STK'), username=os.getenv('API_USERNAME'), password=os.getenv('API_PASSWORD'), verify_certificate=os.path.join(local_path, cert_name))
token_data = c.token.new('wazo_user', expiration=3600, session_type='mobile')  # Creates a new token expiring in 3600 seconds
print(c.token.get(token_data['token']))

Et aujourd’hui :

from wazo_auth_client import Client as Auth
from dotenv import load_dotenv
import os

# Load env
load_dotenv()

# Auth
auth = Auth(os.getenv('STK'), username=os.getenv('API_USERNAME'), password=os.getenv('API_PASSWORD'), verify_certificate=False)

# Auth Token
token_data = auth.token.new('wazo_user', expiration=3600, session_type='mobile')  # Creates a new token expiring in 3600 seconds
print(token_data)

Ça retourne bien un json propre ‘{token’: 'xxxxx…
It works ! Merci !

1 Like