Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix de/serialization of Invitation roles #380

Merged
merged 2 commits into from
Oct 5, 2021
Merged

Fix de/serialization of Invitation roles #380

merged 2 commits into from
Oct 5, 2021

Conversation

lbalmaceda
Copy link
Contributor

@lbalmaceda lbalmaceda commented Oct 4, 2021

Changes

The Invitation object has an array of strings for the roles ids. This is NOT an object and thus, should not be serialized wrapped as an object.

References

Fixes #378 without introducing breaking changes.

Testing

Manually tested with the following snippets. Also, fixed unit tests.

static void assignRole(ManagementAPI api) {
    try {
        api.organizations().addRoles(ORG_ID,
            USER_ID,
            new Roles(Arrays.asList(ADMIN_ROLE_ID)))
            .execute();
    } catch (Auth0Exception e) {
        e.printStackTrace();
    }
}

static void listInvitations(ManagementAPI api) {
    try {
        // Originally failed when invitation contains one or more Roles
        InvitationsPage page = api.organizations().getInvitations(ORG_ID, null).execute();
        for (Invitation i : page.getItems()) {
            System.out.println(i);
        }
    } catch (Auth0Exception e) {
        e.printStackTrace();
    }
}

static void sendInvitation(ManagementAPI api) {
    Invitation invitation = new Invitation(
        new Inviter("Luciano"),
        new Invitee("luciano.balmaceda@auth0.com"),
        CLIENT_ID
    );
    invitation.setRoles(new Roles(Arrays.asList(ADMIN_ROLE_ID)));
    Invitation result;
    try {
        // Originally failed because invitation contains one or more Roles
        result = api.organizations().createInvitation(ORG_ID, invitation).execute();
        System.out.println(result.getInvitationUrl());
    } catch (Auth0Exception e) {
        e.printStackTrace();
    }
}

@lbalmaceda lbalmaceda requested a review from a team as a code owner October 4, 2021 17:58
@lbalmaceda lbalmaceda added this to the v1-Next milestone Oct 4, 2021
@lbalmaceda lbalmaceda merged commit 3b935d6 into master Oct 5, 2021
@lbalmaceda lbalmaceda deleted the fix-roles branch October 5, 2021 14:01
@lbalmaceda lbalmaceda modified the milestones: v1-Next, 1.35.0 Oct 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Org invitation call: invalid request with roles
2 participants