Skip to content

Conversation

@bkiran6398
Copy link

@bkiran6398 bkiran6398 commented Jan 26, 2026

This PR introduces comprehensive support for managing organization invitations through the Auth0 CLI. Users can now create, list, show, and delete organization invitations directly from the command line.

🔧 Changes

Key additions:

  • Added auth0 orgs invitations command group with four subcommands: list, create, show, and delete
  • Added command alias invs for shorter command invocation
  • Extended OrganizationAPI interface with four new methods: Invitations(), CreateInvitation(), Invitation(), and DeleteInvitation()
  • Added new display views for rendering invitation data in multiple output formats (table, JSON, CSV)
  • Added required OAuth scopes for organization invitation management: read:organization_invitations, create:organization_invitations, and delete:organization_invitations

Command capabilities:

  • List: Display all invitations for an organization with pagination support
  • Create: Send new organization invitations with customizable parameters (inviter name, invitee email, client ID, connection ID, TTL, roles, and metadata)
  • Show: View detailed information about a specific invitation
  • Delete: Remove one or multiple invitations with interactive picker support

📚 References

#490

🔬 Testing

Automated Tests:

  • Added comprehensive integration tests covering all invitation commands (list, create, show, delete)
  • Added unit tests for invitation picker functionality
  • Tests validate both successful operations and error handling for invalid inputs (missing arguments, invalid IDs)

Integration Test Enhancements:

  • Created helper scripts for test automation:
    • get-org-invitation-id.sh: Extracts invitation IDs from command output for use in subsequent tests
    • delete-app-id.sh: Cleanup script to remove test artifacts after app deletion tests
  • Updated get-app-id.sh script for better compatibility with invitation-related tests
  • Tests include edge cases such as missing required arguments and operations with non-existent resources

Manual Testing:
All commands have been manually tested with:

  • Interactive and non-interactive modes
  • Various output formats (table, JSON, JSON-compact, CSV)
  • Valid and invalid parameters
  • Multiple invitations operations

📝 Checklist

  • All new/changed/fixed functionality is covered by tests (or N/A)
  • I have added documentation for all new/changed functionality (or N/A)

- Implemented the Invitations method in the OrganizationAPI interface to list invitations for an organization.
- Generated corresponding mock methods in organization_mock.go for testing.
- This change enhances the API's functionality by allowing retrieval of organization invitations, aligning with the management API documentation.
- Introduced `invitationsOrganizationCmd` to handle invitations management.
- Added `listInvitationsOrganizationCmd` for listing organization invitations with options for pagination and output formats.
- Implemented `getOrgInvitationsWithSpinner` and `getOrgInvitations` methods for fetching invitations from the API.
- Created `invitationsView` struct for displaying invitation details in a structured format.
…tions

- Introduced a new section for managing invitations within organizations.
- Added a new file `auth0_orgs_invitations.md` detailing the invitation management commands.
- Created `auth0_orgs_invitations_list.md` to document the command for listing invitations.
- Updated existing documentation files to include links to the new invitations section.

This change enhances the usability of the Auth0 CLI by providing clear guidance on managing organization invitations.
@codecov-commenter
Copy link

Codecov Report

❌ Patch coverage is 31.49606% with 87 lines in your changes missing coverage. Please review.
✅ Project coverage is 58.79%. Comparing base (72153d5) to head (e70e74d).
⚠️ Report is 52 commits behind head on main.

Files with missing lines Patch % Lines
internal/cli/organizations.go 42.55% 53 Missing and 1 partial ⚠️
internal/display/invitations.go 0.00% 33 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1424      +/-   ##
==========================================
- Coverage   64.51%   58.79%   -5.72%     
==========================================
  Files         108      118      +10     
  Lines       17959    20535    +2576     
==========================================
+ Hits        11586    12074     +488     
- Misses       5615     7673    +2058     
- Partials      758      788      +30     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

