Skip to content

Commit

Permalink
Minor updates and added new test recording
Browse files Browse the repository at this point in the history
  • Loading branch information
duedares-rvj committed Aug 16, 2024
1 parent e6b4371 commit 5010e9f
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 65 deletions.
60 changes: 50 additions & 10 deletions management/self_service_profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,86 @@ package management

import (
"context"
"encoding/json"
"time"
)

// SelfServiceProfile allows to configure SSO so that
// customers can independently set up
// SSO and sign in to your application.
type SelfServiceProfile struct {
ID *string `json:"id,omitempty"`
ID *string `json:"id,omitempty"`

// List of attributes to be mapped that
// will be shown to the user during the SS-SSO flow.
UserAttributes []*UserAttributes `json:"user_attributes,omitempty"`
CreatedAt *time.Time `json:"created_at,omitempty"`
UpdatedAt *time.Time `json:"updated_at,omitempty"`
Branding *Branding `json:"branding,omitempty"`

// Branding scheme for the profile.
Branding *Branding `json:"branding,omitempty"`
}

// UserAttributes is used to determine optional attributes.
type UserAttributes struct {
Name *string `json:"name,omitempty"`
Description *string `json:"description,omitempty"`
IsOptional *bool `json:"is_optional,omitempty"`
// Identifier of this attribute.
Name *string `json:"name"`

// Description of this attribute.
Description *string `json:"description"`

// Determines if this attribute is required.
IsOptional *bool `json:"is_optional"`
}

// SSOTicket is used to created self service ticket for a set of clients and organizations.
// SSOTicket is used to created self-service ticket for a set of clients and organizations.
type SSOTicket struct {
ConnectionID *string `json:"connection_id,omitempty"`
ConnectionConfig *ConnectionConfig `json:"connection_config,omitempty"`
EnabledClients []*string `json:"enabled_clients,omitempty"`
// If provided, this will allow editing of the
// provided connection during the SSO Flow.
ConnectionID *string `json:"connection_id,omitempty"`

// If provided, this will create a new connection
// for the SSO flow with the given configuration.
ConnectionConfig *ConnectionConfig `json:"connection_config,omitempty"`

// List of client_ids that the
// connection will be enabled for.
EnabledClients []*string `json:"enabled_clients,omitempty"`

// List of organizations that the
// connection will be enabled for.
EnabledOrganizations []*EnabledOrganizations `json:"enabled_organizations,omitempty"`
Ticket *string `json:"ticket,omitempty"`

// The ticket that is generated.
Ticket *string `json:"ticket,omitempty"`
}

// ConnectionConfig sets the configuration for SSOTicket.
type ConnectionConfig struct {
// The name of the connection that will be
// created as a part of the SSO flow.
Name string `json:"name,omitempty"`
}

// EnabledOrganizations is the list of Organizations associated with the SSO Ticket.
type EnabledOrganizations struct {
// Organization identifier.
OrganizationID string `json:"organization_id,omitempty"`
}

// MarshalJSON implements the json.Marshaller interface.
func (ssp *SelfServiceProfile) MarshalJSON() ([]byte, error) {
type SelfServiceProfileSubset struct {
UserAttributes []*UserAttributes `json:"user_attributes,omitempty"`
Branding *Branding `json:"branding,omitempty"`
}

return json.Marshal(&SelfServiceProfileSubset{
UserAttributes: ssp.UserAttributes,
Branding: ssp.Branding,
})
}

// SelfServiceProfileManager manages Auth0 Self Service Profile resources.
type SelfServiceProfileManager manager

