|
1 | 1 | package com.auth0.client.mgmt; |
2 | 2 |
|
3 | 3 | import com.auth0.client.mgmt.filter.*; |
| 4 | +import com.auth0.json.mgmt.users.authenticationmethods.AuthenticationMethod; |
| 5 | +import com.auth0.json.mgmt.users.authenticationmethods.AuthenticationMethodsPage; |
4 | 6 | import com.auth0.json.mgmt.permissions.Permission; |
5 | 7 | import com.auth0.json.mgmt.permissions.PermissionsPage; |
6 | 8 | import com.auth0.json.mgmt.roles.RolesPage; |
@@ -578,6 +580,169 @@ public Request<OrganizationsPage> getOrganizations(String userId, PageFilter fil |
578 | 580 | }); |
579 | 581 | } |
580 | 582 |
|
| 583 | + /** |
| 584 | + * Get the authentication methods of the user. |
| 585 | + * A token with {@code read:authentication_methods} is required. |
| 586 | + * |
| 587 | + * @param userId the user ID |
| 588 | + * @param filter an optional pagination filter |
| 589 | + * @return a Request to execute |
| 590 | + * |
| 591 | + * @see <a href="https://auth0.com/docs/api/management/v2#!/Users/get_authentication_methods">https://auth0.com/docs/api/management/v2#!/Users/get_authentication_methods</a> |
| 592 | + */ |
| 593 | + public Request<AuthenticationMethodsPage> getAuthenticationMethods(String userId, PageFilter filter) { |
| 594 | + Asserts.assertNotNull(userId, "user ID"); |
| 595 | + |
| 596 | + HttpUrl.Builder builder = baseUrl |
| 597 | + .newBuilder() |
| 598 | + .addPathSegments("api/v2/users") |
| 599 | + .addPathSegment(userId) |
| 600 | + .addPathSegment("authentication-methods"); |
| 601 | + |
| 602 | + if (filter != null) { |
| 603 | + for (Map.Entry<String, Object> e : filter.getAsMap().entrySet()) { |
| 604 | + builder.addQueryParameter(e.getKey(), String.valueOf(e.getValue())); |
| 605 | + } |
| 606 | + } |
| 607 | + String url = builder.build().toString(); |
| 608 | + return new BaseRequest<>(client, tokenProvider, url, HttpMethod.GET, new TypeReference<AuthenticationMethodsPage>() { |
| 609 | + }); |
| 610 | + } |
| 611 | + |
| 612 | + /** |
| 613 | + * Create an authentication method for a given user. |
| 614 | + * A token with scope {@code create:authentication_methods} is needed. |
| 615 | + * @see <a href="https://auth0.com/docs/api/management/v2#!/Users/post_authentication_methods">https://auth0.com/docs/api/management/v2#!/Users/post_authentication_methods</a> |
| 616 | + * |
| 617 | + * @param userId the user to add authentication method to |
| 618 | + * @param authenticationMethod the authentication method to be created |
| 619 | + * @return a Request to execute. |
| 620 | + */ |
| 621 | + public Request<AuthenticationMethod> createAuthenticationMethods(String userId, AuthenticationMethod authenticationMethod) { |
| 622 | + Asserts.assertNotNull(userId, "user ID"); |
| 623 | + Asserts.assertNotNull(authenticationMethod, "authentication methods"); |
| 624 | + |
| 625 | + String url = baseUrl |
| 626 | + .newBuilder() |
| 627 | + .addPathSegments("api/v2/users") |
| 628 | + .addPathSegment(userId) |
| 629 | + .addPathSegment("authentication-methods") |
| 630 | + .build() |
| 631 | + .toString(); |
| 632 | + BaseRequest<AuthenticationMethod> request = new BaseRequest<>(this.client, tokenProvider, url, HttpMethod.POST, new TypeReference<AuthenticationMethod>() { |
| 633 | + }); |
| 634 | + request.setBody(authenticationMethod); |
| 635 | + return request; |
| 636 | + } |
| 637 | + |
| 638 | + /** |
| 639 | + * Updates an authentication method for a given user. |
| 640 | + * A token with scope {@code update:authentication_methods} is needed. |
| 641 | + * @see <a href="https://auth0.com/docs/api/management/v2#!/Users/put_authentication_methods">https://auth0.com/docs/api/management/v2#!/Users/put_authentication_methods</a> |
| 642 | + * |
| 643 | + * @param userId the user to update authentication method |
| 644 | + * @param authenticationMethods the list of authentication method information to be updated |
| 645 | + * @return a Request to execute. |
| 646 | + */ |
| 647 | + public Request<List<AuthenticationMethod>> updateAuthenticationMethods(String userId, List<AuthenticationMethod> authenticationMethods) { |
| 648 | + Asserts.assertNotNull(userId, "user ID"); |
| 649 | + Asserts.assertNotNull(authenticationMethods, "authentication methods"); |
| 650 | + |
| 651 | + String url = baseUrl |
| 652 | + .newBuilder() |
| 653 | + .addPathSegments("api/v2/users") |
| 654 | + .addPathSegment(userId) |
| 655 | + .addPathSegment("authentication-methods") |
| 656 | + .build() |
| 657 | + .toString(); |
| 658 | + BaseRequest<List<AuthenticationMethod>> request = new BaseRequest<>(this.client, tokenProvider, url, HttpMethod.PUT, new TypeReference<List<AuthenticationMethod>>() { |
| 659 | + }); |
| 660 | + request.setBody(authenticationMethods); |
| 661 | + return request; |
| 662 | + } |
| 663 | + |
| 664 | + /** |
| 665 | + * Gets an authentication method by ID. |
| 666 | + * A token with scope {@code read:authentication_methods} is needed. |
| 667 | + * @see <a href="https://auth0.com/docs/api/management/v2#!/Users/get_authentication_methods_by_authentication_method_id">https://auth0.com/docs/api/management/v2#!/Users/get_authentication_methods_by_authentication_method_id</a> |
| 668 | + * |
| 669 | + * @param userId the user to get authentication method for |
| 670 | + * @param authenticationMethodId the authentication method to be fetched |
| 671 | + * @return a Request to execute. |
| 672 | + */ |
| 673 | + public Request<AuthenticationMethod> getAuthenticationMethodById(String userId, String authenticationMethodId) { |
| 674 | + Asserts.assertNotNull(userId, "user ID"); |
| 675 | + Asserts.assertNotNull(authenticationMethodId, "authentication method ID"); |
| 676 | + |
| 677 | + String url = baseUrl |
| 678 | + .newBuilder() |
| 679 | + .addPathSegments("api/v2/users") |
| 680 | + .addPathSegment(userId) |
| 681 | + .addPathSegment("authentication-methods") |
| 682 | + .addPathSegment(authenticationMethodId) |
| 683 | + .build() |
| 684 | + .toString(); |
| 685 | + |
| 686 | + return new BaseRequest<>(this.client, tokenProvider, url, HttpMethod.GET, new TypeReference<AuthenticationMethod>() { |
| 687 | + }); |
| 688 | + } |
| 689 | + |
| 690 | + /** |
| 691 | + * Deletes an authentication method by ID. |
| 692 | + * A token with scope {@code delete:authentication_methods} is needed. |
| 693 | + * @see <a href="https://auth0.com/docs/api/management/v2#!/Users/delete_authentication_methods_by_authentication_method_id">https://auth0.com/docs/api/management/v2#!/Users/delete_authentication_methods_by_authentication_method_id</a> |
| 694 | + * |
| 695 | + * @param userId the user to delete the authentication method for |
| 696 | + * @param authenticationMethodId the authentication method to be deleted |
| 697 | + * @return a Request to execute. |
| 698 | + */ |
| 699 | + public Request<Void> deleteAuthenticationMethodById(String userId, String authenticationMethodId) { |
| 700 | + Asserts.assertNotNull(userId, "user ID"); |
| 701 | + Asserts.assertNotNull(authenticationMethodId, "authentication method ID"); |
| 702 | + |
| 703 | + String url = baseUrl |
| 704 | + .newBuilder() |
| 705 | + .addPathSegments("api/v2/users") |
| 706 | + .addPathSegment(userId) |
| 707 | + .addPathSegment("authentication-methods") |
| 708 | + .addPathSegment(authenticationMethodId) |
| 709 | + .build() |
| 710 | + .toString(); |
| 711 | + |
| 712 | + return new BaseRequest<>(this.client, tokenProvider, url, HttpMethod.DELETE, new TypeReference<Void>() { |
| 713 | + }); |
| 714 | + } |
| 715 | + |
| 716 | + /** |
| 717 | + * Updates an authentication method. |
| 718 | + * A token with scope {@code update:authentication_methods} is needed. |
| 719 | + * @see <a href="https://auth0.com/docs/api/management/v2#!/Users/patch_authentication_methods_by_authentication_method_id">https://auth0.com/docs/api/management/v2#!/Users/patch_authentication_methods_by_authentication_method_id</a> |
| 720 | + * |
| 721 | + * @param userId the user to delete the authentication method for |
| 722 | + * @param authenticationMethodId the authentication method to be deleted |
| 723 | + * @param authenticationMethod the information to be updated |
| 724 | + * @return a Request to execute. |
| 725 | + */ |
| 726 | + public Request<AuthenticationMethod> updateAuthenticationMethodById(String userId, String authenticationMethodId, AuthenticationMethod authenticationMethod) { |
| 727 | + Asserts.assertNotNull(userId, "user ID"); |
| 728 | + Asserts.assertNotNull(authenticationMethodId, "authentication method ID"); |
| 729 | + Asserts.assertNotNull(authenticationMethod, "authentication method"); |
| 730 | + |
| 731 | + String url = baseUrl |
| 732 | + .newBuilder() |
| 733 | + .addPathSegments("api/v2/users") |
| 734 | + .addPathSegment(userId) |
| 735 | + .addPathSegment("authentication-methods") |
| 736 | + .addPathSegment(authenticationMethodId) |
| 737 | + .build() |
| 738 | + .toString(); |
| 739 | + |
| 740 | + BaseRequest<AuthenticationMethod> request = new BaseRequest<>(this.client, tokenProvider, url, HttpMethod.PATCH, new TypeReference<AuthenticationMethod>() { |
| 741 | + }); |
| 742 | + request.setBody(authenticationMethod); |
| 743 | + return request; |
| 744 | + } |
| 745 | + |
581 | 746 | private static void encodeAndAddQueryParam(HttpUrl.Builder builder, BaseFilter filter) { |
582 | 747 | if (filter != null) { |
583 | 748 | for (Map.Entry<String, Object> e : filter.getAsMap().entrySet()) { |
|
0 commit comments