- Implemented CreateInvitation method in OrganizationAPI interface to facilitate creating invitations for organizations.
- Added corresponding mock methods in organization_mock.go for testing purposes.
- This change enhances the API's functionality, allowing users to manage organization invitations more effectively.
- Added `create` command to manage organization invitations, allowing users to create new invitations.
- Introduced flags for inviter name, invitee email, client ID, connection ID, TTL seconds, and metadata.
- Updated `auth0_orgs_invitations.md` to include the new command.
- Created detailed documentation in `auth0_orgs_invitations_create.md` for usage and examples.
- Enhanced `auth0_orgs_invitations_list.md` to reference the new create command.
- Updated `invitations.go` to reflect changes in field names for consistency.
…ality

- Implemented the DeleteInvitation method in the OrganizationAPI interface to allow deletion of invitations.
- Added DeleteInvitation mock methods in organization_mock.go for testing purposes.
- Created a new delete command in organizations.go to handle invitation deletions, including interactive and non-interactive modes.
- Introduced invitationPickerOptions method to facilitate selection of invitations for deletion.
- Added unit tests for invitationPickerOptions to ensure correct behavior under various scenarios.
… options

- Fixed PickMany to validate if the command can prompt for required arguments.
- This prevents making redundant GET api calls to list picker options.
- Removed the unused selectArgument function to streamline the code.
- Implemented the `show` command for displaying organization invitations.
- Added `Invitation` method to the `OrganizationAPI` interface in `organization.go`.
- Created mock methods in `organization_mock.go` for testing the new functionality.
- Updated `invitations.go` to include a new renderer method for showing invitations.
- Introduced aliases for the invitations commands to enhance usability:
- Updated examples in the command documentation to reflect the new aliases.
- This change aims to streamline command usage and improve user experience.
@ramya18101
Copy link
Contributor

@claude

bkiran6398 and others added 7 commits February 6, 2026 15:40
- Implemented new test cases for listing, creating, showing, and deleting organization invitations.
- Added tests to verify behavior with valid and invalid inputs, including edge cases for missing arguments and invalid IDs.
- Created a new script `get-org-invitation-id.sh` to facilitate the retrieval of invitation IDs for testing.
- Updated existing `get-app-id.sh` script to ensure compatibility with the organization-invitation functionality.
- Added new required scopes for managing organization invitations:
  - `read:organization_invitations`
  - `create:organization_invitations`
  - `delete:organization_invitations`

This change is necessary to ensure that the application has the appropriate permissions
to handle organization invitations effectively.
…tion_invitations

- Replaced the previous organization invitation scopes with generic extra scopes for better test coverage.
- Introduced a new script `delete-app-id.sh` to remove the app identifier file created during integration tests.
- This script ensures that the identifier file is deleted only if the app is successfully removed, preventing stale data in subsequent test runs.
- Updated the test case for app deletion to call this cleanup script after the app is deleted.
@bkiran6398 bkiran6398 marked this pull request as ready for review February 6, 2026 14:37
@bkiran6398 bkiran6398 requested a review from a team as a code owner February 6, 2026 14:37
Comment on lines +40 to +43
if !canPrompt(cmd) {
return fmt.Errorf("Missing a required argument: %s", a.GetName())
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't update the existing Pick logic in arguments.go

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The existing Pick function was making API calls to fetch options and then checking whether those could be prompted. This change doesn’t affect the existing logic, but it avoids a redundant API call.

Comment on lines 112 to 119
ShortForm: "c",
Help: "Auth0 client ID. Used to resolve the application's login initiation endpoint.",
IsRequired: true,
}

connectionID = Flag{
Name: "Connection ID",
LongForm: "connection-id",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid confusion, remove shortform for clientID too..
as we didn't include shortform for connectionID

}

