Skip to content

Commit

Permalink
SSO v2 updates
Browse files Browse the repository at this point in the history
  • Loading branch information
duedares-rvj committed Nov 3, 2024
1 parent 89bcb9b commit cbaf973
Show file tree
Hide file tree
Showing 9 changed files with 299 additions and 102 deletions.
43 changes: 38 additions & 5 deletions management/self_service_profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ import (
type SelfServiceProfile struct {
ID *string `json:"id,omitempty"`

// The name of the self-service Profile
Name *string `json:"name,omitempty"`
// The description of the self-service Profile.
Description *string `json:"description,omitempty"`

// List of IdP strategies that will be shown to users during the Self-Service SSO flow.
// Possible values: [oidc, samlp, waad, google-apps, adfs, okta, keycloak-samlp]
AllowedStrategies []*string `json:"allowed_strategies,omitempty"`

// List of attributes to be mapped that
// will be shown to the user during the SS-SSO flow.
UserAttributes []*SelfServiceProfileUserAttributes `json:"user_attributes,omitempty"`
Expand All @@ -34,6 +43,12 @@ type SelfServiceProfileUserAttributes struct {
IsOptional *bool `json:"is_optional"`
}

// SelfServiceProfileList is a list of SelfServiceProfiles.
type SelfServiceProfileList struct {
List
SelfServiceProfile []*SelfServiceProfile `json:"self_service_profiles"`
}

// SelfServiceProfileTicket is used to created self-service ticket for a set of clients and organizations.
type SelfServiceProfileTicket struct {
// If provided, this will allow editing of the
Expand Down Expand Up @@ -72,13 +87,19 @@ type SelfServiceProfileTicketEnabledOrganizations struct {
// MarshalJSON implements the json.Marshaller interface.
func (ssp *SelfServiceProfile) MarshalJSON() ([]byte, error) {
type SelfServiceProfileSubset struct {
UserAttributes []*SelfServiceProfileUserAttributes `json:"user_attributes,omitempty"`
Branding *Branding `json:"branding,omitempty"`
Name *string `json:"name,omitempty"`
Description *string `json:"description,omitempty"`
AllowedStrategies []*string `json:"allowed_strategies,omitempty"`
UserAttributes []*SelfServiceProfileUserAttributes `json:"user_attributes,omitempty"`
Branding *Branding `json:"branding,omitempty"`
}

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

Expand All @@ -92,7 +113,7 @@ func (m *SelfServiceProfileManager) Create(ctx context.Context, s *SelfServicePr
}

// List all Self Service Profiles.
func (m *SelfServiceProfileManager) List(ctx context.Context, opts ...RequestOption) (s []*SelfServiceProfile, err error) {
func (m *SelfServiceProfileManager) List(ctx context.Context, opts ...RequestOption) (s *SelfServiceProfileList, err error) {
err = m.management.Request(ctx, "GET", m.management.URI("self-service-profiles"), &s, applyListDefaults(opts))
return
}
Expand All @@ -113,6 +134,18 @@ func (m *SelfServiceProfileManager) Delete(ctx context.Context, id string, opts
return m.management.Request(ctx, "DELETE", m.management.URI("self-service-profiles", id), nil, opts...)
}

// GetCustomText retrieves text customizations for a given self-service profile, language and Self Service SSO Flow page.
func (m *SelfServiceProfileManager) GetCustomText(ctx context.Context, id string, language string, page string, opts ...RequestOption) (payload map[string]interface{}, err error) {
err = m.management.Request(ctx, "GET", m.management.URI("self-service-profiles", id, "custom-text", language, page), &payload, opts...)
return
}

// SetCustomText updates text customizations for a given self-service profile, language and Self Service SSO Flow page.
func (m *SelfServiceProfileManager) SetCustomText(ctx context.Context, id string, language string, page string, payload map[string]interface{}, opts ...RequestOption) (err error) {
err = m.management.Request(ctx, "PUT", m.management.URI("self-service-profiles", id, "custom-text", language, page), payload, opts...)
return
}

// CreateTicket creates a sso-access ticket to initiate the Self Service SSO Flow.
func (m *SelfServiceProfileManager) CreateTicket(ctx context.Context, id string, t *SelfServiceProfileTicket, opts ...RequestOption) (err error) {
err = m.management.Request(ctx, "POST", m.management.URI("self-service-profiles", id, "sso-ticket"), t, opts...)
Expand Down
23 changes: 21 additions & 2 deletions management/self_service_profiles_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ import (
func TestSelfServiceProfileManager_Create(t *testing.T) {
configureHTTPTestRecordings(t)
ssop := &SelfServiceProfile{
Name: auth0.String("Sample Self Service Profile"),
Description: auth0.String("Sample Desc"),
AllowedStrategies: []*string{auth0.String("oidc")},
Branding: &Branding{
LogoURL: auth0.String("https://example.com/logo.png"),
Colors: &BrandingColors{
Expand Down Expand Up @@ -45,8 +48,8 @@ func TestSelfServiceProfileManager_List(t *testing.T) {
ssop := givenASelfServiceProfile(t)
ssopList, err := api.SelfServiceProfile.List(context.Background())
assert.NoError(t, err)
assert.Greater(t, len(ssopList), 0)
assert.Contains(t, ssopList, ssop)
assert.Greater(t, len(ssopList.SelfServiceProfile), 0)
assert.Contains(t, ssopList.SelfServiceProfile, ssop)
}

func TestSelfServiceProfileManager_Read(t *testing.T) {
Expand Down Expand Up @@ -92,6 +95,19 @@ func TestSelfServiceProfileManager_Delete(t *testing.T) {
assert.Equal(t, http.StatusNotFound, err.(Error).Status())
}

func TestSelfServiceProfileManager_SetGetCustomText(t *testing.T) {
configureHTTPTestRecordings(t)
ssop := givenASelfServiceProfile(t)
payload := map[string]interface{}{
"introduction": "\"Welcome! With only a few steps you'll be able to setup your new connection.\"\n",
}
err := api.SelfServiceProfile.SetCustomText(context.Background(), ssop.GetID(), "en", "get-started", payload)
assert.Equal(t, err, nil)
retrievedCustomText, err := api.SelfServiceProfile.GetCustomText(context.Background(), ssop.GetID(), "en", "get-started")
assert.Equal(t, err, nil)
assert.Equal(t, payload, retrievedCustomText)
}

func TestSelfServiceProfileManager_CreateTicket(t *testing.T) {
configureHTTPTestRecordings(t)
ssop := givenASelfServiceProfile(t)
Expand Down Expand Up @@ -147,6 +163,9 @@ func TestSelfServiceProfileManager_MarshalJSON(t *testing.T) {
func givenASelfServiceProfile(t *testing.T) *SelfServiceProfile {
t.Helper()
ssop := &SelfServiceProfile{
Name: auth0.String("Sample Self Service Profile"),
Description: auth0.String("Sample Desc"),
AllowedStrategies: []*string{auth0.String("oidc")},
Branding: &Branding{
LogoURL: auth0.String("https://example.com/logo.png"),
Colors: &BrandingColors{
Expand Down
26 changes: 13 additions & 13 deletions test/data/recordings/TestSelfServiceProfileManager_Create.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@ interactions:
proto: HTTP/1.1
proto_major: 1
proto_minor: 1
content_length: 186
content_length: 281
transfer_encoding: []
trailer: {}
host: go-auth0-dev.eu.auth0.com
remote_addr: ""
request_uri: ""
body: |
{"user_attributes":[{"name":"some-name-here","description":"some-description","is_optional":true}],"branding":{"colors":{"primary":"#334455"},"logo_url":"https://example.com/logo.png"}}
{"name":"Sample Self Service Profile","description":"Sample Desc","allowed_strategies":["oidc"],"user_attributes":[{"name":"some-name-here","description":"some-description","is_optional":true}],"branding":{"colors":{"primary":"#334455"},"logo_url":"https://example.com/logo.png"}}
form: {}
headers:
Content-Type:
- application/json
User-Agent:
- Go-Auth0/1.8.0
- Go-Auth0/1.11.2
url: https://go-auth0-dev.eu.auth0.com/api/v2/self-service-profiles
method: POST
response:
Expand All @@ -28,15 +28,15 @@ interactions:
proto_minor: 0
transfer_encoding: []
trailer: {}
content_length: 299
content_length: 394
uncompressed: false
body: '{"id":"ssp_8z3r5eqUUVBBC1QyZdV5Xq","user_attributes":[{"name":"some-name-here","description":"some-description","is_optional":true}],"created_at":"2024-08-16T06:32:10.792Z","updated_at":"2024-08-16T06:32:10.792Z","branding":{"logo_url":"https://example.com/logo.png","colors":{"primary":"#334455"}}}'
body: '{"id":"ssp_qJjPnZcqrYMQnn5XbrwjDp","name":"Sample Self Service Profile","description":"Sample Desc","user_attributes":[{"name":"some-name-here","description":"some-description","is_optional":true}],"allowed_strategies":["oidc"],"created_at":"2024-11-03T11:22:35.206Z","updated_at":"2024-11-03T11:22:35.206Z","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: 1.047568167s
duration: 999.470917ms
- id: 1
request:
proto: HTTP/1.1
Expand All @@ -54,8 +54,8 @@ interactions:
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_8z3r5eqUUVBBC1QyZdV5Xq
- Go-Auth0/1.11.2
url: https://go-auth0-dev.eu.auth0.com/api/v2/self-service-profiles/ssp_qJjPnZcqrYMQnn5XbrwjDp
method: GET
response:
proto: HTTP/2.0
Expand All @@ -65,13 +65,13 @@ interactions:
trailer: {}
content_length: -1
uncompressed: true
body: '{"id":"ssp_8z3r5eqUUVBBC1QyZdV5Xq","user_attributes":[{"name":"some-name-here","description":"some-description","is_optional":true}],"created_at":"2024-08-16T06:32:10.792Z","updated_at":"2024-08-16T06:32:10.792Z","branding":{"logo_url":"https://example.com/logo.png","colors":{"primary":"#334455"}}}'
body: '{"id":"ssp_qJjPnZcqrYMQnn5XbrwjDp","name":"Sample Self Service Profile","description":"Sample Desc","user_attributes":[{"name":"some-name-here","description":"some-description","is_optional":true}],"allowed_strategies":["oidc"],"created_at":"2024-11-03T11:22:35.206Z","updated_at":"2024-11-03T11:22:35.206Z","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: 410.606208ms
duration: 421.911834ms
- id: 2
request:
proto: HTTP/1.1
Expand All @@ -89,8 +89,8 @@ interactions:
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_8z3r5eqUUVBBC1QyZdV5Xq
- Go-Auth0/1.11.2
url: https://go-auth0-dev.eu.auth0.com/api/v2/self-service-profiles/ssp_qJjPnZcqrYMQnn5XbrwjDp
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: 405.070709ms
duration: 372.68675ms
Loading

0 comments on commit cbaf973

Please sign in to comment.