Skip to content

Commit

Permalink
Added new endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
duedares-rvj committed Nov 6, 2024
1 parent a7d5b7e commit 1e73ae9
Show file tree
Hide file tree
Showing 11 changed files with 325 additions and 70 deletions.
77 changes: 77 additions & 0 deletions management/management.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

98 changes: 98 additions & 0 deletions management/management.gen_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 27 additions & 2 deletions management/self_service_profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ type SelfServiceProfileTicket struct {
// connection will be enabled for.
EnabledOrganizations []*SelfServiceProfileTicketEnabledOrganizations `json:"enabled_organizations,omitempty"`

TTLSec int `json:"ttl_sec"`

// The ticket that is generated.
Ticket *string `json:"ticket,omitempty"`
}
Expand All @@ -75,13 +77,30 @@ type SelfServiceProfileTicket struct {
type SelfServiceProfileTicketConnectionConfig struct {
// The name of the connection that will be
// created as a part of the SSO flow.
Name string `json:"name,omitempty"`
Name *string `json:"name,omitempty"`

// The display name of the connection that will be
// created as a part of the SSO flow.
DisplayName *string `json:"display_name,omitempty"`

IsDomainConnection *bool `json:"is_domain_connection,omitempty"`
ShowAsButton *bool `json:"show_as_button,omitempty"`
Metadata *map[string]interface{} `json:"metadata,omitempty"`
Options SelfServiceProfileTicketConnectionConfigOptions `json:"options,omitempty"`
}

// SelfServiceProfileTicketConnectionConfigOptions is the list of Options for SSO Ticket.
type SelfServiceProfileTicketConnectionConfigOptions struct {
IconURL *string `json:"icon_url,omitempty"`
DomainAliases []*string `json:"domain_aliases,omitempty"`
}

// SelfServiceProfileTicketEnabledOrganizations is the list of Organizations associated with the SSO Ticket.
type SelfServiceProfileTicketEnabledOrganizations struct {
// Organization identifier.
OrganizationID string `json:"organization_id,omitempty"`
OrganizationID *string `json:"organization_id,omitempty"`
AssignMembershipOnLogin *bool `json:"assign_membership_on_login,omitempty"`
ShowAsButton *bool `json:"show_as_button,omitempty"`
}

// MarshalJSON implements the json.Marshaller interface.
Expand Down Expand Up @@ -151,3 +170,9 @@ func (m *SelfServiceProfileManager) CreateTicket(ctx context.Context, id string,
err = m.management.Request(ctx, "POST", m.management.URI("self-service-profiles", id, "sso-ticket"), t, opts...)
return
}

// RevokeTicket revokes the sso-access ticket against a specific SSO Profile.
func (m *SelfServiceProfileManager) RevokeTicket(ctx context.Context, id string, ticketID string, opts ...RequestOption) (err error) {
err = m.management.Request(ctx, "POST", m.management.URI("self-service-profiles", id, "sso-ticket", ticketID, "revoke"), nil, opts...)
return
}
26 changes: 23 additions & 3 deletions management/self_service_profiles_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"net/http"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -108,26 +109,45 @@ func TestSelfServiceProfileManager_SetGetCustomText(t *testing.T) {
assert.Equal(t, payload, retrievedCustomText)
}

func TestSelfServiceProfileManager_CreateTicket(t *testing.T) {
func TestSelfServiceProfileManager_CreateAndRevokeTicket(t *testing.T) {
configureHTTPTestRecordings(t)
ssop := givenASelfServiceProfile(t)
client := givenAClient(t)
org := givenAnOrganization(t)

ticket := &SelfServiceProfileTicket{
ConnectionConfig: &SelfServiceProfileTicketConnectionConfig{
Name: "sso-generated-ticket",
Name: auth0.String("sso-generated-ticket"),
DisplayName: auth0.String("sso-generated-ticket-display-name"),
IsDomainConnection: auth0.Bool(true),
ShowAsButton: auth0.Bool(true),
Metadata: &map[string]interface{}{
"key1": "value1",
"key2": "value2",
},
Options: SelfServiceProfileTicketConnectionConfigOptions{
IconURL: auth0.String("https://metabox.com/my_icon.jpeg"),
DomainAliases: []*string{auth0.String("okta.com")},
},
},
EnabledClients: []*string{auth0.String(client.GetClientID())},
EnabledOrganizations: []*SelfServiceProfileTicketEnabledOrganizations{
{
org.GetID(),
AssignMembershipOnLogin: auth0.Bool(true),
ShowAsButton: auth0.Bool(true),
OrganizationID: auth0.String(org.GetID()),
},
},
}
err := api.SelfServiceProfile.CreateTicket(context.Background(), ssop.GetID(), ticket)
assert.NoError(t, err)
assert.NotEmpty(t, ticket.GetTicket())

ticketURL := ticket.GetTicket()
ticketID := ticketURL[strings.LastIndex(ticketURL, "=")+1:]

err = api.SelfServiceProfile.RevokeTicket(context.Background(), ssop.GetID(), ticketID)
assert.NoError(t, err)
}

func TestSelfServiceProfileManager_MarshalJSON(t *testing.T) {
Expand Down
14 changes: 7 additions & 7 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: 394
uncompressed: false
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"}}}'
body: '{"id":"ssp_rRN6NKjp1Xk3SoghgjovRx","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-06T19:41:31.394Z","updated_at":"2024-11-06T19:41:31.394Z","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: 999.470917ms
duration: 1.290922208s
- id: 1
request:
proto: HTTP/1.1
Expand All @@ -55,7 +55,7 @@ interactions:
- application/json
User-Agent:
- Go-Auth0/1.11.2
url: https://go-auth0-dev.eu.auth0.com/api/v2/self-service-profiles/ssp_qJjPnZcqrYMQnn5XbrwjDp
url: https://go-auth0-dev.eu.auth0.com/api/v2/self-service-profiles/ssp_rRN6NKjp1Xk3SoghgjovRx
method: GET
response:
proto: HTTP/2.0
Expand All @@ -65,13 +65,13 @@ interactions:
trailer: {}
content_length: -1
uncompressed: true
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"}}}'
body: '{"id":"ssp_rRN6NKjp1Xk3SoghgjovRx","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-06T19:41:31.394Z","updated_at":"2024-11-06T19:41:31.394Z","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: 421.911834ms
duration: 437.787458ms
- id: 2
request:
proto: HTTP/1.1
Expand All @@ -90,7 +90,7 @@ interactions:
- application/json
User-Agent:
- Go-Auth0/1.11.2
url: https://go-auth0-dev.eu.auth0.com/api/v2/self-service-profiles/ssp_qJjPnZcqrYMQnn5XbrwjDp
url: https://go-auth0-dev.eu.auth0.com/api/v2/self-service-profiles/ssp_rRN6NKjp1Xk3SoghgjovRx
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: 372.68675ms
duration: 364.379833ms
Loading

0 comments on commit 1e73ae9

Please sign in to comment.