Skip to content
This repository has been archived by the owner on Feb 16, 2022. It is now read-only.

Implement Organizations Management API #216

Merged
merged 8 commits into from
Jun 17, 2021
Merged

Implement Organizations Management API #216

merged 8 commits into from
Jun 17, 2021

Conversation

sethyates
Copy link
Contributor

Proposed Changes

  • Implements Organizations Management API

Acceptance Test Output

$ go test ./... -v -run TestOrganization

=== RUN   TestOrganization
--- FAIL: TestOrganization (12.71s)
=== RUN   TestOrganization/Create
    organization_test.go:98: {
          "id": "org_862pZwOTjQgrkHOM",
          "name": "testorganization20210514011508",
          "display_name": "Test Organization",
          "branding": {
            "logo_url": "https://example.com/logo.gif"
          }
        }
    --- PASS: TestOrganization/Create (0.33s)
=== RUN   TestOrganization/List
    organization_test.go:108: {
          "start": 0,
          "limit": 50,
          "length": 0,
          "total": 1,
          "organizations": [
            {
              "id": "org_862pZwOTjQgrkHOM",
              "name": "testorganization20210514011508",
              "display_name": "Test Organization",
              "branding": {
                "logo_url": "https://example.com/logo.gif"
              }
            }
          ]
        }
    --- PASS: TestOrganization/List (0.20s)
=== RUN   TestOrganization/GetByID
    organization_test.go:116: {
          "id": "org_862pZwOTjQgrkHOM",
          "name": "testorganization20210514011508",
          "display_name": "Test Organization",
          "branding": {
            "logo_url": "https://example.com/logo.gif"
          }
        }
    --- PASS: TestOrganization/GetByID (0.20s)
=== RUN   TestOrganization/Update
    organization_test.go:124: {
          "id": "org_862pZwOTjQgrkHOM",
          "name": "testorganization20210514011508",
          "display_name": "Test Organization",
          "branding": {
            "logo_url": "https://example.com/logo.gif"
          }
        }
    --- PASS: TestOrganization/Update (0.20s)
=== RUN   TestOrganization/GetByName
    organization_test.go:132: {
          "id": "org_862pZwOTjQgrkHOM",
          "name": "testorganization20210514011508",
          "display_name": "Test Organization",
          "branding": {
            "logo_url": "https://example.com/logo.gif"
          }
        }
    --- PASS: TestOrganization/GetByName (0.17s)
=== RUN   TestOrganization/Connections
    organization_test.go:141: {
          "start": 0,
          "limit": 0,
          "length": 0,
          "total": 0,
          "enabled_connections": []
        }
    --- PASS: TestOrganization/Connections (0.19s)
=== RUN   TestOrganization/AddConnection
    organization_test.go:149: {
          "connection_id": "con_wxSG1iaQpixlsYiC",
          "assign_membership_on_login": true,
          "connection": {
            "name": "testconn20210514011507",
            "strategy": "auth0"
          }
        }
    --- PASS: TestOrganization/AddConnection (0.20s)
=== RUN   TestOrganization/GetConnection
    organization_test.go:157: {
          "connection_id": "con_wxSG1iaQpixlsYiC",
          "assign_membership_on_login": true,
          "connection": {
            "name": "testconn20210514011507",
            "strategy": "auth0"
          }
        }
    --- PASS: TestOrganization/GetConnection (0.18s)
=== RUN   TestOrganization/UpdateConnection
    organization_test.go:165: {
          "connection_id": "con_wxSG1iaQpixlsYiC",
          "assign_membership_on_login": true,
          "connection": {
            "name": "testconn20210514011507",
            "strategy": "auth0"
          }
        }
    --- PASS: TestOrganization/UpdateConnection (0.21s)
=== RUN   TestOrganization/Invitations
    organization_test.go:174: {
          "start": 0,
          "limit": 0,
          "length": 0,
          "total": 0,
          "invitations": []
        }
    --- PASS: TestOrganization/Invitations (0.20s)
=== RUN   TestOrganization/CreateInvitation
    organization_test.go:180: 400 Bad Request: The specified client_id (V0xxeyals4SQwfx7b1E1yJ1yb8vMQo4m) does not allow organizations
    organization_test.go:182: {
          "inviter": {
            "name": "Test Inviter"
          },
          "invitee": {
            "email": "test@example.com"
          },
          "client_id": "V0xxeyals4SQwfx7b1E1yJ1yb8vMQo4m"
        }
    --- FAIL: TestOrganization/CreateInvitation (0.17s)

=== RUN   TestOrganization/GetInvitation
    organization_test.go:189: 404 Not Found: Not Found
    organization_test.go:191: null
    --- FAIL: TestOrganization/GetInvitation (0.19s)

=== RUN   TestOrganization/Members
    organization_test.go:200: {
          "start": 0,
          "limit": 50,
          "length": 0,
          "total": 0,
          "members": []
        }
    --- PASS: TestOrganization/Members (0.17s)
=== RUN   TestOrganization/AddMembers
    --- PASS: TestOrganization/AddMembers (0.20s)
=== RUN   TestOrganization/MemberRoles
    organization_test.go:216: {
          "start": 0,
          "limit": 50,
          "length": 0,
          "total": 0,
          "roles": []
        }
    --- PASS: TestOrganization/MemberRoles (0.19s)
=== RUN   TestOrganization/AssignMemberRoles
    --- PASS: TestOrganization/AssignMemberRoles (0.49s)
=== RUN   TestOrganization/DeleteMemberRoles
    --- PASS: TestOrganization/DeleteMemberRoles (6.35s)
=== RUN   TestOrganization/DeleteMember
    --- PASS: TestOrganization/DeleteMember (0.19s)
=== RUN   TestOrganization/DeleteConnection
    organization_test.go:246: {
          "connection_id": "con_wxSG1iaQpixlsYiC",
          "assign_membership_on_login": true,
          "connection": {
            "name": "testconn20210514011507",
            "strategy": "auth0"
          }
        }
    --- PASS: TestOrganization/DeleteConnection (0.16s)
=== RUN   TestOrganization/DeleteInvitation
    organization_test.go:252: 404 Not Found: Not Found
    organization_test.go:254: {
          "inviter": {
            "name": "Test Inviter"
          },
          "invitee": {
            "email": "test@example.com"
          },
          "client_id": "V0xxeyals4SQwfx7b1E1yJ1yb8vMQo4m"
        }
    --- FAIL: TestOrganization/DeleteInvitation (0.16s)

=== RUN   TestOrganization/Delete
    --- PASS: TestOrganization/Delete (0.22s)

FAIL

Process finished with the exit code 1

Note the failure is related to Organizations enabled on the client I am using. Any help on how to enable this would be appreciated (might be related to entitlements on my dev tenant).

Community Note

  • Please vote on this pull request by adding a 👍 reaction to the original pull request comment to help the community and maintainers prioritize this request
  • Please do not leave "+1" comments, they generate extra noise for pull request followers and do not help prioritize the request

@yvovandoorn
Copy link
Contributor

Hey @sethyates. Thank you for this amazing contribution.