func (cli *cli) invitationPickerOptions(ctx context.Context, orgID string) (pickerOptions, error) {
invitations, err := cli.getOrgInvitations(ctx, orgID, 1000)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are we fetching only 1000 invitations..?

Comment on lines 144 to 156
applicationMetadata = Flag{
Name: "App Metadata",
LongForm: "app-metadata",
ShortForm: "a",
Help: "Application metadata for the invited user in key=value format.",
}

userMetadata = Flag{
Name: "User Metadata",
LongForm: "user-metadata",
ShortForm: "u",
Help: "User metadata for the invited user in key=value format.",
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clearly mention in the Help of Metadata logic : formatted as JSON.

Use: "invitations",
Aliases: []string{"invs"},
Short: "Manage invitations of an organization",
Long: "Manage invitations of an organization.",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update Long more descriptive by taking the reference from : https://auth0.com/docs/manage-users/organizations/configure-organizations/invite-members

Args: cobra.MaximumNArgs(2),
Short: "Show an organization invitation",
Long: "Display information about an organization invitation.",
Example: ` auth0 orgs invs show
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't follow args format, Instead create separate flags for -orgId and -invId ..

Short: "Create a new invitation to an organization",
Long: "Create a new invitation to an organization.",
Example: ` auth0 orgs invs create
auth0 orgs invs create <org-id>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parse org-id as a flag and use picker logic on top of it

Comment on lines 1310 to 1311
inputs.OrgID = args[0]
args = args[1:]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use orgId as a flag

return err
}

sortInvitations(invitations)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we manually sorting, we have a field supporting --sort

},
}

organizationNumber.Help = "Number of organization invitations to retrieve. Minimum 1, maximum 1000."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we limiting the range to 1 and 1000.
and why are we defining help Here..?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • 1000 limit is used in many other list implementations like users, orgs, apis, apps.
  • organizationNumber is used by multiple sub-commands with relevant custom help message.

…in the command

- Updated example commands in the documentation to reflect the removal of the short form.
- Ensured consistency in the command usage by using the long form for `--client-id`.
…ickerOptions

- Changed the method of fetching organization invitations from a local function to a direct API call.
- Updated the variable names for clarity, changing `invitations` to `orgInvitations` and `value` to `id`.
- Changed AppMetadata and UserMetadata from map[string]string to string to accept JSON formatted input.
- Updated help text for flags to clarify expected data format.
- Adjusted JSON unmarshalling logic in createInvitationOrganizationCmd to handle new string format.
- Ensured compatibility with existing functionality while improving data handling for user and app metadata.
- Updated the long descriptions for commands related to organization invitations to provide clearer guidance on usage.
- Added interactive and non-interactive usage instructions for the following commands:
  - `auth0 orgs invs create`
  - `auth0 orgs invs list`
  - `auth0 orgs invs show`
- Improved user understanding of how to manage invitations effectively.
- Changed the variable name from `ID` to `OrgID` for clarity in `listInvitationsOrganizationCmd`.
- Removed the `getOrgInvitationsWithSpinner` function as it was redundant.
- Added sorting flag to invitation list API req.
- Enhanced the logic in `getOrgInvitations` to determine if there are more
  invitations based on whether the current page is empty, using a new helper
  function `isEmptyInvitationList`.
…rg and inv id as flags

- Added new flags for Organization ID and Invitation ID to improve command usability.
- Updated command arguments to use flags instead of positional arguments for better clarity.
- Revised command descriptions and examples to reflect the new flag usage.
- Ensured that the commands now support interactive and non-interactive modes consistently.
- Removed the CreatedAt field from the invitationsView struct and its related methods.
- Updated AsTableHeader, AsTableRow, and KeyValues methods to reflect this change.
- This simplifies the invitation display by focusing on relevant fields, improving clarity for users.
bkiran6398 and others added 7 commits February 10, 2026 16:23
- Implemented unit tests for the invitationsView struct to ensure proper functionality.
- Added tests for AsTableHeader, AsTableRow, KeyValues, Object, and makeInvitationsView methods.
- These tests validate the expected output for various invitation attributes, enhancing code reliability and maintainability.
…methods in the `Flag` struct to handle multiple flag selections.

- Updated `askMultiSelect` to accept an `isUpdate` parameter for better control over input validation.
- Modified `PickMany` in the `Argument` struct to support the new multi-select behavior.
…s flag.

- Enhanced the delete command to accept multiple invitation IDs in flag for deletion.
- Improved command examples for clarity on usage.
…on-id flags

- Updated test cases for listing, creating, showing, and deleting organization invitations to reflect this change.
- Changed error messages for missing Org ID and Invitation ID to be more descriptive.
- Updated the command for creating an invitation to explicitly include the `--org-id` flag for clarity.
- Adjusted the command for listing invitations to use the `--org-id` flag instead of positional arguments.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants