|
| 1 | +from ..rest import RestClient |
| 2 | + |
| 3 | + |
| 4 | +class ClientCredentials(object): |
| 5 | + """Auth0 client credentials endpoints. |
| 6 | +
|
| 7 | + Args: |
| 8 | + domain (str): Your Auth0 domain, for example: 'my-domain.us.auth0.com' |
| 9 | +
|
| 10 | + token (str): Management API v2 Token |
| 11 | +
|
| 12 | + telemetry (bool, optional): Enable or disable telemetry |
| 13 | + (defaults to True) |
| 14 | +
|
| 15 | + timeout (float or tuple, optional): Change the requests |
| 16 | + connect and read timeout. Pass a tuple to specify |
| 17 | + both values separately or a float to set both to it. |
| 18 | + (defaults to 5.0 for both) |
| 19 | +
|
| 20 | + rest_options (RestClientOptions): Pass an instance of |
| 21 | + RestClientOptions to configure additional RestClient |
| 22 | + options, such as rate-limit retries. |
| 23 | + (defaults to None) |
| 24 | + """ |
| 25 | + |
| 26 | + def __init__( |
| 27 | + self, |
| 28 | + domain, |
| 29 | + token, |
| 30 | + telemetry=True, |
| 31 | + timeout=5.0, |
| 32 | + protocol="https", |
| 33 | + rest_options=None, |
| 34 | + ): |
| 35 | + self.domain = domain |
| 36 | + self.protocol = protocol |
| 37 | + self.client = RestClient( |
| 38 | + jwt=token, telemetry=telemetry, timeout=timeout, options=rest_options |
| 39 | + ) |
| 40 | + |
| 41 | + def _url(self, client_id, id=None): |
| 42 | + url = "{}://{}/api/v2/clients/{}/credentials".format( |
| 43 | + self.protocol, self.domain, client_id |
| 44 | + ) |
| 45 | + if id is not None: |
| 46 | + return "{}/{}".format(url, id) |
| 47 | + return url |
| 48 | + |
| 49 | + def all(self, client_id): |
| 50 | + """Get a list of credentials associated with a client. |
| 51 | +
|
| 52 | + Args: |
| 53 | + client_id (string): The id of a client that owns the credentials. |
| 54 | +
|
| 55 | + See: https://auth0.com/docs/api/management/v2#!/Client_Credentials/get_client_credentials |
| 56 | + """ |
| 57 | + return self.client.get(self._url(client_id)) |
| 58 | + |
| 59 | + def get(self, client_id, id): |
| 60 | + """Retrieve a specified client credential. |
| 61 | +
|
| 62 | + Args: |
| 63 | + client_id (string): The id of a client that owns the credential. |
| 64 | +
|
| 65 | + id (string): The id of the credential. |
| 66 | +
|
| 67 | + See: https://auth0.com/docs/api/management/v2#!/Client_Credentials/get_client_credentials_by_id |
| 68 | + """ |
| 69 | + return self.client.get(self._url(client_id, id)) |
| 70 | + |
| 71 | + def create(self, client_id, body): |
| 72 | + """Create a credential on a client. |
| 73 | +
|
| 74 | + Args: |
| 75 | + client_id (string): The id of a client to create the credential for. |
| 76 | +
|
| 77 | + See: https://auth0.com/docs/api/management/v2#!/Client_Credentials/post_client_credentials |
| 78 | + """ |
| 79 | + return self.client.post(self._url(client_id), data=body) |
| 80 | + |
| 81 | + def delete(self, client_id, id): |
| 82 | + """Delete a client's credential. |
| 83 | +
|
| 84 | + Args: |
| 85 | + id (str): The id of credential to delete. |
| 86 | +
|
| 87 | + See: https://auth0.com/docs/api/management/v2#!/Client_Credentials/delete_client_credentials_by_id |
| 88 | + """ |
| 89 | + |
| 90 | + return self.client.delete(self._url(client_id, id)) |
0 commit comments