From 7f53f1c08a4bc3fe6723b2b5f50e7624e2ccfd7f Mon Sep 17 00:00:00 2001 From: Kunal Dawar Date: Thu, 25 Apr 2024 21:23:56 +0530 Subject: [PATCH] [GH-366] - Add support for enabled_connections field in CreateOrganization --- management/organization.go | 5 + management/organization_test.go | 26 ++ .../TestOrganizationManager_Create.yaml | 304 +++++++++++++++++- 3 files changed, 325 insertions(+), 10 deletions(-) diff --git a/management/organization.go b/management/organization.go index 9b0617df..409fe219 100644 --- a/management/organization.go +++ b/management/organization.go @@ -23,6 +23,11 @@ type Organization struct { // Metadata associated with the organization, in the form of an object with // string values (max 255 chars). Maximum of 10 metadata properties allowed. Metadata *map[string]string `json:"metadata,omitempty"` + + // OrganizationConnections that will be enabled for this organization. + // See POST enabled_connections endpoint for the object format. + // (Max of 10 connections allowed) + OrganizationConnections []*OrganizationConnection `json:"enabled_connections,omitempty"` } // OrganizationBranding holds branding information for an Organization. diff --git a/management/organization_test.go b/management/organization_test.go index 0295b1e9..414dec1c 100644 --- a/management/organization_test.go +++ b/management/organization_test.go @@ -17,12 +17,16 @@ import ( func TestOrganizationManager_Create(t *testing.T) { configureHTTPTestRecordings(t) + orgConn := givenAnOrganizationConnectionWithoutOrgID(t) + orgConn2 := givenAnOrganizationConnectionWithoutOrgID(t) + org := &Organization{ Name: auth0.String(fmt.Sprintf("test-organization%v", rand.Intn(999))), DisplayName: auth0.String("Test Organization"), Branding: &OrganizationBranding{ LogoURL: auth0.String("https://example.com/logo.gif"), }, + OrganizationConnections: []*OrganizationConnection{orgConn, orgConn2}, } err := api.Organization.Create(context.Background(), org) @@ -435,6 +439,28 @@ func givenAnOrganizationConnection(t *testing.T, orgID string) *OrganizationConn return orgConn } +func givenAnOrganizationConnectionWithoutOrgID(t *testing.T) *OrganizationConnection { + client := givenAClient(t) + conn := givenAConnection(t, connectionTestCase{ + connection: Connection{ + Name: auth0.String(fmt.Sprintf("test-conn%v", rand.Intn(999))), + DisplayName: auth0.String(fmt.Sprintf("Test Connection %v", rand.Intn(999))), + Strategy: auth0.String(ConnectionStrategyAD), + EnabledClients: &[]string{ + os.Getenv("AUTH0_CLIENT_ID"), + client.GetClientID(), + }, + }, + }) + orgConn := &OrganizationConnection{ + ConnectionID: conn.ID, + AssignMembershipOnLogin: auth0.Bool(true), + ShowAsButton: auth0.Bool(true), + } + + return orgConn +} + func givenAnOrganizationInvitation(t *testing.T, orgID string) *OrganizationInvitation { t.Helper() diff --git a/test/data/recordings/TestOrganizationManager_Create.yaml b/test/data/recordings/TestOrganizationManager_Create.yaml index 91aeb8a1..077b8a52 100644 --- a/test/data/recordings/TestOrganizationManager_Create.yaml +++ b/test/data/recordings/TestOrganizationManager_Create.yaml @@ -6,21 +6,21 @@ interactions: proto: HTTP/1.1 proto_major: 1 proto_minor: 1 - content_length: 121 + content_length: 1125 transfer_encoding: [] trailer: {} host: go-auth0-dev.eu.auth0.com remote_addr: "" request_uri: "" body: | - {"name":"test-organization20","display_name":"Test Organization","branding":{"logo_url":"https://example.com/logo.gif"}} + {"name":"Test Client (Apr 25 21:20:38.073)","description":"This is just a test client.","jwt_configuration":{"alg":"RS256"},"organization_usage":"allow","client_authentication_methods":{"private_key_jwt":{"credentials":[{"name":"Test Credential (Apr 25 21:20:38.073)","credential_type":"public_key","pem":"-----BEGIN PUBLIC KEY-----\nMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAua6LXMfgDE/tDdkOL1Oe\n3oWUwg1r4dSTg9L7RCcI5hItUzmkVofHtWN0H4CH2lm2ANmaJUsnhzctYowYW2+R\ntHvU9afTmtbdhpy993972hUqZSYLsE3iGziphYkOKVsqq38+VRH3TNg93zSLoRao\nJnTTkMXseVqiyqYRmFN8+gQQoEclHSGPUWQG5XMZ+hhuXeFyo+Yw/qbZWca/6/2I\n3rsca9jXR1alhxhHrXrg8N4Dm3gBgGbmiht6YYYT2Tyl1OqB9+iOI/9D7dfoCF6X\nAWJXRE454cmC8k8oucpjZVpflA+ocKshwPDR6YTLQYbXYiaWxEoaz0QGUErNQBnG\nI+sr9jDY3ua/s6HF6h0qyi/HVZH4wx+m4CtOfJoYTjrGBbaRszzUxhtSN2/MhXDu\n+a35q9/2zcu/3fjkkfVvGUt+NyyiYOKQ9vsJC1g/xxdUWtowjNwjfZE2zcG4usi8\nr38Bp0lmiipAsMLduZM/D5dFXkRdWCBNDfULmmg/4nv2wwjbjQuLemAMh7mmrztW\ni/85WMnjKQZT8NqS43pmgyIzg1gK1neMqdS90YmQ/PvJ36qALxCs245w1JpN9BAL\nJbwxCg/dbmKT7PalfWrksx9hGcJxtGqebldaOpw+5GVIPxxtC1C0gVr9BKeiDS3f\naibASY5pIRiKENmbZELDtucCAwEAAQ==\n-----END PUBLIC KEY-----"}]}}} form: {} headers: Content-Type: - application/json User-Agent: - - Go-Auth0-SDK/latest - url: https://go-auth0-dev.eu.auth0.com/api/v2/organizations + - Go-Auth0/1.5.0 + url: https://go-auth0-dev.eu.auth0.com/api/v2/clients method: POST response: proto: HTTP/2.0 @@ -28,16 +28,300 @@ interactions: proto_minor: 0 transfer_encoding: [] trailer: {} - content_length: 148 + content_length: -1 uncompressed: false - body: '{"name":"test-organization20","display_name":"Test Organization","branding":{"logo_url":"https://example.com/logo.gif"},"id":"org_BURmVtp0ptCAPjbw"}' + body: '{"name":"Test Client (Apr 25 21:20:38.073)","description":"This is just a test client.","client_id":"4kTtC10PpErb6UiXkA0nsRmt20596Kcy","client_secret":"[REDACTED]","is_first_party":true,"is_token_endpoint_ip_header_trusted":false,"oidc_conformant":false,"jwt_configuration":{"secret_encoded":false,"alg":"RS256"},"signing_keys":[{"cert":"[REDACTED]"}],"sso_disabled":false,"grant_types":["authorization_code","implicit","refresh_token","client_credentials"],"custom_login_page_on":true,"refresh_token":{"rotation_type":"non-rotating","expiration_type":"non-expiring","leeway":0,"token_lifetime":2592000,"infinite_token_lifetime":true,"infinite_idle_token_lifetime":true,"idle_token_lifetime":1296000},"organization_usage":"allow","client_authentication_methods":{"private_key_jwt":{"credentials":[{"id":"cred_9eScX1Md8CCXwHkWdnEwVM","name":"Test Credential (Apr 25 21:20:38.073)","kid":"4e7yYf0TKdyTLbVnpq2wLN6mZ8t7eb9UJkMksyHj9iU","credential_type":"public_key","alg":"RS256","created_at":"2024-04-25T15:50:38.977Z","updated_at":"2024-04-25T15:50:38.977Z"}]}}}' headers: Content-Type: - application/json; charset=utf-8 status: 201 Created code: 201 - duration: 136.012208ms + duration: 1.06730875s - id: 1 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 167 + transfer_encoding: [] + trailer: {} + host: go-auth0-dev.eu.auth0.com + remote_addr: "" + request_uri: "" + body: | + {"name":"test-conn153","display_name":"Test Connection 441","strategy":"ad","enabled_clients":["QjlAo2nIDERZYBBZozsv8apykJUBtCq4","4kTtC10PpErb6UiXkA0nsRmt20596Kcy"]} + form: {} + headers: + Content-Type: + - application/json + User-Agent: + - Go-Auth0/1.5.0 + url: https://go-auth0-dev.eu.auth0.com/api/v2/connections + method: POST + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: 422 + uncompressed: false + body: '{"id":"con_6fUiQeazlpjyM00z","options":{"ips":null,"brute_force_protection":true},"strategy":"ad","name":"test-conn153","provisioning_ticket_url":"https://go-auth0-dev.eu.auth0.com.us.auth0.com/p/ad/cKoAR60QK4wW4ezlpjhNKshJFM4YamU7","is_domain_connection":false,"show_as_button":false,"display_name":"Test Connection 441","enabled_clients":["4kTtC10PpErb6UiXkA0nsRmt20596Kcy","QjlAo2nIDERZYBBZozsv8apykJUBtCq4"],"realms":["test-conn153"]}' + headers: + Content-Type: + - application/json; charset=utf-8 + status: 201 Created + code: 201 + duration: 481.124791ms + - id: 2 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 1125 + transfer_encoding: [] + trailer: {} + host: go-auth0-dev.eu.auth0.com + remote_addr: "" + request_uri: "" + body: | + {"name":"Test Client (Apr 25 21:20:39.626)","description":"This is just a test client.","jwt_configuration":{"alg":"RS256"},"organization_usage":"allow","client_authentication_methods":{"private_key_jwt":{"credentials":[{"name":"Test Credential (Apr 25 21:20:39.626)","credential_type":"public_key","pem":"-----BEGIN PUBLIC KEY-----\nMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAua6LXMfgDE/tDdkOL1Oe\n3oWUwg1r4dSTg9L7RCcI5hItUzmkVofHtWN0H4CH2lm2ANmaJUsnhzctYowYW2+R\ntHvU9afTmtbdhpy993972hUqZSYLsE3iGziphYkOKVsqq38+VRH3TNg93zSLoRao\nJnTTkMXseVqiyqYRmFN8+gQQoEclHSGPUWQG5XMZ+hhuXeFyo+Yw/qbZWca/6/2I\n3rsca9jXR1alhxhHrXrg8N4Dm3gBgGbmiht6YYYT2Tyl1OqB9+iOI/9D7dfoCF6X\nAWJXRE454cmC8k8oucpjZVpflA+ocKshwPDR6YTLQYbXYiaWxEoaz0QGUErNQBnG\nI+sr9jDY3ua/s6HF6h0qyi/HVZH4wx+m4CtOfJoYTjrGBbaRszzUxhtSN2/MhXDu\n+a35q9/2zcu/3fjkkfVvGUt+NyyiYOKQ9vsJC1g/xxdUWtowjNwjfZE2zcG4usi8\nr38Bp0lmiipAsMLduZM/D5dFXkRdWCBNDfULmmg/4nv2wwjbjQuLemAMh7mmrztW\ni/85WMnjKQZT8NqS43pmgyIzg1gK1neMqdS90YmQ/PvJ36qALxCs245w1JpN9BAL\nJbwxCg/dbmKT7PalfWrksx9hGcJxtGqebldaOpw+5GVIPxxtC1C0gVr9BKeiDS3f\naibASY5pIRiKENmbZELDtucCAwEAAQ==\n-----END PUBLIC KEY-----"}]}}} + form: {} + headers: + Content-Type: + - application/json + User-Agent: + - Go-Auth0/1.5.0 + url: https://go-auth0-dev.eu.auth0.com/api/v2/clients + method: POST + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: -1 + uncompressed: false + body: '{"name":"Test Client (Apr 25 21:20:39.626)","description":"This is just a test client.","client_id":"GEEKan59VUsQSvCg38tDgPubual5o4t7","client_secret":"[REDACTED]","is_first_party":true,"is_token_endpoint_ip_header_trusted":false,"oidc_conformant":false,"jwt_configuration":{"secret_encoded":false,"alg":"RS256"},"signing_keys":[{"cert":"[REDACTED]"}],"sso_disabled":false,"grant_types":["authorization_code","implicit","refresh_token","client_credentials"],"custom_login_page_on":true,"refresh_token":{"rotation_type":"non-rotating","expiration_type":"non-expiring","leeway":0,"token_lifetime":2592000,"infinite_token_lifetime":true,"infinite_idle_token_lifetime":true,"idle_token_lifetime":1296000},"organization_usage":"allow","client_authentication_methods":{"private_key_jwt":{"credentials":[{"id":"cred_8LStMd6CvbAxQczgqm52Md","name":"Test Credential (Apr 25 21:20:39.626)","kid":"4e7yYf0TKdyTLbVnpq2wLN6mZ8t7eb9UJkMksyHj9iU","credential_type":"public_key","alg":"RS256","created_at":"2024-04-25T15:50:40.039Z","updated_at":"2024-04-25T15:50:40.039Z"}]}}}' + headers: + Content-Type: + - application/json; charset=utf-8 + status: 201 Created + code: 201 + duration: 808.534ms + - id: 3 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 167 + transfer_encoding: [] + trailer: {} + host: go-auth0-dev.eu.auth0.com + remote_addr: "" + request_uri: "" + body: | + {"name":"test-conn958","display_name":"Test Connection 337","strategy":"ad","enabled_clients":["QjlAo2nIDERZYBBZozsv8apykJUBtCq4","GEEKan59VUsQSvCg38tDgPubual5o4t7"]} + form: {} + headers: + Content-Type: + - application/json + User-Agent: + - Go-Auth0/1.5.0 + url: https://go-auth0-dev.eu.auth0.com/api/v2/connections + method: POST + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: 422 + uncompressed: false + body: '{"id":"con_g1TIjToKF1ZWSBQt","options":{"ips":null,"brute_force_protection":true},"strategy":"ad","name":"test-conn958","provisioning_ticket_url":"https://go-auth0-dev.eu.auth0.com.us.auth0.com/p/ad/r6p5WhDRng1MKdwgR4rCWgAtxAXuKaI2","is_domain_connection":false,"show_as_button":false,"display_name":"Test Connection 337","enabled_clients":["GEEKan59VUsQSvCg38tDgPubual5o4t7","QjlAo2nIDERZYBBZozsv8apykJUBtCq4"],"realms":["test-conn958"]}' + headers: + Content-Type: + - application/json; charset=utf-8 + status: 201 Created + code: 201 + duration: 523.868792ms + - id: 4 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 340 + transfer_encoding: [] + trailer: {} + host: go-auth0-dev.eu.auth0.com + remote_addr: "" + request_uri: "" + body: | + {"name":"test-organization110","display_name":"Test Organization","branding":{"logo_url":"https://example.com/logo.gif"},"enabled_connections":[{"connection_id":"con_6fUiQeazlpjyM00z","assign_membership_on_login":true,"show_as_button":true},{"connection_id":"con_g1TIjToKF1ZWSBQt","assign_membership_on_login":true,"show_as_button":true}]} + form: {} + headers: + Content-Type: + - application/json + User-Agent: + - Go-Auth0/1.5.0 + url: https://go-auth0-dev.eu.auth0.com/api/v2/organizations + method: POST + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: 367 + uncompressed: false + body: '{"name":"test-organization110","display_name":"Test Organization","branding":{"logo_url":"https://example.com/logo.gif"},"enabled_connections":[{"connection_id":"con_6fUiQeazlpjyM00z","assign_membership_on_login":true,"show_as_button":true},{"connection_id":"con_g1TIjToKF1ZWSBQt","assign_membership_on_login":true,"show_as_button":true}],"id":"org_kppEAG7SMhxyoPDo"}' + headers: + Content-Type: + - application/json; charset=utf-8 + status: 201 Created + code: 201 + duration: 519.078042ms + - id: 5 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 0 + transfer_encoding: [] + trailer: {} + host: go-auth0-dev.eu.auth0.com + remote_addr: "" + request_uri: "" + body: "" + form: {} + headers: + Content-Type: + - application/json + User-Agent: + - Go-Auth0/1.5.0 + url: https://go-auth0-dev.eu.auth0.com/api/v2/organizations/org_kppEAG7SMhxyoPDo + method: DELETE + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: 0 + uncompressed: false + body: "" + headers: + Content-Type: + - application/json; charset=utf-8 + status: 204 No Content + code: 204 + duration: 376.369708ms + - id: 6 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 0 + transfer_encoding: [] + trailer: {} + host: go-auth0-dev.eu.auth0.com + remote_addr: "" + request_uri: "" + body: "" + form: {} + headers: + Content-Type: + - application/json + User-Agent: + - Go-Auth0/1.5.0 + url: https://go-auth0-dev.eu.auth0.com/api/v2/connections/con_g1TIjToKF1ZWSBQt + method: DELETE + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: 41 + uncompressed: false + body: '{"deleted_at":"2024-04-25T15:50:42.270Z"}' + headers: + Content-Type: + - application/json; charset=utf-8 + status: 202 Accepted + code: 202 + duration: 406.799792ms + - id: 7 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 0 + transfer_encoding: [] + trailer: {} + host: go-auth0-dev.eu.auth0.com + remote_addr: "" + request_uri: "" + body: "" + form: {} + headers: + Content-Type: + - application/json + User-Agent: + - Go-Auth0/1.5.0 + url: https://go-auth0-dev.eu.auth0.com/api/v2/clients/GEEKan59VUsQSvCg38tDgPubual5o4t7 + method: DELETE + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: 0 + uncompressed: false + body: "" + headers: + Content-Type: + - application/json; charset=utf-8 + status: 204 No Content + code: 204 + duration: 372.123458ms + - id: 8 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 0 + transfer_encoding: [] + trailer: {} + host: go-auth0-dev.eu.auth0.com + remote_addr: "" + request_uri: "" + body: "" + form: {} + headers: + Content-Type: + - application/json + User-Agent: + - Go-Auth0/1.5.0 + url: https://go-auth0-dev.eu.auth0.com/api/v2/connections/con_6fUiQeazlpjyM00z + method: DELETE + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: 41 + uncompressed: false + body: '{"deleted_at":"2024-04-25T15:50:42.964Z"}' + headers: + Content-Type: + - application/json; charset=utf-8 + status: 202 Accepted + code: 202 + duration: 330.4075ms + - id: 9 request: proto: HTTP/1.1 proto_major: 1 @@ -54,8 +338,8 @@ interactions: Content-Type: - application/json User-Agent: - - Go-Auth0-SDK/latest - url: https://go-auth0-dev.eu.auth0.com/api/v2/organizations/org_BURmVtp0ptCAPjbw + - Go-Auth0/1.5.0 + url: https://go-auth0-dev.eu.auth0.com/api/v2/clients/4kTtC10PpErb6UiXkA0nsRmt20596Kcy method: DELETE response: proto: HTTP/2.0 @@ -71,4 +355,4 @@ interactions: - application/json; charset=utf-8 status: 204 No Content code: 204 - duration: 126.143334ms + duration: 367.008375ms