question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Org invitation call: invalid request with roles

See original GitHub issue

Describe the problem you’d like to have solved

When attempting invitations to users for an org with

organizations().createInvitation(orgId, invitation)

the call is failing if we add roles to invitation object as below

    List<String> roles = Arrays.asList("some role");
    invitation.setRoles(new Roles(roles));

exception snippet

com.auth0.exception.APIException: Request failed with status code 400: Payload validation error: 'Expected type array but found type object' on property roles (List of roles IDs to associated with the user).
   at com.auth0.net.ExtendedBaseRequest.createResponseException(ExtendedBaseRequest.java:131) ~[auth0-1.34.0.jar:1.34.0]
   at com.auth0.net.ExtendedBaseRequest.parseResponse(ExtendedBaseRequest.java:66) ~[auth0-1.34.0.jar:1.34.0]
   at com.auth0.net.BaseRequest.execute(BaseRequest.java:35) ~[auth0-1.34.0.jar:1.34.0]

It seems SDK is expecting Roles object here which inturn has List<roles> so the resulting json is turning out to be something like:

{
  "inviter" : {
    "name" : "xxxx"
  },
  "invitee" : {
    "email" : "xx@ss.com"
  },
  "client_id" : "<<client-id>>",
  "connection_id" : "<<con-id>>",
  "send_invitation_email" : true,
  "roles" : {
    "roles" : [ "rol_7NdVtrUWWwpcYZz8", "rol_7NdVtrUWWwpcYZz8" ]
  }
}

whereas organization invites post request https://auth0.com/docs/api/management/v2#!/Organizations/post_invitations is expecting roles to be a list

{
  "inviter": {
    "name": "Jane Doe"
  },
  "invitee": {
    "email": "john.doe@gmail.com"
  },
  "client_id": "AaiyAPdpYdesoKnqjj8HJqRn4T5titww",
  "connection_id": "con_0000000000000001",
  "app_metadata": {},
  "user_metadata": {},
  "ttl_sec": 0,
  "roles": [
    "rol_0000000000000001",
    "rol_0000000000000002"
  ],
  "send_invitation_email": true
}

Here is a snippet of how I am using SDK

    Inviter inviter = new Inviter(inviterAddress);
    Invitee invitee = new Invitee(userEmail);
    Invitation invitation = new Invitation(inviter, invitee, appClientId);
    invitation.setSendInvitationEmail(true);
    List<String> roles = Arrays.asList(roleId);
    Roles roles = new Roles(rolesList);
    invitation.setRoles(roles);
    invitation.setConnectionId(getConnectionId());
    return executeWithRetry(tokenManager.getMgmt().organizations()
        .createInvitation(orgId, invitation)).getId();

Describe the ideal solution

invitation.setRoles should accept List of Roles to be consistent with request pattern

Alternatives and current work-arounds

Please suggest if there are any alternatives or correct me if I am not invoking SDK properly

Additional information, if any

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
lbalmacedacommented, Oct 4, 2021

Thanks for reporting this. I think a good solution would be to remove the class Roles and use a List<String> instead, so the JSON serialization gets fixed. While that would be a breaking change, it’s to fix something that is not working today. I’ll explore if there are other options, maybe using a Jackson annotation somewhere to change the de/serialization strategy. cc @jimmyjames

0reactions
lbalmacedacommented, Oct 14, 2021

A new release is likely to go out this week. Thanks! cc @jimmyjames

Read more comments on GitHub >

github_iconTop Results From Across the Web

Send Organization Membership Invitations - Auth0
One or more of the specified roles do not exist: role1, role2'. The request payload is not valid. 400, invalid_body, Invalid request body....
Read more >
Applying IAM policy failed with "Request contains an invalid ...
The user has not accepted the invitation to be an owner of the project/org/account. Once I removed the offending users, the Terraform resource ......
Read more >
EnableAWSServiceAccess - AWS Organizations
INVALID_ROLE_NAME: You provided a role name that isn't valid. A role name can't begin with the reserved prefix AWSServiceRoleFor .
Read more >
Create invitation - Microsoft Graph v1.0
Use this API to create a new invitation. Invitation adds an external user to the organization.
Read more >
RFC 3261: SIP: Session Initiation Protocol
SIP makes use of elements called proxy servers to help route requests to the ... A caller retains this role from the time...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found