Debian Codegraph @

src/auth0/management/clients/credentials/raw_client.py

raw symbols SCIP
1 # This file was auto-generated by Fern from our API Definition.
2
3 import datetime as dt
4 import typing
5 from json.decoder import JSONDecodeError
6
7 from ...core.api_error import ApiError
8 from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
9 from ...core.http_response import AsyncHttpResponse, HttpResponse
10 from ...core.jsonable_encoder import encode_path_param
11 from ...core.parse_error import ParsingError
12 from ...core.pydantic_utilities import parse_obj_as
13 from ...core.request_options import RequestOptions
14 from ...errors.bad_request_error import BadRequestError
15 from ...errors.forbidden_error import ForbiddenError
16 from ...errors.not_found_error import NotFoundError
17 from ...errors.too_many_requests_error import TooManyRequestsError
18 from ...errors.unauthorized_error import UnauthorizedError
19 from ...types.client_credential import ClientCredential
20 from ...types.client_credential_type_enum import ClientCredentialTypeEnum
21 from ...types.get_client_credential_response_content import GetClientCredentialResponseContent
22 from ...types.patch_client_credential_response_content import PatchClientCredentialResponseContent
23 from ...types.post_client_credential_response_content import PostClientCredentialResponseContent
24 from ...types.public_key_credential_algorithm_enum import PublicKeyCredentialAlgorithmEnum
25 from pydantic import ValidationError
26
27 # this is used as the default value for optional parameters
28 OMIT = typing.cast(typing.Any, ...)
29
30
31 class RawCredentialsClient:
32 def __init__(self, *, client_wrapper: SyncClientWrapper):
33 self._client_wrapper = client_wrapper
34
35 def list(
36 self, client_id: str, *, request_options: typing.Optional[RequestOptions] = None
37 ) -> HttpResponse[typing.List[ClientCredential]]:
38 """
39 Get the details of a client credential.
40
41 **Important**: To enable credentials to be used for a client authentication method, set the `client_authentication_methods` property on the client. To enable credentials to be used for JWT-Secured Authorization requests set the `signed_request_object` property on the client.
42
43 Parameters
44 ----------
45 client_id : str
46 ID of the client.
47
48 request_options : typing.Optional[RequestOptions]
49 Request-specific configuration.
50
51 Returns
52 -------
53 HttpResponse[typing.List[ClientCredential]]
54 Credentials successfully retrieved.
55 """
56 _response = self._client_wrapper.httpx_client.request(
57 f"clients/{encode_path_param(client_id)}/credentials",
58 method="GET",
59 request_options=request_options,
60 )
61 try:
62 if 200 <= _response.status_code < 300:
63 _data = typing.cast(
64 typing.List[ClientCredential],
65 parse_obj_as(
66 type_=typing.List[ClientCredential], # type: ignore
67 object_=_response.json(),
68 ),
69 )
70 return HttpResponse(response=_response, data=_data)
71 if _response.status_code == 401:
72 raise UnauthorizedError(
73 headers=dict(_response.headers),
74 body=typing.cast(
75 typing.Any,
76 parse_obj_as(
77 type_=typing.Any, # type: ignore
78 object_=_response.json(),
79 ),
80 ),
81 )
82 if _response.status_code == 403:
83 raise ForbiddenError(
84 headers=dict(_response.headers),
85 body=typing.cast(
86 typing.Any,
87 parse_obj_as(
88 type_=typing.Any, # type: ignore
89 object_=_response.json(),
90 ),
91 ),
92 )
93 if _response.status_code == 404:
94 raise NotFoundError(
95 headers=dict(_response.headers),
96 body=typing.cast(
97 typing.Any,
98 parse_obj_as(
99 type_=typing.Any, # type: ignore
100 object_=_response.json(),
101 ),
102 ),
103 )
104 if _response.status_code == 429:
105 raise TooManyRequestsError(
106 headers=dict(_response.headers),
107 body=typing.cast(
108 typing.Any,
109 parse_obj_as(
110 type_=typing.Any, # type: ignore
111 object_=_response.json(),
112 ),
113 ),
114 )
115 _response_json = _response.json()
116 except JSONDecodeError:
117 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
118 except ValidationError as e:
119 raise ParsingError(
120 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
121 )
122 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
123
124 def create(
125 self,
126 client_id: str,
127 *,
128 credential_type: ClientCredentialTypeEnum,
129 name: typing.Optional[str] = OMIT,
130 subject_dn: typing.Optional[str] = OMIT,
131 pem: typing.Optional[str] = OMIT,
132 alg: typing.Optional[PublicKeyCredentialAlgorithmEnum] = OMIT,
133 parse_expiry_from_cert: typing.Optional[bool] = OMIT,
134 expires_at: typing.Optional[dt.datetime] = OMIT,
135 kid: typing.Optional[str] = OMIT,
136 request_options: typing.Optional[RequestOptions] = None,
137 ) -> HttpResponse[PostClientCredentialResponseContent]:
138 """
139 Create a client credential associated to your application. Credentials can be used to configure Private Key JWT and mTLS authentication methods, as well as for JWT-secured Authorization requests.
140
141 **Public Key**
142
143 Public Key credentials can be used to set up Private Key JWT client authentication and JWT-secured Authorization requests.
144
145 Sample:
146
147 ```json
148 {
149 "credential_type": "public_key",
150 "name": "string",
151 "pem": "string",
152 "alg": "RS256",
153 "parse_expiry_from_cert": false,
154 "expires_at": "2022-12-31T23:59:59Z"
155 }
156 ```
157
158 **Certificate (CA-signed & self-signed)**
159
160 Certificate credentials can be used to set up mTLS client authentication. CA-signed certificates can be configured either with a signed certificate or with just the certificate Subject DN.
161
162 CA-signed Certificate Sample (pem):
163
164 ```json
165 {
166 "credential_type": "x509_cert",
167 "name": "string",
168 "pem": "string"
169 }
170 ```
171
172 CA-signed Certificate Sample (subject_dn):
173
174 ```json
175 {
176 "credential_type": "cert_subject_dn",
177 "name": "string",
178 "subject_dn": "string"
179 }
180 ```
181
182 Self-signed Certificate Sample:
183
184 ```json
185 {
186 "credential_type": "cert_subject_dn",
187 "name": "string",
188 "pem": "string"
189 }
190 ```
191
192 The credential will be created but not yet enabled for use until you set the corresponding properties in the client:
193
194 - To enable the credential for Private Key JWT or mTLS authentication methods, set the `client_authentication_methods` property on the client. For more information, read [Configure Private Key JWT Authentication](https://auth0.com/docs/get-started/applications/configure-private-key-jwt) and [Configure mTLS Authentication](https://auth0.com/docs/get-started/applications/configure-mtls)
195 - To enable the credential for JWT-secured Authorization requests, set the `signed_request_object`property on the client. For more information, read [Configure JWT-secured Authorization Requests (JAR)](https://auth0.com/docs/get-started/applications/configure-jar)
196
197 Parameters
198 ----------
199 client_id : str
200 ID of the client.
201
202 credential_type : ClientCredentialTypeEnum
203
204 name : typing.Optional[str]
205 Friendly name for a credential.
206
207 subject_dn : typing.Optional[str]
208 Subject Distinguished Name. Mutually exclusive with `pem` property. Applies to `cert_subject_dn` credential type.
209
210 pem : typing.Optional[str]
211 PEM-formatted public key (SPKI and PKCS1) or X509 certificate. Must be JSON escaped.
212
213 alg : typing.Optional[PublicKeyCredentialAlgorithmEnum]
214
215 parse_expiry_from_cert : typing.Optional[bool]
216 Parse expiry from x509 certificate. If true, attempts to parse the expiry date from the provided PEM. Applies to `public_key` credential type.
217
218 expires_at : typing.Optional[dt.datetime]
219 The ISO 8601 formatted date representing the expiration of the credential. If not specified (not recommended), the credential never expires. Applies to `public_key` credential type.
220
221 kid : typing.Optional[str]
222 Optional kid (Key ID), used to uniquely identify the credential. If not specified, a kid value will be auto-generated. The kid header parameter in JWTs sent by your client should match this value. Valid format is [0-9a-zA-Z-_]{10,64}
223
224 request_options : typing.Optional[RequestOptions]
225 Request-specific configuration.
226
227 Returns
228 -------
229 HttpResponse[PostClientCredentialResponseContent]
230 Credential successfully created.
231 """
232 _response = self._client_wrapper.httpx_client.request(
233 f"clients/{encode_path_param(client_id)}/credentials",
234 method="POST",
235 json={
236 "credential_type": credential_type,
237 "name": name,
238 "subject_dn": subject_dn,
239 "pem": pem,
240 "alg": alg,
241 "parse_expiry_from_cert": parse_expiry_from_cert,
242 "expires_at": expires_at,
243 "kid": kid,
244 },
245 headers={
246 "content-type": "application/json",
247 },
248 request_options=request_options,
249 omit=OMIT,
250 )
251 try:
252 if 200 <= _response.status_code < 300:
253 _data = typing.cast(
254 PostClientCredentialResponseContent,
255 parse_obj_as(
256 type_=PostClientCredentialResponseContent, # type: ignore
257 object_=_response.json(),
258 ),
259 )
260 return HttpResponse(response=_response, data=_data)
261 if _response.status_code == 400:
262 raise BadRequestError(
263 headers=dict(_response.headers),
264 body=typing.cast(
265 typing.Any,
266 parse_obj_as(
267 type_=typing.Any, # type: ignore
268 object_=_response.json(),
269 ),
270 ),
271 )
272 if _response.status_code == 401:
273 raise UnauthorizedError(
274 headers=dict(_response.headers),
275 body=typing.cast(
276 typing.Any,
277 parse_obj_as(
278 type_=typing.Any, # type: ignore
279 object_=_response.json(),
280 ),
281 ),
282 )
283 if _response.status_code == 403:
284 raise ForbiddenError(
285 headers=dict(_response.headers),
286 body=typing.cast(
287 typing.Any,
288 parse_obj_as(
289 type_=typing.Any, # type: ignore
290 object_=_response.json(),
291 ),
292 ),
293 )
294 if _response.status_code == 404:
295 raise NotFoundError(
296 headers=dict(_response.headers),
297 body=typing.cast(
298 typing.Any,
299 parse_obj_as(
300 type_=typing.Any, # type: ignore
301 object_=_response.json(),
302 ),
303 ),
304 )
305 if _response.status_code == 429:
306 raise TooManyRequestsError(
307 headers=dict(_response.headers),
308 body=typing.cast(
309 typing.Any,
310 parse_obj_as(
311 type_=typing.Any, # type: ignore
312 object_=_response.json(),
313 ),
314 ),
315 )
316 _response_json = _response.json()
317 except JSONDecodeError:
318 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
319 except ValidationError as e:
320 raise ParsingError(
321 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
322 )
323 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
324
325 def get(
326 self, client_id: str, credential_id: str, *, request_options: typing.Optional[RequestOptions] = None
327 ) -> HttpResponse[GetClientCredentialResponseContent]:
328 """
329 Get the details of a client credential.
330
331 **Important**: To enable credentials to be used for a client authentication method, set the `client_authentication_methods` property on the client. To enable credentials to be used for JWT-Secured Authorization requests set the `signed_request_object` property on the client.
332
333 Parameters
334 ----------
335 client_id : str
336 ID of the client.
337
338 credential_id : str
339 ID of the credential.
340
341 request_options : typing.Optional[RequestOptions]
342 Request-specific configuration.
343
344 Returns
345 -------
346 HttpResponse[GetClientCredentialResponseContent]
347 Credential successfully retrieved.
348 """
349 _response = self._client_wrapper.httpx_client.request(
350 f"clients/{encode_path_param(client_id)}/credentials/{encode_path_param(credential_id)}",
351 method="GET",
352 request_options=request_options,
353 )
354 try:
355 if 200 <= _response.status_code < 300:
356 _data = typing.cast(
357 GetClientCredentialResponseContent,
358 parse_obj_as(
359 type_=GetClientCredentialResponseContent, # type: ignore
360 object_=_response.json(),
361 ),
362 )
363 return HttpResponse(response=_response, data=_data)
364 if _response.status_code == 401:
365 raise UnauthorizedError(
366 headers=dict(_response.headers),
367 body=typing.cast(
368 typing.Any,
369 parse_obj_as(
370 type_=typing.Any, # type: ignore
371 object_=_response.json(),
372 ),
373 ),
374 )
375 if _response.status_code == 403:
376 raise ForbiddenError(
377 headers=dict(_response.headers),
378 body=typing.cast(
379 typing.Any,
380 parse_obj_as(
381 type_=typing.Any, # type: ignore
382 object_=_response.json(),
383 ),
384 ),
385 )
386 if _response.status_code == 404:
387 raise NotFoundError(
388 headers=dict(_response.headers),
389 body=typing.cast(
390 typing.Any,
391 parse_obj_as(
392 type_=typing.Any, # type: ignore
393 object_=_response.json(),
394 ),
395 ),
396 )
397 if _response.status_code == 429:
398 raise TooManyRequestsError(
399 headers=dict(_response.headers),
400 body=typing.cast(
401 typing.Any,
402 parse_obj_as(
403 type_=typing.Any, # type: ignore
404 object_=_response.json(),
405 ),
406 ),
407 )
408 _response_json = _response.json()
409 except JSONDecodeError:
410 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
411 except ValidationError as e:
412 raise ParsingError(
413 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
414 )
415 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
416
417 def delete(
418 self, client_id: str, credential_id: str, *, request_options: typing.Optional[RequestOptions] = None
419 ) -> HttpResponse[None]:
420 """
421 Delete a client credential you previously created. May be enabled or disabled. For more information, read <a href="https://www.auth0.com/docs/get-started/authentication-and-authorization-flow/client-credentials-flow">Client Credential Flow</a>.
422
423 Parameters
424 ----------
425 client_id : str
426 ID of the client.
427
428 credential_id : str
429 ID of the credential to delete.
430
431 request_options : typing.Optional[RequestOptions]
432 Request-specific configuration.
433
434 Returns
435 -------
436 HttpResponse[None]
437 """
438 _response = self._client_wrapper.httpx_client.request(
439 f"clients/{encode_path_param(client_id)}/credentials/{encode_path_param(credential_id)}",
440 method="DELETE",
441 request_options=request_options,
442 )
443 try:
444 if 200 <= _response.status_code < 300:
445 return HttpResponse(response=_response, data=None)
446 if _response.status_code == 400:
447 raise BadRequestError(
448 headers=dict(_response.headers),
449 body=typing.cast(
450 typing.Any,
451 parse_obj_as(
452 type_=typing.Any, # type: ignore
453 object_=_response.json(),
454 ),
455 ),
456 )
457 if _response.status_code == 401:
458 raise UnauthorizedError(
459 headers=dict(_response.headers),
460 body=typing.cast(
461 typing.Any,
462 parse_obj_as(
463 type_=typing.Any, # type: ignore
464 object_=_response.json(),
465 ),
466 ),
467 )
468 if _response.status_code == 403:
469 raise ForbiddenError(
470 headers=dict(_response.headers),
471 body=typing.cast(
472 typing.Any,
473 parse_obj_as(
474 type_=typing.Any, # type: ignore
475 object_=_response.json(),
476 ),
477 ),
478 )
479 if _response.status_code == 429:
480 raise TooManyRequestsError(
481 headers=dict(_response.headers),
482 body=typing.cast(
483 typing.Any,
484 parse_obj_as(
485 type_=typing.Any, # type: ignore
486 object_=_response.json(),
487 ),
488 ),
489 )
490 _response_json = _response.json()
491 except JSONDecodeError:
492 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
493 except ValidationError as e:
494 raise ParsingError(
495 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
496 )
497 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
498
499 def update(
500 self,
501 client_id: str,
502 credential_id: str,
503 *,
504 expires_at: typing.Optional[dt.datetime] = OMIT,
505 request_options: typing.Optional[RequestOptions] = None,
506 ) -> HttpResponse[PatchClientCredentialResponseContent]:
507 """
508 Change a client credential you previously created. May be enabled or disabled. For more information, read <a href="https://www.auth0.com/docs/get-started/authentication-and-authorization-flow/client-credentials-flow">Client Credential Flow</a>.
509
510 Parameters
511 ----------
512 client_id : str
513 ID of the client.
514
515 credential_id : str
516 ID of the credential.
517
518 expires_at : typing.Optional[dt.datetime]
519 The ISO 8601 formatted date representing the expiration of the credential.
520
521 request_options : typing.Optional[RequestOptions]
522 Request-specific configuration.
523
524 Returns
525 -------
526 HttpResponse[PatchClientCredentialResponseContent]
527 Credential successfully updated.
528 """
529 _response = self._client_wrapper.httpx_client.request(
530 f"clients/{encode_path_param(client_id)}/credentials/{encode_path_param(credential_id)}",
531 method="PATCH",
532 json={
533 "expires_at": expires_at,
534 },
535 headers={
536 "content-type": "application/json",
537 },
538 request_options=request_options,
539 omit=OMIT,
540 )
541 try:
542 if 200 <= _response.status_code < 300:
543 _data = typing.cast(
544 PatchClientCredentialResponseContent,
545 parse_obj_as(
546 type_=PatchClientCredentialResponseContent, # type: ignore
547 object_=_response.json(),
548 ),
549 )
550 return HttpResponse(response=_response, data=_data)
551 if _response.status_code == 400:
552 raise BadRequestError(
553 headers=dict(_response.headers),
554 body=typing.cast(
555 typing.Any,
556 parse_obj_as(
557 type_=typing.Any, # type: ignore
558 object_=_response.json(),
559 ),
560 ),
561 )
562 if _response.status_code == 401:
563 raise UnauthorizedError(
564 headers=dict(_response.headers),
565 body=typing.cast(
566 typing.Any,
567 parse_obj_as(
568 type_=typing.Any, # type: ignore
569 object_=_response.json(),
570 ),
571 ),
572 )
573 if _response.status_code == 403:
574 raise ForbiddenError(
575 headers=dict(_response.headers),
576 body=typing.cast(
577 typing.Any,
578 parse_obj_as(
579 type_=typing.Any, # type: ignore
580 object_=_response.json(),
581 ),
582 ),
583 )
584 if _response.status_code == 404:
585 raise NotFoundError(
586 headers=dict(_response.headers),
587 body=typing.cast(
588 typing.Any,
589 parse_obj_as(
590 type_=typing.Any, # type: ignore
591 object_=_response.json(),
592 ),
593 ),
594 )
595 if _response.status_code == 429:
596 raise TooManyRequestsError(
597 headers=dict(_response.headers),
598 body=typing.cast(
599 typing.Any,
600 parse_obj_as(
601 type_=typing.Any, # type: ignore
602 object_=_response.json(),
603 ),
604 ),
605 )
606 _response_json = _response.json()
607 except JSONDecodeError:
608 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
609 except ValidationError as e:
610 raise ParsingError(
611 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
612 )
613 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
614
615
616 class AsyncRawCredentialsClient:
617 def __init__(self, *, client_wrapper: AsyncClientWrapper):
618 self._client_wrapper = client_wrapper
619
620 async def list(
621 self, client_id: str, *, request_options: typing.Optional[RequestOptions] = None
622 ) -> AsyncHttpResponse[typing.List[ClientCredential]]:
623 """
624 Get the details of a client credential.
625
626 **Important**: To enable credentials to be used for a client authentication method, set the `client_authentication_methods` property on the client. To enable credentials to be used for JWT-Secured Authorization requests set the `signed_request_object` property on the client.
627
628 Parameters
629 ----------
630 client_id : str
631 ID of the client.
632
633 request_options : typing.Optional[RequestOptions]
634 Request-specific configuration.
635
636 Returns
637 -------
638 AsyncHttpResponse[typing.List[ClientCredential]]
639 Credentials successfully retrieved.
640 """
641 _response = await self._client_wrapper.httpx_client.request(
642 f"clients/{encode_path_param(client_id)}/credentials",
643 method="GET",
644 request_options=request_options,
645 )
646 try:
647 if 200 <= _response.status_code < 300:
648 _data = typing.cast(
649 typing.List[ClientCredential],
650 parse_obj_as(
651 type_=typing.List[ClientCredential], # type: ignore
652 object_=_response.json(),
653 ),
654 )
655 return AsyncHttpResponse(response=_response, data=_data)
656 if _response.status_code == 401:
657 raise UnauthorizedError(
658 headers=dict(_response.headers),
659 body=typing.cast(
660 typing.Any,
661 parse_obj_as(
662 type_=typing.Any, # type: ignore
663 object_=_response.json(),
664 ),
665 ),
666 )
667 if _response.status_code == 403:
668 raise ForbiddenError(
669 headers=dict(_response.headers),
670 body=typing.cast(
671 typing.Any,
672 parse_obj_as(
673 type_=typing.Any, # type: ignore
674 object_=_response.json(),
675 ),
676 ),
677 )
678 if _response.status_code == 404:
679 raise NotFoundError(
680 headers=dict(_response.headers),
681 body=typing.cast(
682 typing.Any,
683 parse_obj_as(
684 type_=typing.Any, # type: ignore
685 object_=_response.json(),
686 ),
687 ),
688 )
689 if _response.status_code == 429:
690 raise TooManyRequestsError(
691 headers=dict(_response.headers),
692 body=typing.cast(
693 typing.Any,
694 parse_obj_as(
695 type_=typing.Any, # type: ignore
696 object_=_response.json(),
697 ),
698 ),
699 )
700 _response_json = _response.json()
701 except JSONDecodeError:
702 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
703 except ValidationError as e:
704 raise ParsingError(
705 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
706 )
707 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
708
709 async def create(
710 self,
711 client_id: str,
712 *,
713 credential_type: ClientCredentialTypeEnum,
714 name: typing.Optional[str] = OMIT,
715 subject_dn: typing.Optional[str] = OMIT,
716 pem: typing.Optional[str] = OMIT,
717 alg: typing.Optional[PublicKeyCredentialAlgorithmEnum] = OMIT,
718 parse_expiry_from_cert: typing.Optional[bool] = OMIT,
719 expires_at: typing.Optional[dt.datetime] = OMIT,
720 kid: typing.Optional[str] = OMIT,
721 request_options: typing.Optional[RequestOptions] = None,
722 ) -> AsyncHttpResponse[PostClientCredentialResponseContent]:
723 """
724 Create a client credential associated to your application. Credentials can be used to configure Private Key JWT and mTLS authentication methods, as well as for JWT-secured Authorization requests.
725
726 **Public Key**
727
728 Public Key credentials can be used to set up Private Key JWT client authentication and JWT-secured Authorization requests.
729
730 Sample:
731
732 ```json
733 {
734 "credential_type": "public_key",
735 "name": "string",
736 "pem": "string",
737 "alg": "RS256",
738 "parse_expiry_from_cert": false,
739 "expires_at": "2022-12-31T23:59:59Z"
740 }
741 ```
742
743 **Certificate (CA-signed & self-signed)**
744
745 Certificate credentials can be used to set up mTLS client authentication. CA-signed certificates can be configured either with a signed certificate or with just the certificate Subject DN.
746
747 CA-signed Certificate Sample (pem):
748
749 ```json
750 {
751 "credential_type": "x509_cert",
752 "name": "string",
753 "pem": "string"
754 }
755 ```
756
757 CA-signed Certificate Sample (subject_dn):
758
759 ```json
760 {
761 "credential_type": "cert_subject_dn",
762 "name": "string",
763 "subject_dn": "string"
764 }
765 ```
766
767 Self-signed Certificate Sample:
768
769 ```json
770 {
771 "credential_type": "cert_subject_dn",
772 "name": "string",
773 "pem": "string"
774 }
775 ```
776
777 The credential will be created but not yet enabled for use until you set the corresponding properties in the client:
778
779 - To enable the credential for Private Key JWT or mTLS authentication methods, set the `client_authentication_methods` property on the client. For more information, read [Configure Private Key JWT Authentication](https://auth0.com/docs/get-started/applications/configure-private-key-jwt) and [Configure mTLS Authentication](https://auth0.com/docs/get-started/applications/configure-mtls)
780 - To enable the credential for JWT-secured Authorization requests, set the `signed_request_object`property on the client. For more information, read [Configure JWT-secured Authorization Requests (JAR)](https://auth0.com/docs/get-started/applications/configure-jar)
781
782 Parameters
783 ----------
784 client_id : str
785 ID of the client.
786
787 credential_type : ClientCredentialTypeEnum
788
789 name : typing.Optional[str]
790 Friendly name for a credential.
791
792 subject_dn : typing.Optional[str]
793 Subject Distinguished Name. Mutually exclusive with `pem` property. Applies to `cert_subject_dn` credential type.
794
795 pem : typing.Optional[str]
796 PEM-formatted public key (SPKI and PKCS1) or X509 certificate. Must be JSON escaped.
797
798 alg : typing.Optional[PublicKeyCredentialAlgorithmEnum]
799
800 parse_expiry_from_cert : typing.Optional[bool]
801 Parse expiry from x509 certificate. If true, attempts to parse the expiry date from the provided PEM. Applies to `public_key` credential type.
802
803 expires_at : typing.Optional[dt.datetime]
804 The ISO 8601 formatted date representing the expiration of the credential. If not specified (not recommended), the credential never expires. Applies to `public_key` credential type.
805
806 kid : typing.Optional[str]
807 Optional kid (Key ID), used to uniquely identify the credential. If not specified, a kid value will be auto-generated. The kid header parameter in JWTs sent by your client should match this value. Valid format is [0-9a-zA-Z-_]{10,64}
808
809 request_options : typing.Optional[RequestOptions]
810 Request-specific configuration.
811
812 Returns
813 -------
814 AsyncHttpResponse[PostClientCredentialResponseContent]
815 Credential successfully created.
816 """
817 _response = await self._client_wrapper.httpx_client.request(
818 f"clients/{encode_path_param(client_id)}/credentials",
819 method="POST",
820 json={
821 "credential_type": credential_type,
822 "name": name,
823 "subject_dn": subject_dn,
824 "pem": pem,
825 "alg": alg,
826 "parse_expiry_from_cert": parse_expiry_from_cert,
827 "expires_at": expires_at,
828 "kid": kid,
829 },
830 headers={
831 "content-type": "application/json",
832 },
833 request_options=request_options,
834 omit=OMIT,
835 )
836 try:
837 if 200 <= _response.status_code < 300:
838 _data = typing.cast(
839 PostClientCredentialResponseContent,
840 parse_obj_as(
841 type_=PostClientCredentialResponseContent, # type: ignore
842 object_=_response.json(),
843 ),
844 )
845 return AsyncHttpResponse(response=_response, data=_data)
846 if _response.status_code == 400:
847 raise BadRequestError(
848 headers=dict(_response.headers),
849 body=typing.cast(
850 typing.Any,
851 parse_obj_as(
852 type_=typing.Any, # type: ignore
853 object_=_response.json(),
854 ),
855 ),
856 )
857 if _response.status_code == 401:
858 raise UnauthorizedError(
859 headers=dict(_response.headers),
860 body=typing.cast(
861 typing.Any,
862 parse_obj_as(
863 type_=typing.Any, # type: ignore
864 object_=_response.json(),
865 ),
866 ),
867 )
868 if _response.status_code == 403:
869 raise ForbiddenError(
870 headers=dict(_response.headers),
871 body=typing.cast(
872 typing.Any,
873 parse_obj_as(
874 type_=typing.Any, # type: ignore
875 object_=_response.json(),
876 ),
877 ),
878 )
879 if _response.status_code == 404:
880 raise NotFoundError(
881 headers=dict(_response.headers),
882 body=typing.cast(
883 typing.Any,
884 parse_obj_as(
885 type_=typing.Any, # type: ignore
886 object_=_response.json(),
887 ),
888 ),
889 )
890 if _response.status_code == 429:
891 raise TooManyRequestsError(
892 headers=dict(_response.headers),
893 body=typing.cast(
894 typing.Any,
895 parse_obj_as(
896 type_=typing.Any, # type: ignore
897 object_=_response.json(),
898 ),
899 ),
900 )
901 _response_json = _response.json()
902 except JSONDecodeError:
903 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
904 except ValidationError as e:
905 raise ParsingError(
906 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
907 )
908 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
909
910 async def get(
911 self, client_id: str, credential_id: str, *, request_options: typing.Optional[RequestOptions] = None
912 ) -> AsyncHttpResponse[GetClientCredentialResponseContent]:
913 """
914 Get the details of a client credential.
915
916 **Important**: To enable credentials to be used for a client authentication method, set the `client_authentication_methods` property on the client. To enable credentials to be used for JWT-Secured Authorization requests set the `signed_request_object` property on the client.
917
918 Parameters
919 ----------
920 client_id : str
921 ID of the client.
922
923 credential_id : str
924 ID of the credential.
925
926 request_options : typing.Optional[RequestOptions]
927 Request-specific configuration.
928
929 Returns
930 -------
931 AsyncHttpResponse[GetClientCredentialResponseContent]
932 Credential successfully retrieved.
933 """
934 _response = await self._client_wrapper.httpx_client.request(
935 f"clients/{encode_path_param(client_id)}/credentials/{encode_path_param(credential_id)}",
936 method="GET",
937 request_options=request_options,
938 )
939 try:
940 if 200 <= _response.status_code < 300:
941 _data = typing.cast(
942 GetClientCredentialResponseContent,
943 parse_obj_as(
944 type_=GetClientCredentialResponseContent, # type: ignore
945 object_=_response.json(),
946 ),
947 )
948 return AsyncHttpResponse(response=_response, data=_data)
949 if _response.status_code == 401:
950 raise UnauthorizedError(
951 headers=dict(_response.headers),
952 body=typing.cast(
953 typing.Any,
954 parse_obj_as(
955 type_=typing.Any, # type: ignore
956 object_=_response.json(),
957 ),
958 ),
959 )
960 if _response.status_code == 403:
961 raise ForbiddenError(
962 headers=dict(_response.headers),
963 body=typing.cast(
964 typing.Any,
965 parse_obj_as(
966 type_=typing.Any, # type: ignore
967 object_=_response.json(),
968 ),
969 ),
970 )
971 if _response.status_code == 404:
972 raise NotFoundError(
973 headers=dict(_response.headers),
974 body=typing.cast(
975 typing.Any,
976 parse_obj_as(
977 type_=typing.Any, # type: ignore
978 object_=_response.json(),
979 ),
980 ),
981 )
982 if _response.status_code == 429:
983 raise TooManyRequestsError(
984 headers=dict(_response.headers),
985 body=typing.cast(
986 typing.Any,
987 parse_obj_as(
988 type_=typing.Any, # type: ignore
989 object_=_response.json(),
990 ),
991 ),
992 )
993 _response_json = _response.json()
994 except JSONDecodeError:
995 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
996 except ValidationError as e:
997 raise ParsingError(
998 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
999 )
1000 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
1001
1002 async def delete(
1003 self, client_id: str, credential_id: str, *, request_options: typing.Optional[RequestOptions] = None
1004 ) -> AsyncHttpResponse[None]:
1005 """
1006 Delete a client credential you previously created. May be enabled or disabled. For more information, read <a href="https://www.auth0.com/docs/get-started/authentication-and-authorization-flow/client-credentials-flow">Client Credential Flow</a>.
1007
1008 Parameters
1009 ----------
1010 client_id : str
1011 ID of the client.
1012
1013 credential_id : str
1014 ID of the credential to delete.
1015
1016 request_options : typing.Optional[RequestOptions]
1017 Request-specific configuration.
1018
1019 Returns
1020 -------
1021 AsyncHttpResponse[None]
1022 """
1023 _response = await self._client_wrapper.httpx_client.request(
1024 f"clients/{encode_path_param(client_id)}/credentials/{encode_path_param(credential_id)}",
1025 method="DELETE",
1026 request_options=request_options,
1027 )
1028 try:
1029 if 200 <= _response.status_code < 300:
1030 return AsyncHttpResponse(response=_response, data=None)
1031 if _response.status_code == 400:
1032 raise BadRequestError(
1033 headers=dict(_response.headers),
1034 body=typing.cast(
1035 typing.Any,
1036 parse_obj_as(
1037 type_=typing.Any, # type: ignore
1038 object_=_response.json(),
1039 ),
1040 ),
1041 )
1042 if _response.status_code == 401:
1043 raise UnauthorizedError(
1044 headers=dict(_response.headers),
1045 body=typing.cast(
1046 typing.Any,
1047 parse_obj_as(
1048 type_=typing.Any, # type: ignore
1049 object_=_response.json(),
1050 ),
1051 ),
1052 )
1053 if _response.status_code == 403:
1054 raise ForbiddenError(
1055 headers=dict(_response.headers),
1056 body=typing.cast(
1057 typing.Any,
1058 parse_obj_as(
1059 type_=typing.Any, # type: ignore
1060 object_=_response.json(),
1061 ),
1062 ),
1063 )
1064 if _response.status_code == 429:
1065 raise TooManyRequestsError(
1066 headers=dict(_response.headers),
1067 body=typing.cast(
1068 typing.Any,
1069 parse_obj_as(
1070 type_=typing.Any, # type: ignore
1071 object_=_response.json(),
1072 ),
1073 ),
1074 )
1075 _response_json = _response.json()
1076 except JSONDecodeError:
1077 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
1078 except ValidationError as e:
1079 raise ParsingError(
1080 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
1081 )
1082 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
1083
1084 async def update(
1085 self,
1086 client_id: str,
1087 credential_id: str,
1088 *,
1089 expires_at: typing.Optional[dt.datetime] = OMIT,
1090 request_options: typing.Optional[RequestOptions] = None,
1091 ) -> AsyncHttpResponse[PatchClientCredentialResponseContent]:
1092 """
1093 Change a client credential you previously created. May be enabled or disabled. For more information, read <a href="https://www.auth0.com/docs/get-started/authentication-and-authorization-flow/client-credentials-flow">Client Credential Flow</a>.
1094
1095 Parameters
1096 ----------
1097 client_id : str
1098 ID of the client.
1099
1100 credential_id : str
1101 ID of the credential.
1102
1103 expires_at : typing.Optional[dt.datetime]
1104 The ISO 8601 formatted date representing the expiration of the credential.
1105
1106 request_options : typing.Optional[RequestOptions]
1107 Request-specific configuration.
1108
1109 Returns
1110 -------
1111 AsyncHttpResponse[PatchClientCredentialResponseContent]
1112 Credential successfully updated.
1113 """
1114 _response = await self._client_wrapper.httpx_client.request(
1115 f"clients/{encode_path_param(client_id)}/credentials/{encode_path_param(credential_id)}",
1116 method="PATCH",
1117 json={
1118 "expires_at": expires_at,
1119 },
1120 headers={
1121 "content-type": "application/json",
1122 },
1123 request_options=request_options,
1124 omit=OMIT,
1125 )
1126 try:
1127 if 200 <= _response.status_code < 300:
1128 _data = typing.cast(
1129 PatchClientCredentialResponseContent,
1130 parse_obj_as(
1131 type_=PatchClientCredentialResponseContent, # type: ignore
1132 object_=_response.json(),
1133 ),
1134 )
1135 return AsyncHttpResponse(response=_response, data=_data)
1136 if _response.status_code == 400:
1137 raise BadRequestError(
1138 headers=dict(_response.headers),
1139 body=typing.cast(
1140 typing.Any,
1141 parse_obj_as(
1142 type_=typing.Any, # type: ignore
1143 object_=_response.json(),
1144 ),
1145 ),
1146 )
1147 if _response.status_code == 401:
1148 raise UnauthorizedError(
1149 headers=dict(_response.headers),
1150 body=typing.cast(
1151 typing.Any,
1152 parse_obj_as(
1153 type_=typing.Any, # type: ignore
1154 object_=_response.json(),
1155 ),
1156 ),
1157 )
1158 if _response.status_code == 403:
1159 raise ForbiddenError(
1160 headers=dict(_response.headers),
1161 body=typing.cast(
1162 typing.Any,
1163 parse_obj_as(
1164 type_=typing.Any, # type: ignore
1165 object_=_response.json(),
1166 ),
1167 ),
1168 )
1169 if _response.status_code == 404:
1170 raise NotFoundError(
1171 headers=dict(_response.headers),
1172 body=typing.cast(
1173 typing.Any,
1174 parse_obj_as(
1175 type_=typing.Any, # type: ignore
1176 object_=_response.json(),
1177 ),
1178 ),
1179 )
1180 if _response.status_code == 429:
1181 raise TooManyRequestsError(
1182 headers=dict(_response.headers),
1183 body=typing.cast(
1184 typing.Any,
1185 parse_obj_as(
1186 type_=typing.Any, # type: ignore
1187 object_=_response.json(),
1188 ),
1189 ),
1190 )
1191 _response_json = _response.json()
1192 except JSONDecodeError:
1193 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
1194 except ValidationError as e:
1195 raise ParsingError(
1196 status_code=_response.status_code, headers=dict(_response.headers), body=_response.json(), cause=e
1197 )
1198 raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)