-
Notifications
You must be signed in to change notification settings - Fork 12
/
fusionauth_client.py
4711 lines (3987 loc) · 178 KB
/
fusionauth_client.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#
# Copyright (c) 2018-2023, FusionAuth, All Rights Reserved
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
# either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
#
from deprecated import deprecated
from fusionauth.rest_client import RESTClient, JSONBodyHandler, FormDataBodyHandler
class FusionAuthClient:
"""The FusionAuthClient provides easy access to the FusionAuth API."""
def __init__(self, api_key, base_url):
"""Constructs a new FusionAuthClient.
Attributes:
api_key: A string representing the API used to authenticate the API call to FusionAuth
base_url: A string representing the URL use to access FusionAuth
"""
self.api_key = api_key
self.base_url = base_url
self.tenant_id = None
def set_tenant_id(self, tenant_id):
"""Sets the tenant_id on the client"""
self.tenant_id = tenant_id
def action_user(self, request):
"""
Takes an action on a user. The user being actioned is called the "actionee" and the user taking the action is called the
"actioner". Both user ids are required in the request object.
Attributes:
request: The action request that includes all the information about the action being taken including
the Id of the action, any options and the duration (if applicable).
"""
return self.start().uri('/api/user/action') \
.body_handler(JSONBodyHandler(request)) \
.post() \
.go()
def activate_reactor(self, request):
"""
Activates the FusionAuth Reactor using a license Id and optionally a license text (for air-gapped deployments)
Attributes:
request: An optional request that contains the license text to activate Reactor (useful for air-gap deployments of FusionAuth).
"""
return self.start().uri('/api/reactor') \
.body_handler(JSONBodyHandler(request)) \
.post() \
.go()
def add_user_to_family(self, family_id, request):
"""
Adds a user to an existing family. The family Id must be specified.
Attributes:
family_id: The Id of the family.
request: The request object that contains all the information used to determine which user to add to the family.
"""
return self.start().uri('/api/user/family') \
.url_segment(family_id) \
.body_handler(JSONBodyHandler(request)) \
.put() \
.go()
def approve_device(self, token, user_code, client_id=None, client_secret=None):
"""
Approve a device grant.
Attributes:
client_id: (Optional) The unique client identifier. The client Id is the Id of the FusionAuth Application in which you are attempting to authenticate.
client_secret: (Optional) The client secret. This value will be required if client authentication is enabled.
token: The access token used to identify the user.
user_code: The end-user verification code.
"""
body = {
"client_id": client_id,
"client_secret": client_secret,
"token": token,
"user_code": user_code,
}
return self.start().uri('/oauth2/device/approve') \
.body_handler(FormDataBodyHandler(body)) \
.post() \
.go()
def cancel_action(self, action_id, request):
"""
Cancels the user action.
Attributes:
action_id: The action Id of the action to cancel.
request: The action request that contains the information about the cancellation.
"""
return self.start().uri('/api/user/action') \
.url_segment(action_id) \
.body_handler(JSONBodyHandler(request)) \
.delete() \
.go()
def change_password(self, change_password_id, request):
"""
Changes a user's password using the change password Id. This usually occurs after an email has been sent to the user
and they clicked on a link to reset their password.
As of version 1.32.2, prefer sending the changePasswordId in the request body. To do this, omit the first parameter, and set
the value in the request body.
Attributes:
change_password_id: The change password Id used to find the user. This value is generated by FusionAuth once the change password workflow has been initiated.
request: The change password request that contains all the information used to change the password.
"""
return self.start_anonymous().uri('/api/user/change-password') \
.url_segment(change_password_id) \
.body_handler(JSONBodyHandler(request)) \
.post() \
.go()
def change_password_by_identity(self, request):
"""
Changes a user's password using their identity (loginId and password). Using a loginId instead of the changePasswordId
bypasses the email verification and allows a password to be changed directly without first calling the #forgotPassword
method.
Attributes:
request: The change password request that contains all the information used to change the password.
"""
return self.start().uri('/api/user/change-password') \
.body_handler(JSONBodyHandler(request)) \
.post() \
.go()
def check_change_password_using_id(self, change_password_id):
"""
Check to see if the user must obtain a Trust Token Id in order to complete a change password request.
When a user has enabled Two-Factor authentication, before you are allowed to use the Change Password API to change
your password, you must obtain a Trust Token by completing a Two-Factor Step-Up authentication.
An HTTP status code of 400 with a general error code of [TrustTokenRequired] indicates that a Trust Token is required to make a POST request to this API.
Attributes:
change_password_id: The change password Id used to find the user. This value is generated by FusionAuth once the change password workflow has been initiated.
"""
return self.start_anonymous().uri('/api/user/change-password') \
.url_segment(change_password_id) \
.get() \
.go()
def check_change_password_using_jwt(self, encoded_jwt):
"""
Check to see if the user must obtain a Trust Token Id in order to complete a change password request.
When a user has enabled Two-Factor authentication, before you are allowed to use the Change Password API to change
your password, you must obtain a Trust Token by completing a Two-Factor Step-Up authentication.
An HTTP status code of 400 with a general error code of [TrustTokenRequired] indicates that a Trust Token is required to make a POST request to this API.
Attributes:
encoded_jwt: The encoded JWT (access token).
"""
return self.start_anonymous().uri('/api/user/change-password') \
.authorization("Bearer " + encoded_jwt) \
.get() \
.go()
def check_change_password_using_login_id(self, login_id):
"""
Check to see if the user must obtain a Trust Request Id in order to complete a change password request.
When a user has enabled Two-Factor authentication, before you are allowed to use the Change Password API to change
your password, you must obtain a Trust Request Id by completing a Two-Factor Step-Up authentication.
An HTTP status code of 400 with a general error code of [TrustTokenRequired] indicates that a Trust Token is required to make a POST request to this API.
Attributes:
login_id: The loginId of the User that you intend to change the password for.
"""
return self.start().uri('/api/user/change-password') \
.url_parameter('username', self.convert_true_false(login_id)) \
.get() \
.go()
def client_credentials_grant(self, client_id=None, client_secret=None, scope=None):
"""
Make a Client Credentials grant request to obtain an access token.
Attributes:
client_id: (Optional) The client identifier. The client Id is the Id of the FusionAuth Entity in which you are attempting to authenticate.
This parameter is optional when Basic Authorization is used to authenticate this request.
client_secret: (Optional) The client secret used to authenticate this request.
This parameter is optional when Basic Authorization is used to authenticate this request.
scope: (Optional) This parameter is used to indicate which target entity you are requesting access. To request access to an entity, use the format target-entity:<target-entity-id>:<roles>. Roles are an optional comma separated list.
"""
body = {
"client_id": client_id,
"client_secret": client_secret,
"grant_type": "client_credentials",
"scope": scope,
}
return self.start_anonymous().uri('/oauth2/token') \
.body_handler(FormDataBodyHandler(body)) \
.post() \
.go()
def comment_on_user(self, request):
"""
Adds a comment to the user's account.
Attributes:
request: The request object that contains all the information used to create the user comment.
"""
return self.start().uri('/api/user/comment') \
.body_handler(JSONBodyHandler(request)) \
.post() \
.go()
def complete_web_authn_assertion(self, request):
"""
Complete a WebAuthn authentication ceremony by validating the signature against the previously generated challenge without logging the user in
Attributes:
request: An object containing data necessary for completing the authentication ceremony
"""
return self.start_anonymous().uri('/api/webauthn/assert') \
.body_handler(JSONBodyHandler(request)) \
.post() \
.go()
def complete_web_authn_login(self, request):
"""
Complete a WebAuthn authentication ceremony by validating the signature against the previously generated challenge and then login the user in
Attributes:
request: An object containing data necessary for completing the authentication ceremony
"""
return self.start_anonymous().uri('/api/webauthn/login') \
.body_handler(JSONBodyHandler(request)) \
.post() \
.go()
def complete_web_authn_registration(self, request):
"""
Complete a WebAuthn registration ceremony by validating the client request and saving the new credential
Attributes:
request: An object containing data necessary for completing the registration ceremony
"""
return self.start().uri('/api/webauthn/register/complete') \
.body_handler(JSONBodyHandler(request)) \
.post() \
.go()
def create_api_key(self, request, key_id=None):
"""
Creates an API key. You can optionally specify a unique Id for the key, if not provided one will be generated.
an API key can only be created with equal or lesser authority. An API key cannot create another API key unless it is granted
to that API key.
If an API key is locked to a tenant, it can only create API Keys for that same tenant.
Attributes:
key_id: (Optional) The unique Id of the API key. If not provided a secure random Id will be generated.
request: The request object that contains all the information needed to create the APIKey.
"""
return self.start().uri('/api/api-key') \
.url_segment(key_id) \
.body_handler(JSONBodyHandler(request)) \
.post() \
.go()
def create_application(self, request, application_id=None):
"""
Creates an application. You can optionally specify an Id for the application, if not provided one will be generated.
Attributes:
application_id: (Optional) The Id to use for the application. If not provided a secure random UUID will be generated.
request: The request object that contains all the information used to create the application.
"""
return self.start().uri('/api/application') \
.url_segment(application_id) \
.body_handler(JSONBodyHandler(request)) \
.post() \
.go()
def create_application_role(self, application_id, request, role_id=None):
"""
Creates a new role for an application. You must specify the Id of the application you are creating the role for.
You can optionally specify an Id for the role inside the ApplicationRole object itself, if not provided one will be generated.
Attributes:
application_id: The Id of the application to create the role on.
role_id: (Optional) The Id of the role. If not provided a secure random UUID will be generated.
request: The request object that contains all the information used to create the application role.
"""
return self.start().uri('/api/application') \
.url_segment(application_id) \
.url_segment("role") \
.url_segment(role_id) \
.body_handler(JSONBodyHandler(request)) \
.post() \
.go()
def create_audit_log(self, request):
"""
Creates an audit log with the message and user name (usually an email). Audit logs should be written anytime you
make changes to the FusionAuth database. When using the FusionAuth App web interface, any changes are automatically
written to the audit log. However, if you are accessing the API, you must write the audit logs yourself.
Attributes:
request: The request object that contains all the information used to create the audit log entry.
"""
return self.start().uri('/api/system/audit-log') \
.body_handler(JSONBodyHandler(request)) \
.post() \
.go()
def create_connector(self, request, connector_id=None):
"""
Creates a connector. You can optionally specify an Id for the connector, if not provided one will be generated.
Attributes:
connector_id: (Optional) The Id for the connector. If not provided a secure random UUID will be generated.
request: The request object that contains all the information used to create the connector.
"""
return self.start().uri('/api/connector') \
.url_segment(connector_id) \
.body_handler(JSONBodyHandler(request)) \
.post() \
.go()
def create_consent(self, request, consent_id=None):
"""
Creates a user consent type. You can optionally specify an Id for the consent type, if not provided one will be generated.
Attributes:
consent_id: (Optional) The Id for the consent. If not provided a secure random UUID will be generated.
request: The request object that contains all the information used to create the consent.
"""
return self.start().uri('/api/consent') \
.url_segment(consent_id) \
.body_handler(JSONBodyHandler(request)) \
.post() \
.go()
def create_email_template(self, request, email_template_id=None):
"""
Creates an email template. You can optionally specify an Id for the template, if not provided one will be generated.
Attributes:
email_template_id: (Optional) The Id for the template. If not provided a secure random UUID will be generated.
request: The request object that contains all the information used to create the email template.
"""
return self.start().uri('/api/email/template') \
.url_segment(email_template_id) \
.body_handler(JSONBodyHandler(request)) \
.post() \
.go()
def create_entity(self, request, entity_id=None):
"""
Creates an Entity. You can optionally specify an Id for the Entity. If not provided one will be generated.
Attributes:
entity_id: (Optional) The Id for the Entity. If not provided a secure random UUID will be generated.
request: The request object that contains all the information used to create the Entity.
"""
return self.start().uri('/api/entity') \
.url_segment(entity_id) \
.body_handler(JSONBodyHandler(request)) \
.post() \
.go()
def create_entity_type(self, request, entity_type_id=None):
"""
Creates a Entity Type. You can optionally specify an Id for the Entity Type, if not provided one will be generated.
Attributes:
entity_type_id: (Optional) The Id for the Entity Type. If not provided a secure random UUID will be generated.
request: The request object that contains all the information used to create the Entity Type.
"""
return self.start().uri('/api/entity/type') \
.url_segment(entity_type_id) \
.body_handler(JSONBodyHandler(request)) \
.post() \
.go()
def create_entity_type_permission(self, entity_type_id, request, permission_id=None):
"""
Creates a new permission for an entity type. You must specify the Id of the entity type you are creating the permission for.
You can optionally specify an Id for the permission inside the EntityTypePermission object itself, if not provided one will be generated.
Attributes:
entity_type_id: The Id of the entity type to create the permission on.
permission_id: (Optional) The Id of the permission. If not provided a secure random UUID will be generated.
request: The request object that contains all the information used to create the permission.
"""
return self.start().uri('/api/entity/type') \
.url_segment(entity_type_id) \
.url_segment("permission") \
.url_segment(permission_id) \
.body_handler(JSONBodyHandler(request)) \
.post() \
.go()
def create_family(self, request, family_id=None):
"""
Creates a family with the user Id in the request as the owner and sole member of the family. You can optionally specify an Id for the
family, if not provided one will be generated.
Attributes:
family_id: (Optional) The Id for the family. If not provided a secure random UUID will be generated.
request: The request object that contains all the information used to create the family.
"""
return self.start().uri('/api/user/family') \
.url_segment(family_id) \
.body_handler(JSONBodyHandler(request)) \
.post() \
.go()
def create_form(self, request, form_id=None):
"""
Creates a form. You can optionally specify an Id for the form, if not provided one will be generated.
Attributes:
form_id: (Optional) The Id for the form. If not provided a secure random UUID will be generated.
request: The request object that contains all the information used to create the form.
"""
return self.start().uri('/api/form') \
.url_segment(form_id) \
.body_handler(JSONBodyHandler(request)) \
.post() \
.go()
def create_form_field(self, request, field_id=None):
"""
Creates a form field. You can optionally specify an Id for the form, if not provided one will be generated.
Attributes:
field_id: (Optional) The Id for the form field. If not provided a secure random UUID will be generated.
request: The request object that contains all the information used to create the form field.
"""
return self.start().uri('/api/form/field') \
.url_segment(field_id) \
.body_handler(JSONBodyHandler(request)) \
.post() \
.go()
def create_group(self, request, group_id=None):
"""
Creates a group. You can optionally specify an Id for the group, if not provided one will be generated.
Attributes:
group_id: (Optional) The Id for the group. If not provided a secure random UUID will be generated.
request: The request object that contains all the information used to create the group.
"""
return self.start().uri('/api/group') \
.url_segment(group_id) \
.body_handler(JSONBodyHandler(request)) \
.post() \
.go()
def create_group_members(self, request):
"""
Creates a member in a group.
Attributes:
request: The request object that contains all the information used to create the group member(s).
"""
return self.start().uri('/api/group/member') \
.body_handler(JSONBodyHandler(request)) \
.post() \
.go()
def create_ip_access_control_list(self, request, access_control_list_id=None):
"""
Creates an IP Access Control List. You can optionally specify an Id on this create request, if one is not provided one will be generated.
Attributes:
access_control_list_id: (Optional) The Id for the IP Access Control List. If not provided a secure random UUID will be generated.
request: The request object that contains all the information used to create the IP Access Control List.
"""
return self.start().uri('/api/ip-acl') \
.url_segment(access_control_list_id) \
.body_handler(JSONBodyHandler(request)) \
.post() \
.go()
def create_identity_provider(self, request, identity_provider_id=None):
"""
Creates an identity provider. You can optionally specify an Id for the identity provider, if not provided one will be generated.
Attributes:
identity_provider_id: (Optional) The Id of the identity provider. If not provided a secure random UUID will be generated.
request: The request object that contains all the information used to create the identity provider.
"""
return self.start().uri('/api/identity-provider') \
.url_segment(identity_provider_id) \
.body_handler(JSONBodyHandler(request)) \
.post() \
.go()
def create_lambda(self, request, lambda_id=None):
"""
Creates a Lambda. You can optionally specify an Id for the lambda, if not provided one will be generated.
Attributes:
lambda_id: (Optional) The Id for the lambda. If not provided a secure random UUID will be generated.
request: The request object that contains all the information used to create the lambda.
"""
return self.start().uri('/api/lambda') \
.url_segment(lambda_id) \
.body_handler(JSONBodyHandler(request)) \
.post() \
.go()
def create_message_template(self, request, message_template_id=None):
"""
Creates an message template. You can optionally specify an Id for the template, if not provided one will be generated.
Attributes:
message_template_id: (Optional) The Id for the template. If not provided a secure random UUID will be generated.
request: The request object that contains all the information used to create the message template.
"""
return self.start().uri('/api/message/template') \
.url_segment(message_template_id) \
.body_handler(JSONBodyHandler(request)) \
.post() \
.go()
def create_messenger(self, request, messenger_id=None):
"""
Creates a messenger. You can optionally specify an Id for the messenger, if not provided one will be generated.
Attributes:
messenger_id: (Optional) The Id for the messenger. If not provided a secure random UUID will be generated.
request: The request object that contains all the information used to create the messenger.
"""
return self.start().uri('/api/messenger') \
.url_segment(messenger_id) \
.body_handler(JSONBodyHandler(request)) \
.post() \
.go()
def create_o_auth_scope(self, application_id, request, scope_id=None):
"""
Creates a new custom OAuth scope for an application. You must specify the Id of the application you are creating the scope for.
You can optionally specify an Id for the OAuth scope on the URL, if not provided one will be generated.
Attributes:
application_id: The Id of the application to create the OAuth scope on.
scope_id: (Optional) The Id of the OAuth scope. If not provided a secure random UUID will be generated.
request: The request object that contains all the information used to create the OAuth OAuth scope.
"""
return self.start().uri('/api/application') \
.url_segment(application_id) \
.url_segment("scope") \
.url_segment(scope_id) \
.body_handler(JSONBodyHandler(request)) \
.post() \
.go()
def create_tenant(self, request, tenant_id=None):
"""
Creates a tenant. You can optionally specify an Id for the tenant, if not provided one will be generated.
Attributes:
tenant_id: (Optional) The Id for the tenant. If not provided a secure random UUID will be generated.
request: The request object that contains all the information used to create the tenant.
"""
return self.start().uri('/api/tenant') \
.url_segment(tenant_id) \
.body_handler(JSONBodyHandler(request)) \
.post() \
.go()
def create_theme(self, request, theme_id=None):
"""
Creates a Theme. You can optionally specify an Id for the theme, if not provided one will be generated.
Attributes:
theme_id: (Optional) The Id for the theme. If not provided a secure random UUID will be generated.
request: The request object that contains all the information used to create the theme.
"""
return self.start().uri('/api/theme') \
.url_segment(theme_id) \
.body_handler(JSONBodyHandler(request)) \
.post() \
.go()
def create_user(self, request, user_id=None):
"""
Creates a user. You can optionally specify an Id for the user, if not provided one will be generated.
Attributes:
user_id: (Optional) The Id for the user. If not provided a secure random UUID will be generated.
request: The request object that contains all the information used to create the user.
"""
return self.start().uri('/api/user') \
.url_segment(user_id) \
.body_handler(JSONBodyHandler(request)) \
.post() \
.go()
def create_user_action(self, request, user_action_id=None):
"""
Creates a user action. This action cannot be taken on a user until this call successfully returns. Anytime after
that the user action can be applied to any user.
Attributes:
user_action_id: (Optional) The Id for the user action. If not provided a secure random UUID will be generated.
request: The request object that contains all the information used to create the user action.
"""
return self.start().uri('/api/user-action') \
.url_segment(user_action_id) \
.body_handler(JSONBodyHandler(request)) \
.post() \
.go()
def create_user_action_reason(self, request, user_action_reason_id=None):
"""
Creates a user reason. This user action reason cannot be used when actioning a user until this call completes
successfully. Anytime after that the user action reason can be used.
Attributes:
user_action_reason_id: (Optional) The Id for the user action reason. If not provided a secure random UUID will be generated.
request: The request object that contains all the information used to create the user action reason.
"""
return self.start().uri('/api/user-action-reason') \
.url_segment(user_action_reason_id) \
.body_handler(JSONBodyHandler(request)) \
.post() \
.go()
def create_user_consent(self, request, user_consent_id=None):
"""
Creates a single User consent.
Attributes:
user_consent_id: (Optional) The Id for the User consent. If not provided a secure random UUID will be generated.
request: The request that contains the user consent information.
"""
return self.start().uri('/api/user/consent') \
.url_segment(user_consent_id) \
.body_handler(JSONBodyHandler(request)) \
.post() \
.go()
def create_user_link(self, request):
"""
Link an external user from a 3rd party identity provider to a FusionAuth user.
Attributes:
request: The request object that contains all the information used to link the FusionAuth user.
"""
return self.start().uri('/api/identity-provider/link') \
.body_handler(JSONBodyHandler(request)) \
.post() \
.go()
def create_webhook(self, request, webhook_id=None):
"""
Creates a webhook. You can optionally specify an Id for the webhook, if not provided one will be generated.
Attributes:
webhook_id: (Optional) The Id for the webhook. If not provided a secure random UUID will be generated.
request: The request object that contains all the information used to create the webhook.
"""
return self.start().uri('/api/webhook') \
.url_segment(webhook_id) \
.body_handler(JSONBodyHandler(request)) \
.post() \
.go()
def deactivate_application(self, application_id):
"""
Deactivates the application with the given Id.
Attributes:
application_id: The Id of the application to deactivate.
"""
return self.start().uri('/api/application') \
.url_segment(application_id) \
.delete() \
.go()
def deactivate_reactor(self):
"""
Deactivates the FusionAuth Reactor.
Attributes:
"""
return self.start().uri('/api/reactor') \
.delete() \
.go()
def deactivate_user(self, user_id):
"""
Deactivates the user with the given Id.
Attributes:
user_id: The Id of the user to deactivate.
"""
return self.start().uri('/api/user') \
.url_segment(user_id) \
.delete() \
.go()
def deactivate_user_action(self, user_action_id):
"""
Deactivates the user action with the given Id.
Attributes:
user_action_id: The Id of the user action to deactivate.
"""
return self.start().uri('/api/user-action') \
.url_segment(user_action_id) \
.delete() \
.go()
@deprecated("This method has been renamed to deactivate_users_by_ids, use that method instead.")
def deactivate_users(self, user_ids):
"""
Deactivates the users with the given ids.
Attributes:
user_ids: The ids of the users to deactivate.
"""
return self.start().uri('/api/user/bulk') \
.url_parameter('userId', self.convert_true_false(user_ids)) \
.url_parameter('dryRun', self.convert_true_false("false")) \
.url_parameter('hardDelete', self.convert_true_false("false")) \
.delete() \
.go()
def deactivate_users_by_ids(self, user_ids):
"""
Deactivates the users with the given ids.
Attributes:
user_ids: The ids of the users to deactivate.
"""
return self.start().uri('/api/user/bulk') \
.url_parameter('userId', self.convert_true_false(user_ids)) \
.url_parameter('dryRun', self.convert_true_false("false")) \
.url_parameter('hardDelete', self.convert_true_false("false")) \
.delete() \
.go()
def delete_api_key(self, key_id):
"""
Deletes the API key for the given Id.
Attributes:
key_id: The Id of the authentication API key to delete.
"""
return self.start().uri('/api/api-key') \
.url_segment(key_id) \
.delete() \
.go()
def delete_application(self, application_id):
"""
Hard deletes an application. This is a dangerous operation and should not be used in most circumstances. This will
delete the application, any registrations for that application, metrics and reports for the application, all the
roles for the application, and any other data associated with the application. This operation could take a very
long time, depending on the amount of data in your database.
Attributes:
application_id: The Id of the application to delete.
"""
return self.start().uri('/api/application') \
.url_segment(application_id) \
.url_parameter('hardDelete', self.convert_true_false("true")) \
.delete() \
.go()
def delete_application_role(self, application_id, role_id):
"""
Hard deletes an application role. This is a dangerous operation and should not be used in most circumstances. This
permanently removes the given role from all users that had it.
Attributes:
application_id: The Id of the application that the role belongs to.
role_id: The Id of the role to delete.
"""
return self.start().uri('/api/application') \
.url_segment(application_id) \
.url_segment("role") \
.url_segment(role_id) \
.delete() \
.go()
def delete_connector(self, connector_id):
"""
Deletes the connector for the given Id.
Attributes:
connector_id: The Id of the connector to delete.
"""
return self.start().uri('/api/connector') \
.url_segment(connector_id) \
.delete() \
.go()
def delete_consent(self, consent_id):
"""
Deletes the consent for the given Id.
Attributes:
consent_id: The Id of the consent to delete.
"""
return self.start().uri('/api/consent') \
.url_segment(consent_id) \
.delete() \
.go()
def delete_email_template(self, email_template_id):
"""
Deletes the email template for the given Id.
Attributes:
email_template_id: The Id of the email template to delete.
"""
return self.start().uri('/api/email/template') \
.url_segment(email_template_id) \
.delete() \
.go()
def delete_entity(self, entity_id):
"""
Deletes the Entity for the given Id.
Attributes:
entity_id: The Id of the Entity to delete.
"""
return self.start().uri('/api/entity') \
.url_segment(entity_id) \
.delete() \
.go()
def delete_entity_grant(self, entity_id, recipient_entity_id=None, user_id=None):
"""
Deletes an Entity Grant for the given User or Entity.
Attributes:
entity_id: The Id of the Entity that the Entity Grant is being deleted for.
recipient_entity_id: (Optional) The Id of the Entity that the Entity Grant is for.
user_id: (Optional) The Id of the User that the Entity Grant is for.
"""
return self.start().uri('/api/entity') \
.url_segment(entity_id) \
.url_segment("grant") \
.url_parameter('recipientEntityId', self.convert_true_false(recipient_entity_id)) \
.url_parameter('userId', self.convert_true_false(user_id)) \
.delete() \
.go()
def delete_entity_type(self, entity_type_id):
"""
Deletes the Entity Type for the given Id.
Attributes:
entity_type_id: The Id of the Entity Type to delete.
"""
return self.start().uri('/api/entity/type') \
.url_segment(entity_type_id) \
.delete() \
.go()
def delete_entity_type_permission(self, entity_type_id, permission_id):
"""
Hard deletes a permission. This is a dangerous operation and should not be used in most circumstances. This
permanently removes the given permission from all grants that had it.
Attributes:
entity_type_id: The Id of the entityType the the permission belongs to.
permission_id: The Id of the permission to delete.
"""
return self.start().uri('/api/entity/type') \
.url_segment(entity_type_id) \
.url_segment("permission") \
.url_segment(permission_id) \
.delete() \
.go()
def delete_form(self, form_id):
"""
Deletes the form for the given Id.
Attributes:
form_id: The Id of the form to delete.
"""
return self.start().uri('/api/form') \
.url_segment(form_id) \
.delete() \
.go()
def delete_form_field(self, field_id):
"""
Deletes the form field for the given Id.
Attributes:
field_id: The Id of the form field to delete.
"""
return self.start().uri('/api/form/field') \
.url_segment(field_id) \
.delete() \
.go()
def delete_group(self, group_id):
"""
Deletes the group for the given Id.
Attributes:
group_id: The Id of the group to delete.
"""
return self.start().uri('/api/group') \
.url_segment(group_id) \
.delete() \
.go()
def delete_group_members(self, request):
"""
Removes users as members of a group.
Attributes:
request: The member request that contains all the information used to remove members to the group.
"""
return self.start().uri('/api/group/member') \
.body_handler(JSONBodyHandler(request)) \
.delete() \
.go()
def delete_ip_access_control_list(self, ip_access_control_list_id):
"""
Deletes the IP Access Control List for the given Id.
Attributes:
ip_access_control_list_id: The Id of the IP Access Control List to delete.
"""
return self.start().uri('/api/ip-acl') \
.url_segment(ip_access_control_list_id) \
.delete() \
.go()
def delete_identity_provider(self, identity_provider_id):
"""
Deletes the identity provider for the given Id.
Attributes:
identity_provider_id: The Id of the identity provider to delete.
"""
return self.start().uri('/api/identity-provider') \
.url_segment(identity_provider_id) \
.delete() \
.go()
def delete_key(self, key_id):
"""
Deletes the key for the given Id.
Attributes:
key_id: The Id of the key to delete.
"""
return self.start().uri('/api/key') \
.url_segment(key_id) \
.delete() \
.go()
def delete_lambda(self, lambda_id):
"""
Deletes the lambda for the given Id.
Attributes:
lambda_id: The Id of the lambda to delete.
"""
return self.start().uri('/api/lambda') \
.url_segment(lambda_id) \
.delete() \
.go()
def delete_message_template(self, message_template_id):
"""
Deletes the message template for the given Id.
Attributes:
message_template_id: The Id of the message template to delete.
"""
return self.start().uri('/api/message/template') \