-
Notifications
You must be signed in to change notification settings - Fork 5
/
FusionAuthClient.java
5734 lines (5365 loc) · 220 KB
/
FusionAuthClient.java
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.
*/
package io.fusionauth.client;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.inversoft.error.Errors;
import com.inversoft.json.JacksonModule;
import com.inversoft.rest.ClientResponse;
import com.inversoft.rest.FormDataBodyHandler;
import com.inversoft.rest.JSONBodyHandler;
import com.inversoft.rest.JSONResponseHandler;
import com.inversoft.rest.RESTClient;
import io.fusionauth.domain.LambdaType;
import io.fusionauth.domain.OpenIdConfiguration;
import io.fusionauth.domain.api.APIKeyRequest;
import io.fusionauth.domain.api.APIKeyResponse;
import io.fusionauth.domain.api.ApplicationOAuthScopeRequest;
import io.fusionauth.domain.api.ApplicationOAuthScopeResponse;
import io.fusionauth.domain.api.ApplicationRequest;
import io.fusionauth.domain.api.ApplicationResponse;
import io.fusionauth.domain.api.ApplicationSearchRequest;
import io.fusionauth.domain.api.ApplicationSearchResponse;
import io.fusionauth.domain.api.AuditLogRequest;
import io.fusionauth.domain.api.AuditLogResponse;
import io.fusionauth.domain.api.AuditLogSearchRequest;
import io.fusionauth.domain.api.AuditLogSearchResponse;
import io.fusionauth.domain.api.ConnectorRequest;
import io.fusionauth.domain.api.ConnectorResponse;
import io.fusionauth.domain.api.ConsentRequest;
import io.fusionauth.domain.api.ConsentResponse;
import io.fusionauth.domain.api.ConsentSearchRequest;
import io.fusionauth.domain.api.ConsentSearchResponse;
import io.fusionauth.domain.api.EmailTemplateRequest;
import io.fusionauth.domain.api.EmailTemplateResponse;
import io.fusionauth.domain.api.EmailTemplateSearchRequest;
import io.fusionauth.domain.api.EmailTemplateSearchResponse;
import io.fusionauth.domain.api.EntityGrantRequest;
import io.fusionauth.domain.api.EntityGrantResponse;
import io.fusionauth.domain.api.EntityGrantSearchRequest;
import io.fusionauth.domain.api.EntityGrantSearchResponse;
import io.fusionauth.domain.api.EntityRequest;
import io.fusionauth.domain.api.EntityResponse;
import io.fusionauth.domain.api.EntitySearchRequest;
import io.fusionauth.domain.api.EntitySearchResponse;
import io.fusionauth.domain.api.EntityTypeRequest;
import io.fusionauth.domain.api.EntityTypeResponse;
import io.fusionauth.domain.api.EntityTypeSearchRequest;
import io.fusionauth.domain.api.EntityTypeSearchResponse;
import io.fusionauth.domain.api.EventLogResponse;
import io.fusionauth.domain.api.EventLogSearchRequest;
import io.fusionauth.domain.api.EventLogSearchResponse;
import io.fusionauth.domain.api.FamilyEmailRequest;
import io.fusionauth.domain.api.FamilyRequest;
import io.fusionauth.domain.api.FamilyResponse;
import io.fusionauth.domain.api.FormFieldRequest;
import io.fusionauth.domain.api.FormFieldResponse;
import io.fusionauth.domain.api.FormRequest;
import io.fusionauth.domain.api.FormResponse;
import io.fusionauth.domain.api.GroupMemberSearchRequest;
import io.fusionauth.domain.api.GroupMemberSearchResponse;
import io.fusionauth.domain.api.GroupSearchRequest;
import io.fusionauth.domain.api.GroupSearchResponse;
import io.fusionauth.domain.api.GroupRequest;
import io.fusionauth.domain.api.GroupResponse;
import io.fusionauth.domain.api.IPAccessControlListRequest;
import io.fusionauth.domain.api.IPAccessControlListResponse;
import io.fusionauth.domain.api.IPAccessControlListSearchRequest;
import io.fusionauth.domain.api.IPAccessControlListSearchResponse;
import io.fusionauth.domain.api.IdentityProviderSearchRequest;
import io.fusionauth.domain.api.IdentityProviderSearchResponse;
import io.fusionauth.domain.api.IdentityProviderRequest;
import io.fusionauth.domain.api.IdentityProviderResponse;
import io.fusionauth.domain.api.IntegrationRequest;
import io.fusionauth.domain.api.IntegrationResponse;
import io.fusionauth.domain.api.KeyRequest;
import io.fusionauth.domain.api.KeyResponse;
import io.fusionauth.domain.api.KeySearchRequest;
import io.fusionauth.domain.api.KeySearchResponse;
import io.fusionauth.domain.api.LambdaRequest;
import io.fusionauth.domain.api.LambdaResponse;
import io.fusionauth.domain.api.LambdaSearchRequest;
import io.fusionauth.domain.api.LambdaSearchResponse;
import io.fusionauth.domain.api.LoginRecordSearchRequest;
import io.fusionauth.domain.api.LoginRecordSearchResponse;
import io.fusionauth.domain.api.LoginPingRequest;
import io.fusionauth.domain.api.LoginRequest;
import io.fusionauth.domain.api.LoginResponse;
import io.fusionauth.domain.api.LogoutRequest;
import io.fusionauth.domain.api.MemberDeleteRequest;
import io.fusionauth.domain.api.MemberRequest;
import io.fusionauth.domain.api.MemberResponse;
import io.fusionauth.domain.api.MessageTemplateRequest;
import io.fusionauth.domain.api.MessageTemplateResponse;
import io.fusionauth.domain.api.MessengerRequest;
import io.fusionauth.domain.api.MessengerResponse;
import io.fusionauth.domain.api.OAuthConfigurationResponse;
import io.fusionauth.domain.api.PasswordValidationRulesResponse;
import io.fusionauth.domain.api.PendingResponse;
import io.fusionauth.domain.api.PreviewMessageTemplateRequest;
import io.fusionauth.domain.api.PreviewMessageTemplateResponse;
import io.fusionauth.domain.api.PreviewRequest;
import io.fusionauth.domain.api.PreviewResponse;
import io.fusionauth.domain.api.PublicKeyResponse;
import io.fusionauth.domain.api.ReactorMetricsResponse;
import io.fusionauth.domain.api.ReactorRequest;
import io.fusionauth.domain.api.ReactorResponse;
import io.fusionauth.domain.api.ReindexRequest;
import io.fusionauth.domain.api.StatusResponse;
import io.fusionauth.domain.api.SystemConfigurationRequest;
import io.fusionauth.domain.api.SystemConfigurationResponse;
import io.fusionauth.domain.api.TenantDeleteRequest;
import io.fusionauth.domain.api.TenantRequest;
import io.fusionauth.domain.api.TenantResponse;
import io.fusionauth.domain.api.TenantSearchRequest;
import io.fusionauth.domain.api.TenantSearchResponse;
import io.fusionauth.domain.api.ThemeRequest;
import io.fusionauth.domain.api.ThemeResponse;
import io.fusionauth.domain.api.ThemeSearchRequest;
import io.fusionauth.domain.api.ThemeSearchResponse;
import io.fusionauth.domain.api.TwoFactorDisableRequest;
import io.fusionauth.domain.api.TwoFactorRecoveryCodeResponse;
import io.fusionauth.domain.api.TwoFactorRequest;
import io.fusionauth.domain.api.TwoFactorResponse;
import io.fusionauth.domain.api.UserActionReasonRequest;
import io.fusionauth.domain.api.UserActionReasonResponse;
import io.fusionauth.domain.api.UserActionRequest;
import io.fusionauth.domain.api.UserActionResponse;
import io.fusionauth.domain.api.UserCommentRequest;
import io.fusionauth.domain.api.UserCommentResponse;
import io.fusionauth.domain.api.UserCommentSearchRequest;
import io.fusionauth.domain.api.UserCommentSearchResponse;
import io.fusionauth.domain.api.UserConsentRequest;
import io.fusionauth.domain.api.UserConsentResponse;
import io.fusionauth.domain.api.UserDeleteRequest;
import io.fusionauth.domain.api.UserDeleteResponse;
import io.fusionauth.domain.api.UserDeleteSingleRequest;
import io.fusionauth.domain.api.UserRequest;
import io.fusionauth.domain.api.UserResponse;
import io.fusionauth.domain.api.VersionResponse;
import io.fusionauth.domain.api.WebAuthnAssertResponse;
import io.fusionauth.domain.api.WebAuthnCredentialImportRequest;
import io.fusionauth.domain.api.WebAuthnCredentialResponse;
import io.fusionauth.domain.api.WebAuthnLoginRequest;
import io.fusionauth.domain.api.WebAuthnRegisterCompleteRequest;
import io.fusionauth.domain.api.WebAuthnRegisterCompleteResponse;
import io.fusionauth.domain.api.WebAuthnRegisterStartRequest;
import io.fusionauth.domain.api.WebAuthnRegisterStartResponse;
import io.fusionauth.domain.api.WebAuthnStartRequest;
import io.fusionauth.domain.api.WebAuthnStartResponse;
import io.fusionauth.domain.api.WebhookAttemptLogResponse;
import io.fusionauth.domain.api.WebhookEventLogResponse;
import io.fusionauth.domain.api.WebhookEventLogSearchRequest;
import io.fusionauth.domain.api.WebhookEventLogSearchResponse;
import io.fusionauth.domain.api.WebhookRequest;
import io.fusionauth.domain.api.WebhookResponse;
import io.fusionauth.domain.api.WebhookSearchRequest;
import io.fusionauth.domain.api.WebhookSearchResponse;
import io.fusionauth.domain.api.email.SendRequest;
import io.fusionauth.domain.api.email.SendResponse;
import io.fusionauth.domain.api.identityProvider.IdentityProviderLinkRequest;
import io.fusionauth.domain.api.identityProvider.IdentityProviderLinkResponse;
import io.fusionauth.domain.api.identityProvider.IdentityProviderLoginRequest;
import io.fusionauth.domain.api.identityProvider.IdentityProviderPendingLinkResponse;
import io.fusionauth.domain.api.identityProvider.IdentityProviderStartLoginRequest;
import io.fusionauth.domain.api.identityProvider.IdentityProviderStartLoginResponse;
import io.fusionauth.domain.api.identityProvider.LookupResponse;
import io.fusionauth.domain.api.jwt.IssueResponse;
import io.fusionauth.domain.api.jwt.JWTRefreshResponse;
import io.fusionauth.domain.api.jwt.JWTVendRequest;
import io.fusionauth.domain.api.jwt.JWTVendResponse;
import io.fusionauth.domain.api.jwt.RefreshRequest;
import io.fusionauth.domain.api.jwt.RefreshTokenResponse;
import io.fusionauth.domain.api.jwt.RefreshTokenRevokeRequest;
import io.fusionauth.domain.api.jwt.ValidateResponse;
import io.fusionauth.domain.api.passwordless.PasswordlessLoginRequest;
import io.fusionauth.domain.api.passwordless.PasswordlessSendRequest;
import io.fusionauth.domain.api.passwordless.PasswordlessStartRequest;
import io.fusionauth.domain.api.passwordless.PasswordlessStartResponse;
import io.fusionauth.domain.api.report.DailyActiveUserReportResponse;
import io.fusionauth.domain.api.report.LoginReportResponse;
import io.fusionauth.domain.api.report.MonthlyActiveUserReportResponse;
import io.fusionauth.domain.api.report.RegistrationReportResponse;
import io.fusionauth.domain.api.report.TotalsReportResponse;
import io.fusionauth.domain.api.twoFactor.SecretResponse;
import io.fusionauth.domain.api.twoFactor.TwoFactorLoginRequest;
import io.fusionauth.domain.api.twoFactor.TwoFactorSendRequest;
import io.fusionauth.domain.api.twoFactor.TwoFactorStartRequest;
import io.fusionauth.domain.api.twoFactor.TwoFactorStartResponse;
import io.fusionauth.domain.api.twoFactor.TwoFactorStatusResponse;
import io.fusionauth.domain.api.user.ActionRequest;
import io.fusionauth.domain.api.user.ActionResponse;
import io.fusionauth.domain.api.user.ChangePasswordRequest;
import io.fusionauth.domain.api.user.ChangePasswordResponse;
import io.fusionauth.domain.api.user.ForgotPasswordRequest;
import io.fusionauth.domain.api.user.ForgotPasswordResponse;
import io.fusionauth.domain.api.user.ImportRequest;
import io.fusionauth.domain.api.user.RecentLoginResponse;
import io.fusionauth.domain.api.user.RefreshTokenImportRequest;
import io.fusionauth.domain.api.user.RegistrationDeleteRequest;
import io.fusionauth.domain.api.user.RegistrationRequest;
import io.fusionauth.domain.api.user.RegistrationResponse;
import io.fusionauth.domain.api.user.SearchRequest;
import io.fusionauth.domain.api.user.SearchResponse;
import io.fusionauth.domain.api.user.VerifyEmailRequest;
import io.fusionauth.domain.api.user.VerifyEmailResponse;
import io.fusionauth.domain.api.user.VerifyRegistrationRequest;
import io.fusionauth.domain.api.user.VerifyRegistrationResponse;
import io.fusionauth.domain.oauth2.AccessToken;
import io.fusionauth.domain.oauth2.DeviceApprovalResponse;
import io.fusionauth.domain.oauth2.IntrospectResponse;
import io.fusionauth.domain.oauth2.JWKSResponse;
import io.fusionauth.domain.oauth2.OAuthError;
import io.fusionauth.domain.oauth2.UserinfoResponse;
import io.fusionauth.domain.provider.IdentityProviderType;
/**
* Client that connects to a FusionAuth server and provides access to the full set of FusionAuth APIs.
* <p>
* When any method is called the return value is always a ClientResponse object. When an API call was successful, the
* response will contain the response from the server. This might be empty or contain an success object or an error
* object. If there was a validation error or any other type of error, this will return the Errors object in the
* response. Additionally, if FusionAuth could not be contacted because it is down or experiencing a failure, the response
* will contain an Exception, which could be an IOException.
*
* @author Brian Pontarelli
*/
@SuppressWarnings("unused")
public class FusionAuthClient {
public static String TENANT_ID_HEADER = "X-FusionAuth-TenantId";
public static final ObjectMapper objectMapper = new ObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_NULL)
.configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true)
.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false)
.configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, true)
.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, false)
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
.configure(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS, true)
.configure(DeserializationFeature.USE_BIG_INTEGER_FOR_INTS, true)
.registerModule(new JacksonModule());
private final String apiKey;
private final String baseURL;
private final ObjectMapper customMapper;
private final String tenantId;
public int connectTimeout;
public int readTimeout;
public FusionAuthClient(String apiKey, String baseURL) {
this(apiKey, baseURL, null);
}
public FusionAuthClient(String apiKey, String baseURL, String tenantId) {
this(apiKey, baseURL, 2000, 2000, tenantId);
}
public FusionAuthClient(String apiKey, String baseURL, int connectTimeout, int readTimeout) {
this(apiKey, baseURL, connectTimeout, readTimeout, null);
}
public FusionAuthClient(String apiKey, String baseURL, int connectTimeout, int readTimeout, String tenantId) {
this(apiKey, baseURL, connectTimeout, readTimeout, tenantId, null);
}
public FusionAuthClient(String apiKey, String baseURL, int connectTimeout, int readTimeout, String tenantId, ObjectMapper objectMapper) {
this.apiKey = apiKey;
this.baseURL = baseURL;
this.connectTimeout = connectTimeout;
this.readTimeout = readTimeout;
this.tenantId = tenantId;
this.customMapper = objectMapper;
}
/**
* Creates a new copy of this client with the provided tenant Id. When more than one tenant is configured in FusionAuth
* use this method to set the tenant Id prior to making API calls.
* <p>
* When only one tenant is configured, or you have not configured tenants, setting the tenant is not necessary.
*
* @param tenantId The tenant Id
* @return the new FusionAuthClient
*/
public FusionAuthClient setTenantId(UUID tenantId) {
if (tenantId == null) {
return this;
}
return new FusionAuthClient(apiKey, baseURL, connectTimeout, readTimeout, tenantId.toString());
}
/**
* Creates a new copy of this client with the object mapper. This will take the place of the default FusionAuth object mapper when serializing
* and deserializing objects to and from JSON for the request and response bodies.
*
* @param objectMapper The object mapper
* @return the new FusionAuthClient
*/
public FusionAuthClient setObjectMapper(ObjectMapper objectMapper) {
return new FusionAuthClient(apiKey, baseURL, connectTimeout, readTimeout, tenantId, objectMapper);
}
/**
* 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.
*
* @param 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 The ClientResponse object.
*/
public ClientResponse<ActionResponse, Errors> actionUser(ActionRequest request) {
return start(ActionResponse.class, Errors.class)
.uri("/api/user/action")
.bodyHandler(new JSONBodyHandler(request, objectMapper()))
.post()
.go();
}
/**
* Activates the FusionAuth Reactor using a license Id and optionally a license text (for air-gapped deployments)
*
* @param request An optional request that contains the license text to activate Reactor (useful for air-gap deployments of FusionAuth).
* @return The ClientResponse object.
*/
public ClientResponse<Void, Errors> activateReactor(ReactorRequest request) {
return start(Void.TYPE, Errors.class)
.uri("/api/reactor")
.bodyHandler(new JSONBodyHandler(request, objectMapper()))
.post()
.go();
}
/**
* Adds a user to an existing family. The family Id must be specified.
*
* @param familyId The Id of the family.
* @param request The request object that contains all the information used to determine which user to add to the family.
* @return The ClientResponse object.
*/
public ClientResponse<FamilyResponse, Errors> addUserToFamily(UUID familyId, FamilyRequest request) {
return start(FamilyResponse.class, Errors.class)
.uri("/api/user/family")
.urlSegment(familyId)
.bodyHandler(new JSONBodyHandler(request, objectMapper()))
.put()
.go();
}
/**
* Approve a device grant.
*
* @param client_id (Optional) The unique client identifier. The client Id is the Id of the FusionAuth Application in which you are attempting to authenticate.
* @param client_secret (Optional) The client secret. This value will be required if client authentication is enabled.
* @param token The access token used to identify the user.
* @param user_code The end-user verification code.
* @return The ClientResponse object.
*/
public ClientResponse<DeviceApprovalResponse, Errors> approveDevice(String client_id, String client_secret, String token, String user_code) {
Map<String, List<String>> parameters = new HashMap<>();
parameters.put("client_id", Arrays.asList(client_id));
parameters.put("client_secret", Arrays.asList(client_secret));
parameters.put("token", Arrays.asList(token));
parameters.put("user_code", Arrays.asList(user_code));
return start(DeviceApprovalResponse.class, Errors.class)
.uri("/oauth2/device/approve")
.bodyHandler(new FormDataBodyHandler(parameters))
.post()
.go();
}
/**
* Cancels the user action.
*
* @param actionId The action Id of the action to cancel.
* @param request The action request that contains the information about the cancellation.
* @return The ClientResponse object.
*/
public ClientResponse<ActionResponse, Errors> cancelAction(UUID actionId, ActionRequest request) {
return start(ActionResponse.class, Errors.class)
.uri("/api/user/action")
.urlSegment(actionId)
.bodyHandler(new JSONBodyHandler(request, objectMapper()))
.delete()
.go();
}
/**
* 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.
* <p>
* 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.
*
* @param changePasswordId The change password Id used to find the user. This value is generated by FusionAuth once the change password workflow has been initiated.
* @param request The change password request that contains all the information used to change the password.
* @return The ClientResponse object.
*/
public ClientResponse<ChangePasswordResponse, Errors> changePassword(String changePasswordId, ChangePasswordRequest request) {
return startAnonymous(ChangePasswordResponse.class, Errors.class)
.uri("/api/user/change-password")
.urlSegment(changePasswordId)
.bodyHandler(new JSONBodyHandler(request, objectMapper()))
.post()
.go();
}
/**
* 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.
*
* @param request The change password request that contains all the information used to change the password.
* @return The ClientResponse object.
*/
public ClientResponse<Void, Errors> changePasswordByIdentity(ChangePasswordRequest request) {
return start(Void.TYPE, Errors.class)
.uri("/api/user/change-password")
.bodyHandler(new JSONBodyHandler(request, objectMapper()))
.post()
.go();
}
/**
* 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.
* <p>
* 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.
*
* @param changePasswordId The change password Id used to find the user. This value is generated by FusionAuth once the change password workflow has been initiated.
* @return The ClientResponse object.
*/
public ClientResponse<Void, Errors> checkChangePasswordUsingId(String changePasswordId) {
return startAnonymous(Void.TYPE, Errors.class)
.uri("/api/user/change-password")
.urlSegment(changePasswordId)
.get()
.go();
}
/**
* 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.
* <p>
* 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.
*
* @param encodedJWT The encoded JWT (access token).
* @return The ClientResponse object.
*/
public ClientResponse<Void, Errors> checkChangePasswordUsingJWT(String encodedJWT) {
return startAnonymous(Void.TYPE, Errors.class)
.uri("/api/user/change-password")
.authorization("Bearer " + encodedJWT)
.get()
.go();
}
/**
* 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.
* <p>
* 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.
*
* @param loginId The loginId of the User that you intend to change the password for.
* @return The ClientResponse object.
*/
public ClientResponse<Void, Errors> checkChangePasswordUsingLoginId(String loginId) {
return start(Void.TYPE, Errors.class)
.uri("/api/user/change-password")
.urlParameter("username", loginId)
.get()
.go();
}
/**
* Make a Client Credentials grant request to obtain an access token.
*
* @param 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.
* @param client_secret (Optional) The client secret used to authenticate this request.
* This parameter is optional when Basic Authorization is used to authenticate this request.
* @param 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.
* @return The ClientResponse object.
*/
public ClientResponse<AccessToken, OAuthError> clientCredentialsGrant(String client_id, String client_secret, String scope) {
Map<String, List<String>> parameters = new HashMap<>();
parameters.put("client_id", Arrays.asList(client_id));
parameters.put("client_secret", Arrays.asList(client_secret));
parameters.put("grant_type", Arrays.asList("client_credentials"));
parameters.put("scope", Arrays.asList(scope));
return startAnonymous(AccessToken.class, OAuthError.class)
.uri("/oauth2/token")
.bodyHandler(new FormDataBodyHandler(parameters))
.post()
.go();
}
/**
* Adds a comment to the user's account.
*
* @param request The request object that contains all the information used to create the user comment.
* @return The ClientResponse object.
*/
public ClientResponse<UserCommentResponse, Errors> commentOnUser(UserCommentRequest request) {
return start(UserCommentResponse.class, Errors.class)
.uri("/api/user/comment")
.bodyHandler(new JSONBodyHandler(request, objectMapper()))
.post()
.go();
}
/**
* Complete a WebAuthn authentication ceremony by validating the signature against the previously generated challenge without logging the user in
*
* @param request An object containing data necessary for completing the authentication ceremony
* @return The ClientResponse object.
*/
public ClientResponse<WebAuthnAssertResponse, Errors> completeWebAuthnAssertion(WebAuthnLoginRequest request) {
return startAnonymous(WebAuthnAssertResponse.class, Errors.class)
.uri("/api/webauthn/assert")
.bodyHandler(new JSONBodyHandler(request, objectMapper()))
.post()
.go();
}
/**
* Complete a WebAuthn authentication ceremony by validating the signature against the previously generated challenge and then login the user in
*
* @param request An object containing data necessary for completing the authentication ceremony
* @return The ClientResponse object.
*/
public ClientResponse<LoginResponse, Errors> completeWebAuthnLogin(WebAuthnLoginRequest request) {
return startAnonymous(LoginResponse.class, Errors.class)
.uri("/api/webauthn/login")
.bodyHandler(new JSONBodyHandler(request, objectMapper()))
.post()
.go();
}
/**
* Complete a WebAuthn registration ceremony by validating the client request and saving the new credential
*
* @param request An object containing data necessary for completing the registration ceremony
* @return The ClientResponse object.
*/
public ClientResponse<WebAuthnRegisterCompleteResponse, Errors> completeWebAuthnRegistration(WebAuthnRegisterCompleteRequest request) {
return start(WebAuthnRegisterCompleteResponse.class, Errors.class)
.uri("/api/webauthn/register/complete")
.bodyHandler(new JSONBodyHandler(request, objectMapper()))
.post()
.go();
}
/**
* 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.
* <p>
* If an API key is locked to a tenant, it can only create API Keys for that same tenant.
*
* @param keyId (Optional) The unique Id of the API key. If not provided a secure random Id will be generated.
* @param request The request object that contains all the information needed to create the APIKey.
* @return The ClientResponse object.
*/
public ClientResponse<APIKeyResponse, Errors> createAPIKey(UUID keyId, APIKeyRequest request) {
return start(APIKeyResponse.class, Errors.class)
.uri("/api/api-key")
.urlSegment(keyId)
.bodyHandler(new JSONBodyHandler(request, objectMapper()))
.post()
.go();
}
/**
* Creates an application. You can optionally specify an Id for the application, if not provided one will be generated.
*
* @param applicationId (Optional) The Id to use for the application. If not provided a secure random UUID will be generated.
* @param request The request object that contains all the information used to create the application.
* @return The ClientResponse object.
*/
public ClientResponse<ApplicationResponse, Errors> createApplication(UUID applicationId, ApplicationRequest request) {
return start(ApplicationResponse.class, Errors.class)
.uri("/api/application")
.urlSegment(applicationId)
.bodyHandler(new JSONBodyHandler(request, objectMapper()))
.post()
.go();
}
/**
* 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.
*
* @param applicationId The Id of the application to create the role on.
* @param roleId (Optional) The Id of the role. If not provided a secure random UUID will be generated.
* @param request The request object that contains all the information used to create the application role.
* @return The ClientResponse object.
*/
public ClientResponse<ApplicationResponse, Errors> createApplicationRole(UUID applicationId, UUID roleId, ApplicationRequest request) {
return start(ApplicationResponse.class, Errors.class)
.uri("/api/application")
.urlSegment(applicationId)
.urlSegment("role")
.urlSegment(roleId)
.bodyHandler(new JSONBodyHandler(request, objectMapper()))
.post()
.go();
}
/**
* 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.
*
* @param request The request object that contains all the information used to create the audit log entry.
* @return The ClientResponse object.
*/
public ClientResponse<AuditLogResponse, Errors> createAuditLog(AuditLogRequest request) {
return start(AuditLogResponse.class, Errors.class)
.uri("/api/system/audit-log")
.bodyHandler(new JSONBodyHandler(request, objectMapper()))
.post()
.go();
}
/**
* Creates a connector. You can optionally specify an Id for the connector, if not provided one will be generated.
*
* @param connectorId (Optional) The Id for the connector. If not provided a secure random UUID will be generated.
* @param request The request object that contains all the information used to create the connector.
* @return The ClientResponse object.
*/
public ClientResponse<ConnectorResponse, Errors> createConnector(UUID connectorId, ConnectorRequest request) {
return start(ConnectorResponse.class, Errors.class)
.uri("/api/connector")
.urlSegment(connectorId)
.bodyHandler(new JSONBodyHandler(request, objectMapper()))
.post()
.go();
}
/**
* Creates a user consent type. You can optionally specify an Id for the consent type, if not provided one will be generated.
*
* @param consentId (Optional) The Id for the consent. If not provided a secure random UUID will be generated.
* @param request The request object that contains all the information used to create the consent.
* @return The ClientResponse object.
*/
public ClientResponse<ConsentResponse, Errors> createConsent(UUID consentId, ConsentRequest request) {
return start(ConsentResponse.class, Errors.class)
.uri("/api/consent")
.urlSegment(consentId)
.bodyHandler(new JSONBodyHandler(request, objectMapper()))
.post()
.go();
}
/**
* Creates an email template. You can optionally specify an Id for the template, if not provided one will be generated.
*
* @param emailTemplateId (Optional) The Id for the template. If not provided a secure random UUID will be generated.
* @param request The request object that contains all the information used to create the email template.
* @return The ClientResponse object.
*/
public ClientResponse<EmailTemplateResponse, Errors> createEmailTemplate(UUID emailTemplateId, EmailTemplateRequest request) {
return start(EmailTemplateResponse.class, Errors.class)
.uri("/api/email/template")
.urlSegment(emailTemplateId)
.bodyHandler(new JSONBodyHandler(request, objectMapper()))
.post()
.go();
}
/**
* Creates an Entity. You can optionally specify an Id for the Entity. If not provided one will be generated.
*
* @param entityId (Optional) The Id for the Entity. If not provided a secure random UUID will be generated.
* @param request The request object that contains all the information used to create the Entity.
* @return The ClientResponse object.
*/
public ClientResponse<EntityResponse, Errors> createEntity(UUID entityId, EntityRequest request) {
return start(EntityResponse.class, Errors.class)
.uri("/api/entity")
.urlSegment(entityId)
.bodyHandler(new JSONBodyHandler(request, objectMapper()))
.post()
.go();
}
/**
* Creates a Entity Type. You can optionally specify an Id for the Entity Type, if not provided one will be generated.
*
* @param entityTypeId (Optional) The Id for the Entity Type. If not provided a secure random UUID will be generated.
* @param request The request object that contains all the information used to create the Entity Type.
* @return The ClientResponse object.
*/
public ClientResponse<EntityTypeResponse, Errors> createEntityType(UUID entityTypeId, EntityTypeRequest request) {
return start(EntityTypeResponse.class, Errors.class)
.uri("/api/entity/type")
.urlSegment(entityTypeId)
.bodyHandler(new JSONBodyHandler(request, objectMapper()))
.post()
.go();
}
/**
* 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.
*
* @param entityTypeId The Id of the entity type to create the permission on.
* @param permissionId (Optional) The Id of the permission. If not provided a secure random UUID will be generated.
* @param request The request object that contains all the information used to create the permission.
* @return The ClientResponse object.
*/
public ClientResponse<EntityTypeResponse, Errors> createEntityTypePermission(UUID entityTypeId, UUID permissionId, EntityTypeRequest request) {
return start(EntityTypeResponse.class, Errors.class)
.uri("/api/entity/type")
.urlSegment(entityTypeId)
.urlSegment("permission")
.urlSegment(permissionId)
.bodyHandler(new JSONBodyHandler(request, objectMapper()))
.post()
.go();
}
/**
* 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.
*
* @param familyId (Optional) The Id for the family. If not provided a secure random UUID will be generated.
* @param request The request object that contains all the information used to create the family.
* @return The ClientResponse object.
*/
public ClientResponse<FamilyResponse, Errors> createFamily(UUID familyId, FamilyRequest request) {
return start(FamilyResponse.class, Errors.class)
.uri("/api/user/family")
.urlSegment(familyId)
.bodyHandler(new JSONBodyHandler(request, objectMapper()))
.post()
.go();
}
/**
* Creates a form. You can optionally specify an Id for the form, if not provided one will be generated.
*
* @param formId (Optional) The Id for the form. If not provided a secure random UUID will be generated.
* @param request The request object that contains all the information used to create the form.
* @return The ClientResponse object.
*/
public ClientResponse<FormResponse, Errors> createForm(UUID formId, FormRequest request) {
return start(FormResponse.class, Errors.class)
.uri("/api/form")
.urlSegment(formId)
.bodyHandler(new JSONBodyHandler(request, objectMapper()))
.post()
.go();
}
/**
* Creates a form field. You can optionally specify an Id for the form, if not provided one will be generated.
*
* @param fieldId (Optional) The Id for the form field. If not provided a secure random UUID will be generated.
* @param request The request object that contains all the information used to create the form field.
* @return The ClientResponse object.
*/
public ClientResponse<FormFieldResponse, Errors> createFormField(UUID fieldId, FormFieldRequest request) {
return start(FormFieldResponse.class, Errors.class)
.uri("/api/form/field")
.urlSegment(fieldId)
.bodyHandler(new JSONBodyHandler(request, objectMapper()))
.post()
.go();
}
/**
* Creates a group. You can optionally specify an Id for the group, if not provided one will be generated.
*
* @param groupId (Optional) The Id for the group. If not provided a secure random UUID will be generated.
* @param request The request object that contains all the information used to create the group.
* @return The ClientResponse object.
*/
public ClientResponse<GroupResponse, Errors> createGroup(UUID groupId, GroupRequest request) {
return start(GroupResponse.class, Errors.class)
.uri("/api/group")
.urlSegment(groupId)
.bodyHandler(new JSONBodyHandler(request, objectMapper()))
.post()
.go();
}
/**
* Creates a member in a group.
*
* @param request The request object that contains all the information used to create the group member(s).
* @return The ClientResponse object.
*/
public ClientResponse<MemberResponse, Errors> createGroupMembers(MemberRequest request) {
return start(MemberResponse.class, Errors.class)
.uri("/api/group/member")
.bodyHandler(new JSONBodyHandler(request, objectMapper()))
.post()
.go();
}
/**
* 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.
*
* @param accessControlListId (Optional) The Id for the IP Access Control List. If not provided a secure random UUID will be generated.
* @param request The request object that contains all the information used to create the IP Access Control List.
* @return The ClientResponse object.
*/
public ClientResponse<IPAccessControlListResponse, Errors> createIPAccessControlList(UUID accessControlListId, IPAccessControlListRequest request) {
return start(IPAccessControlListResponse.class, Errors.class)
.uri("/api/ip-acl")
.urlSegment(accessControlListId)
.bodyHandler(new JSONBodyHandler(request, objectMapper()))
.post()
.go();
}
/**
* Creates an identity provider. You can optionally specify an Id for the identity provider, if not provided one will be generated.
*
* @param identityProviderId (Optional) The Id of the identity provider. If not provided a secure random UUID will be generated.
* @param request The request object that contains all the information used to create the identity provider.
* @return The ClientResponse object.
*/
public ClientResponse<IdentityProviderResponse, Errors> createIdentityProvider(UUID identityProviderId, IdentityProviderRequest request) {
return start(IdentityProviderResponse.class, Errors.class)
.uri("/api/identity-provider")
.urlSegment(identityProviderId)
.bodyHandler(new JSONBodyHandler(request, objectMapper()))
.post()
.go();
}
/**
* Creates a Lambda. You can optionally specify an Id for the lambda, if not provided one will be generated.
*
* @param lambdaId (Optional) The Id for the lambda. If not provided a secure random UUID will be generated.
* @param request The request object that contains all the information used to create the lambda.
* @return The ClientResponse object.
*/
public ClientResponse<LambdaResponse, Errors> createLambda(UUID lambdaId, LambdaRequest request) {
return start(LambdaResponse.class, Errors.class)
.uri("/api/lambda")
.urlSegment(lambdaId)
.bodyHandler(new JSONBodyHandler(request, objectMapper()))
.post()
.go();
}
/**
* Creates an message template. You can optionally specify an Id for the template, if not provided one will be generated.
*
* @param messageTemplateId (Optional) The Id for the template. If not provided a secure random UUID will be generated.
* @param request The request object that contains all the information used to create the message template.
* @return The ClientResponse object.
*/
public ClientResponse<MessageTemplateResponse, Errors> createMessageTemplate(UUID messageTemplateId, MessageTemplateRequest request) {
return start(MessageTemplateResponse.class, Errors.class)
.uri("/api/message/template")
.urlSegment(messageTemplateId)
.bodyHandler(new JSONBodyHandler(request, objectMapper()))
.post()
.go();
}
/**
* Creates a messenger. You can optionally specify an Id for the messenger, if not provided one will be generated.
*
* @param messengerId (Optional) The Id for the messenger. If not provided a secure random UUID will be generated.
* @param request The request object that contains all the information used to create the messenger.
* @return The ClientResponse object.
*/
public ClientResponse<MessengerResponse, Errors> createMessenger(UUID messengerId, MessengerRequest request) {
return start(MessengerResponse.class, Errors.class)
.uri("/api/messenger")
.urlSegment(messengerId)
.bodyHandler(new JSONBodyHandler(request, objectMapper()))
.post()
.go();
}
/**
* 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.
*
* @param applicationId The Id of the application to create the OAuth scope on.
* @param scopeId (Optional) The Id of the OAuth scope. If not provided a secure random UUID will be generated.
* @param request The request object that contains all the information used to create the OAuth OAuth scope.
* @return The ClientResponse object.
*/
public ClientResponse<ApplicationOAuthScopeResponse, Errors> createOAuthScope(UUID applicationId, UUID scopeId, ApplicationOAuthScopeRequest request) {
return start(ApplicationOAuthScopeResponse.class, Errors.class)
.uri("/api/application")
.urlSegment(applicationId)
.urlSegment("scope")
.urlSegment(scopeId)
.bodyHandler(new JSONBodyHandler(request, objectMapper()))
.post()
.go();
}
/**
* Creates a tenant. You can optionally specify an Id for the tenant, if not provided one will be generated.
*
* @param tenantId (Optional) The Id for the tenant. If not provided a secure random UUID will be generated.
* @param request The request object that contains all the information used to create the tenant.
* @return The ClientResponse object.
*/
public ClientResponse<TenantResponse, Errors> createTenant(UUID tenantId, TenantRequest request) {
return start(TenantResponse.class, Errors.class)
.uri("/api/tenant")
.urlSegment(tenantId)
.bodyHandler(new JSONBodyHandler(request, objectMapper()))
.post()
.go();
}
/**
* Creates a Theme. You can optionally specify an Id for the theme, if not provided one will be generated.
*
* @param themeId (Optional) The Id for the theme. If not provided a secure random UUID will be generated.
* @param request The request object that contains all the information used to create the theme.
* @return The ClientResponse object.
*/
public ClientResponse<ThemeResponse, Errors> createTheme(UUID themeId, ThemeRequest request) {
return start(ThemeResponse.class, Errors.class)
.uri("/api/theme")
.urlSegment(themeId)
.bodyHandler(new JSONBodyHandler(request, objectMapper()))
.post()
.go();
}
/**
* Creates a user. You can optionally specify an Id for the user, if not provided one will be generated.
*
* @param userId (Optional) The Id for the user. If not provided a secure random UUID will be generated.
* @param request The request object that contains all the information used to create the user.
* @return The ClientResponse object.
*/
public ClientResponse<UserResponse, Errors> createUser(UUID userId, UserRequest request) {
return start(UserResponse.class, Errors.class)
.uri("/api/user")
.urlSegment(userId)
.bodyHandler(new JSONBodyHandler(request, objectMapper()))
.post()
.go();
}
/**
* 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.
*
* @param userActionId (Optional) The Id for the user action. If not provided a secure random UUID will be generated.
* @param request The request object that contains all the information used to create the user action.
* @return The ClientResponse object.
*/
public ClientResponse<UserActionResponse, Errors> createUserAction(UUID userActionId, UserActionRequest request) {
return start(UserActionResponse.class, Errors.class)
.uri("/api/user-action")
.urlSegment(userActionId)
.bodyHandler(new JSONBodyHandler(request, objectMapper()))
.post()
.go();
}
/**
* Creates a user reason. This user action reason cannot be used when actioning a user until this call completes