Expand Down
10 changes: 5 additions & 5 deletions management/self_service_profiles_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func TestSelfServiceProfileManager_Create(t *testing.T) {

ssops, err := api.SelfServiceProfile.List(context.Background())
assert.NoError(t, err)
assert.Equal(t, 1, len(ssops))
assert.Greater(t, len(ssops), 0)
assert.Equal(t, ssops[0].UserAttributes[0].GetName(), ssop.UserAttributes[0].GetName())
assert.Equal(t, ssops[0].UserAttributes[0].GetDescription(), ssop.UserAttributes[0].GetDescription())
assert.Equal(t, ssops[0].UserAttributes[0].GetIsOptional(), ssop.UserAttributes[0].GetIsOptional())
Expand All @@ -49,16 +49,16 @@ func TestSelfServiceProfileManager_List(t *testing.T) {
ssop := givenASelfServiceProfile(t)
ssopList, err := api.SelfServiceProfile.List(context.Background())
assert.NoError(t, err)
assert.Equal(t, 1, len(ssopList))
assert.Equal(t, ssop.GetBranding().GetColors().GetPrimary(), ssopList[0].GetBranding().GetColors().GetPrimary())
assert.Greater(t, len(ssopList), 0)
assert.Equal(t, ssopList[0].GetBranding().GetColors().GetPrimary(), ssop.GetBranding().GetColors().GetPrimary())
}

func TestSelfServiceProfileManager_Read(t *testing.T) {
configureHTTPTestRecordings(t)
ssop := givenASelfServiceProfile(t)
ssop, err := api.SelfServiceProfile.Read(context.Background(), ssop.GetID())
ssopRetrieved, err := api.SelfServiceProfile.Read(context.Background(), ssop.GetID())
assert.NoError(t, err)
assert.Equal(t, "some-name-here", ssop.UserAttributes[0].GetName())
assert.Equal(t, ssopRetrieved.UserAttributes[0].GetName(), ssop.UserAttributes[0].GetName())
}

func TestSelfServiceProfileManager_Update(t *testing.T) {
Expand Down
12 changes: 6 additions & 6 deletions test/data/recordings/TestSelfServiceProfileManager_Create.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ interactions:
trailer: {}
content_length: 299
uncompressed: false
body: '{"id":"ssp_4miutJe7PRjA7vqZ4y2j9g","user_attributes":[{"name":"some-name-here","description":"some-description","is_optional":true}],"created_at":"2024-08-12T05:42:28.951Z","updated_at":"2024-08-12T05:42:28.951Z","branding":{"logo_url":"https://example.com/logo.png","colors":{"primary":"#334455"}}}'
body: '{"id":"ssp_ggDf3qSai4e9zYrXdQ7aJL","user_attributes":[{"name":"some-name-here","description":"some-description","is_optional":true}],"created_at":"2024-08-16T04:47:24.788Z","updated_at":"2024-08-16T04:47:24.788Z","branding":{"logo_url":"https://example.com/logo.png","colors":{"primary":"#334455"}}}'
headers:
Content-Type:
- application/json; charset=utf-8
status: 201 Created
code: 201
duration: 837.272125ms
duration: 968.444541ms
- id: 1
request:
proto: HTTP/1.1
Expand Down Expand Up @@ -65,13 +65,13 @@ interactions:
trailer: {}
content_length: -1
uncompressed: true
body: '[{"id":"ssp_4miutJe7PRjA7vqZ4y2j9g","user_attributes":[{"name":"some-name-here","description":"some-description","is_optional":true}],"created_at":"2024-08-12T05:42:28.951Z","updated_at":"2024-08-12T05:42:28.951Z","branding":{"logo_url":"https://example.com/logo.png","colors":{"primary":"#334455"}}}]'
body: '[{"id":"ssp_ggDf3qSai4e9zYrXdQ7aJL","user_attributes":[{"name":"some-name-here","description":"some-description","is_optional":true}],"created_at":"2024-08-16T04:47:24.788Z","updated_at":"2024-08-16T04:47:24.788Z","branding":{"logo_url":"https://example.com/logo.png","colors":{"primary":"#334455"}}}]'
headers:
Content-Type:
- application/json; charset=utf-8
status: 200 OK
code: 200
duration: 434.325875ms
duration: 484.845333ms
- id: 2
request:
proto: HTTP/1.1
Expand All @@ -90,7 +90,7 @@ interactions:
- application/json
User-Agent:
- Go-Auth0/1.8.0
url: https://go-auth0-dev.eu.auth0.com/api/v2/self-service-profiles/ssp_4miutJe7PRjA7vqZ4y2j9g
url: https://go-auth0-dev.eu.auth0.com/api/v2/self-service-profiles/ssp_ggDf3qSai4e9zYrXdQ7aJL
method: DELETE
response:
proto: HTTP/2.0
Expand All @@ -106,4 +106,4 @@ interactions:
- application/json; charset=utf-8
status: 204 No Content
code: 204
duration: 331.140958ms
duration: 401.3665ms
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ interactions:
trailer: {}
content_length: 299
uncompressed: false
body: '{"id":"ssp_bmXiN4rAsd8U3mq2KwFBj6","user_attributes":[{"name":"some-name-here","description":"some-description","is_optional":true}],"created_at":"2024-08-12T05:42:34.257Z","updated_at":"2024-08-12T05:42:34.257Z","branding":{"logo_url":"https://example.com/logo.png","colors":{"primary":"#334455"}}}'
body: '{"id":"ssp_hLuKqzSQiVrFAMNTJm1BL9","user_attributes":[{"name":"some-name-here","description":"some-description","is_optional":true}],"created_at":"2024-08-16T04:47:30.179Z","updated_at":"2024-08-16T04:47:30.179Z","branding":{"logo_url":"https://example.com/logo.png","colors":{"primary":"#334455"}}}'
headers:
Content-Type:
- application/json; charset=utf-8
status: 201 Created
code: 201
duration: 353.909541ms
duration: 345.476959ms
- id: 1
request:
proto: HTTP/1.1
Expand All @@ -49,7 +49,7 @@ interactions:
remote_addr: ""
request_uri: ""
body: |
{"name":"Test Client (Aug 12 11:12:34.435)","description":"This is just a test client.","jwt_configuration":{"alg":"RS256"},"organization_usage":"allow","client_authentication_methods":{"private_key_jwt":{"credentials":[{"name":"Test Credential (Aug 12 11:12:34.435)","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-----"}]}}}
{"name":"Test Client (Aug 16 10:17:30.194)","description":"This is just a test client.","jwt_configuration":{"alg":"RS256"},"organization_usage":"allow","client_authentication_methods":{"private_key_jwt":{"credentials":[{"name":"Test Credential (Aug 16 10:17:30.194)","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:
Expand All @@ -66,13 +66,13 @@ interactions:
trailer: {}
content_length: -1
uncompressed: false
body: '{"name":"Test Client (Aug 12 11:12:34.435)","description":"This is just a test client.","client_id":"BOIL8nAokMxm00xXxxyB4SY3eTDUoO9e","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_iag6eR2sq6rJNcgxpzoAYo","name":"Test Credential (Aug 12 11:12:34.435)","kid":"4e7yYf0TKdyTLbVnpq2wLN6mZ8t7eb9UJkMksyHj9iU","credential_type":"public_key","alg":"RS256","created_at":"2024-08-12T05:42:34.804Z","updated_at":"2024-08-12T05:42:34.804Z"}]}}}'
body: '{"name":"Test Client (Aug 16 10:17:30.194)","description":"This is just a test client.","client_id":"9ZYEVW30TbIdxb5hFkBzQva2webZ19FK","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_5TXbg7M5JLwaFysopHuH88","name":"Test Credential (Aug 16 10:17:30.194)","kid":"4e7yYf0TKdyTLbVnpq2wLN6mZ8t7eb9UJkMksyHj9iU","credential_type":"public_key","alg":"RS256","created_at":"2024-08-16T04:47:30.612Z","updated_at":"2024-08-16T04:47:30.612Z"}]}}}'
headers:
Content-Type:
- application/json; charset=utf-8
status: 201 Created
code: 201
duration: 717.130959ms
duration: 540.919625ms
- id: 2
request:
proto: HTTP/1.1
Expand All @@ -85,7 +85,7 @@ interactions:
remote_addr: ""
request_uri: ""
body: |
{"name":"test-organization722","display_name":"Test Organization","branding":{"logo_url":"https://example.com/logo.gif"}}
{"name":"test-organization640","display_name":"Test Organization","branding":{"logo_url":"https://example.com/logo.gif"}}
form: {}
headers:
Content-Type:
Expand All @@ -102,13 +102,13 @@ interactions:
trailer: {}
content_length: 149
uncompressed: false
body: '{"branding":{"logo_url":"https://example.com/logo.gif"},"id":"org_sZ3IaFfJhYeyjpcL","display_name":"Test Organization","name":"test-organization722"}'
body: '{"branding":{"logo_url":"https://example.com/logo.gif"},"id":"org_s04dFKosOxOZt1on","display_name":"Test Organization","name":"test-organization640"}'
headers:
Content-Type:
- application/json; charset=utf-8
status: 201 Created
code: 201
duration: 350.021417ms
duration: 480.306417ms
- id: 3
request:
proto: HTTP/1.1
Expand All @@ -121,14 +121,14 @@ interactions:
remote_addr: ""
request_uri: ""
body: |
{"connection_config":{"name":"sso-generated-ticket"},"enabled_clients":["BOIL8nAokMxm00xXxxyB4SY3eTDUoO9e"],"enabled_organizations":[{"organization_id":"org_sZ3IaFfJhYeyjpcL"}]}
{"connection_config":{"name":"sso-generated-ticket"},"enabled_clients":["9ZYEVW30TbIdxb5hFkBzQva2webZ19FK"],"enabled_organizations":[{"organization_id":"org_s04dFKosOxOZt1on"}]}
form: {}
headers:
Content-Type:
- application/json
User-Agent:
- Go-Auth0/1.8.0
url: https://go-auth0-dev.eu.auth0.com/api/v2/self-service-profiles/ssp_bmXiN4rAsd8U3mq2KwFBj6/sso-ticket
url: https://go-auth0-dev.eu.auth0.com/api/v2/self-service-profiles/ssp_hLuKqzSQiVrFAMNTJm1BL9/sso-ticket
method: POST
response:
proto: HTTP/2.0
Expand All @@ -138,13 +138,13 @@ interactions:
trailer: {}
content_length: 148
uncompressed: false
body: '{"ticket":"https://go-auth0-dev.eu.auth0.com.sus.auth0.com/self-service/connections-flow?ticket=RephlB0M9XCJseGWZYfo1Bb2ZKE4orDs"}'
body: '{"ticket":"https://go-auth0-dev.eu.auth0.com.sus.auth0.com/self-service/connections-flow?ticket=uEWkhrfyM2oby2wGTumHoHeya7ixZJKY"}'
headers:
Content-Type:
- application/json; charset=utf-8
status: 201 Created
code: 201
duration: 373.495417ms
duration: 382.64925ms
- id: 4
request:
proto: HTTP/1.1
Expand All @@ -163,7 +163,7 @@ interactions:
- application/json
User-Agent:
- Go-Auth0/1.8.0
url: https://go-auth0-dev.eu.auth0.com/api/v2/organizations/org_sZ3IaFfJhYeyjpcL
url: https://go-auth0-dev.eu.auth0.com/api/v2/organizations/org_s04dFKosOxOZt1on
method: DELETE
response:
proto: HTTP/2.0
Expand All @@ -179,7 +179,7 @@ interactions:
- application/json; charset=utf-8
status: 204 No Content
code: 204
duration: 326.183417ms
duration: 353.554417ms
- id: 5
request:
proto: HTTP/1.1
Expand All @@ -198,7 +198,7 @@ interactions:
- application/json
User-Agent:
- Go-Auth0/1.8.0
url: https://go-auth0-dev.eu.auth0.com/api/v2/clients/BOIL8nAokMxm00xXxxyB4SY3eTDUoO9e
url: https://go-auth0-dev.eu.auth0.com/api/v2/clients/9ZYEVW30TbIdxb5hFkBzQva2webZ19FK
method: DELETE
response:
proto: HTTP/2.0
Expand All @@ -214,7 +214,7 @@ interactions:
- application/json; charset=utf-8
status: 204 No Content
code: 204
duration: 378.754125ms
duration: 454.73225ms
- id: 6
request:
proto: HTTP/1.1
Expand All @@ -233,7 +233,7 @@ interactions:
- application/json
User-Agent:
- Go-Auth0/1.8.0
url: https://go-auth0-dev.eu.auth0.com/api/v2/self-service-profiles/ssp_bmXiN4rAsd8U3mq2KwFBj6
url: https://go-auth0-dev.eu.auth0.com/api/v2/self-service-profiles/ssp_hLuKqzSQiVrFAMNTJm1BL9
method: DELETE
response:
proto: HTTP/2.0
Expand All @@ -249,4 +249,4 @@ interactions:
- application/json; charset=utf-8
status: 204 No Content
code: 204
duration: 308.308459ms
duration: 340.758917ms
Loading

0 comments on commit 5010e9f

Please sign in to comment.