Here (https://gist.github.com/yvovandoorn/ec3fad004a25501123327eb4a81e2e43) is a Postman collection to indicate the overall changes made to other API endpoints, including the client endpoint that you're getting an error on.

Perhaps this can be of use to complete the remaining updates.

@sethyates
Copy link
Contributor Author

@yvovandoorn ok I've fixed the unit tests by creating a custom Client with the right configurations. Along the way, I had to update Client to include OrganizationUsage and OrganizationRequireBehavior. Here are the passing tests:

=== RUN   TestOrganization
--- PASS: TestOrganization (14.23s)
=== RUN   TestOrganization/Create
    organization_test.go:117: {
          "id": "org_jzrkykRsAoYCkmqp",
          "name": "testorganization20210615015942",
          "display_name": "Test Organization",
          "branding": {
            "logo_url": "https://example.com/logo.gif"
          }
        }
    --- PASS: TestOrganization/Create (0.38s)
=== RUN   TestOrganization/List
    organization_test.go:127: {
          "start": 0,
          "limit": 50,
          "length": 0,
          "total": 4,
          "organizations": [
            {
              "id": "org_QSoDrqYyr2g2ERE4",
              "name": "sethtest",
              "display_name": "Seth Test",
              "metadata": {
                "entitlements": "a b c"
              }
            },
            {
              "id": "org_580uE3N6dsY5d326",
              "name": "sstest",
              "display_name": "Suejung's test"
            },
            {
              "id": "org_cPHKyp8rAtWFFTqr",
              "name": "sstest2",
              "display_name": "Suejung's second test"
            },
            {
              "id": "org_jzrkykRsAoYCkmqp",
              "name": "testorganization20210615015942",
              "display_name": "Test Organization",
              "branding": {
                "logo_url": "https://example.com/logo.gif"
              }
            }
          ]
        }
    --- PASS: TestOrganization/List (0.47s)
=== RUN   TestOrganization/GetByID
    organization_test.go:135: {
          "id": "org_jzrkykRsAoYCkmqp",
          "name": "testorganization20210615015942",
          "display_name": "Test Organization",
          "branding": {
            "logo_url": "https://example.com/logo.gif"
          }
        }
    --- PASS: TestOrganization/GetByID (0.42s)
=== RUN   TestOrganization/Update
    organization_test.go:143: {
          "id": "org_jzrkykRsAoYCkmqp",
          "name": "testorganization20210615015942",
          "display_name": "Test Organization",
          "branding": {
            "logo_url": "https://example.com/logo.gif"
          }
        }
    --- PASS: TestOrganization/Update (0.38s)
=== RUN   TestOrganization/GetByName
    organization_test.go:151: {
          "id": "org_jzrkykRsAoYCkmqp",
          "name": "testorganization20210615015942",
          "display_name": "Test Organization",
          "branding": {
            "logo_url": "https://example.com/logo.gif"
          }
        }
    --- PASS: TestOrganization/GetByName (0.38s)
=== RUN   TestOrganization/Connections
    organization_test.go:160: {
          "start": 0,
          "limit": 0,
          "length": 0,
          "total": 0,
          "enabled_connections": []
        }
    --- PASS: TestOrganization/Connections (0.36s)
=== RUN   TestOrganization/AddConnection
    organization_test.go:168: {
          "connection_id": "con_DSTHgMmKlXLr0lsF",
          "assign_membership_on_login": true,
          "connection": {
            "name": "testconn20210615015941",
            "strategy": "auth0"
          }
        }
    --- PASS: TestOrganization/AddConnection (0.48s)
=== RUN   TestOrganization/GetConnection
    organization_test.go:176: {
          "connection_id": "con_DSTHgMmKlXLr0lsF",
          "assign_membership_on_login": true,
          "connection": {
            "name": "testconn20210615015941",
            "strategy": "auth0"
          }
        }
    --- PASS: TestOrganization/GetConnection (0.41s)
=== RUN   TestOrganization/UpdateConnection
    organization_test.go:184: {
          "connection_id": "con_DSTHgMmKlXLr0lsF",
          "assign_membership_on_login": true,
          "connection": {
            "name": "testconn20210615015941",
            "strategy": "auth0"
          }
        }
    --- PASS: TestOrganization/UpdateConnection (0.40s)
=== RUN   TestOrganization/Invitations
    organization_test.go:193: {
          "start": 0,
          "limit": 0,
          "length": 0,
          "total": 0,
          "invitations": []
        }
    --- PASS: TestOrganization/Invitations (0.43s)
=== RUN   TestOrganization/CreateInvitation
    organization_test.go:201: {
          "id": "uinv_W2oo0ApWWcmFi75O",
          "organization_id": "org_jzrkykRsAoYCkmqp",
          "inviter": {
            "name": "Test Inviter"
          },
          "invitee": {
            "email": "test@example.com"
          },
          "invitation_url": "https://dev.ketch.com/auth/signin?invitation=Hw1yZe6jd40NHpm8BCiDtSi9cFxjd39J\u0026organization=org_jzrkykRsAoYCkmqp\u0026organization_name=testorganization20210615015942",
          "created_at": "2021-06-15T08:59:47.112Z",
          "expires_at": "2021-06-22T08:59:47.112Z",
          "client_id": "QblSqtyLuzRH926lqX7UKBPdmmnDlXOR",
          "ticket_id": "Hw1yZe6jd40NHpm8BCiDtSi9cFxjd39J"
        }
    --- PASS: TestOrganization/CreateInvitation (0.61s)
=== RUN   TestOrganization/GetInvitation
    organization_test.go:210: {
          "id": "uinv_W2oo0ApWWcmFi75O",
          "organization_id": "org_jzrkykRsAoYCkmqp",
          "inviter": {
            "name": "Test Inviter"
          },
          "invitee": {
            "email": "test@example.com"
          },
          "invitation_url": "https://dev.ketch.com/auth/signin?invitation=Hw1yZe6jd40NHpm8BCiDtSi9cFxjd39J\u0026organization=org_jzrkykRsAoYCkmqp\u0026organization_name=testorganization20210615015942",
          "created_at": "2021-06-15T08:59:47.112Z",
          "expires_at": "2021-06-22T08:59:47.112Z",
          "client_id": "QblSqtyLuzRH926lqX7UKBPdmmnDlXOR",
          "ticket_id": "Hw1yZe6jd40NHpm8BCiDtSi9cFxjd39J"
        }
    --- PASS: TestOrganization/GetInvitation (0.62s)
=== RUN   TestOrganization/Members
    organization_test.go:219: {
          "start": 0,
          "limit": 50,
          "length": 0,
          "total": 0,
          "members": []
        }
    --- PASS: TestOrganization/Members (0.41s)
=== RUN   TestOrganization/AddMembers
    --- PASS: TestOrganization/AddMembers (0.41s)
=== RUN   TestOrganization/MemberRoles
    organization_test.go:235: {
          "start": 0,
          "limit": 50,
          "length": 0,
          "total": 0,
          "roles": []
        }
    --- PASS: TestOrganization/MemberRoles (0.38s)
=== RUN   TestOrganization/AssignMemberRoles
    --- PASS: TestOrganization/AssignMemberRoles (0.44s)
=== RUN   TestOrganization/DeleteMemberRoles
    --- PASS: TestOrganization/DeleteMemberRoles (0.37s)
=== RUN   TestOrganization/DeleteMember
    --- PASS: TestOrganization/DeleteMember (0.14s)
=== RUN   TestOrganization/DeleteConnection
    organization_test.go:265: {
          "connection_id": "con_DSTHgMmKlXLr0lsF",
          "assign_membership_on_login": true,
          "connection": {
            "name": "testconn20210615015941",
            "strategy": "auth0"
          }
        }
    --- PASS: TestOrganization/DeleteConnection (0.51s)
=== RUN   TestOrganization/DeleteInvitation
    organization_test.go:273: {
          "id": "uinv_W2oo0ApWWcmFi75O",
          "organization_id": "org_jzrkykRsAoYCkmqp",
          "inviter": {
            "name": "Test Inviter"
          },
          "invitee": {
            "email": "test@example.com"
          },
          "invitation_url": "https://dev.ketch.com/auth/signin?invitation=Hw1yZe6jd40NHpm8BCiDtSi9cFxjd39J\u0026organization=org_jzrkykRsAoYCkmqp\u0026organization_name=testorganization20210615015942",
          "created_at": "2021-06-15T08:59:47.112Z",
          "expires_at": "2021-06-22T08:59:47.112Z",
          "client_id": "QblSqtyLuzRH926lqX7UKBPdmmnDlXOR",
          "ticket_id": "Hw1yZe6jd40NHpm8BCiDtSi9cFxjd39J"
        }
    --- PASS: TestOrganization/DeleteInvitation (0.62s)
=== RUN   TestOrganization/Delete
    --- PASS: TestOrganization/Delete (0.61s)
PASS

Process finished with the exit code 0

@sethyates
Copy link
Contributor Author

What are the next steps to get this GA'd and released? We are currently using from my branch but would obviously prefer to switch to the base repo.

@yvovandoorn
Copy link
Contributor

yvovandoorn commented Jun 17, 2021

Hi @sethyates. I am making time today to see if I can merge it.

@yvovandoorn
Copy link
Contributor

Hey @sethyates!

Two updates needed.

  1. Could you also update management/user and add something like:
// List user's organizations
//
// See: https://auth0.com/docs/api/management/v2#!/Users/get_organizations
func (m *UserManager) Organizations(id string, opts ...RequestOption) (p *OrganizationList, err error) {
	err = m.Request("GET", m.URI("users", id, "organizations"), &p, applyListDefaults(opts))
	return
}

  1. Your last commit (79721f8) made the management.gen.go out of date, so can you re-run go generate ./...

Once those two changes are made, I'll merge!

@sethyates
Copy link
Contributor Author

@yvovandoorn done

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants