Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions saml_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type SAMLConnection struct {
AllowOrganizationAccountLinking bool `json:"allow_organization_account_linking"`
CustomAttributes *[]CustomAttribute `json:"custom_attributes,omitempty"`
Authenticatable bool `json:"authenticatable"`
LoginHint *LoginHint `json:"login_hint,omitempty"`
CreatedAt int64 `json:"created_at"`
UpdatedAt int64 `json:"updated_at"`
}
Expand All @@ -52,6 +53,13 @@ type SAMLConnectionAttributeMapping struct {
LastName string `json:"last_name"`
}

// LoginHint describes the login hint a SAML connection sends to the identity
// provider when initiating a sign-in.
type LoginHint struct {
Mode string `json:"mode"`
Source *string `json:"source,omitempty"`
}

type SAMLConnectionList struct {
APIResource
SAMLConnections []*SAMLConnection `json:"data"`
Expand Down
9 changes: 9 additions & 0 deletions samlconnection/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ type AttributeMappingParams struct {
LastName string `json:"last_name"`
}

// LoginHintParams configures the login hint a SAML connection sends to the
// identity provider when initiating a sign-in.
type LoginHintParams struct {
Mode *string `json:"mode,omitempty"`
Source *string `json:"source,omitempty"`
}

type CreateParams struct {
clerk.APIParams
Name *string `json:"name,omitempty"`
Expand All @@ -55,6 +62,7 @@ type CreateParams struct {
AttributeMapping *AttributeMappingParams `json:"attribute_mapping,omitempty"`
ForceAuthn *bool `json:"force_authn,omitempty"`
DisableJITProvisioning *bool `json:"disable_jit_provisioning,omitempty"`
LoginHint *LoginHintParams `json:"login_hint,omitempty"`
// CustomAttributes is an Experimental feature, not available for all customers.
CustomAttributes *[]clerk.CustomAttribute `json:"custom_attributes,omitempty"`
}
Expand Down Expand Up @@ -123,6 +131,7 @@ type UpdateParams struct {
DisableJITProvisioning *bool `json:"disable_jit_provisioning,omitempty"`
ConsentVerifiedDomainsDeletion *bool `json:"consent_verified_domains_deletion,omitempty"`
Authenticatable *bool `json:"authenticatable,omitempty"`
LoginHint *LoginHintParams `json:"login_hint,omitempty"`
// CustomAttributes is an Experimental feature, not available for all customers.
CustomAttributes *[]clerk.CustomAttribute `json:"custom_attributes,omitempty"`
}
Expand Down
31 changes: 26 additions & 5 deletions samlconnection/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ func TestSAMLConnectionClientCreate(t *testing.T) {
domain := "example.com"
provider := "saml_custom"
forceAuthn := true
loginHintMode := "custom_attribute"
loginHintSource := "employee_id"
config := &clerk.ClientConfig{}
config.HTTPClient = &http.Client{
Transport: &clerktest.RoundTripper{
T: t,
In: json.RawMessage(fmt.Sprintf(`{"name":"%s","domain":"%s","provider":"%s","force_authn":%t}`, name, domain, provider, forceAuthn)),
Out: json.RawMessage(fmt.Sprintf(`{"id":"%s","name":"%s","domain":"%s","provider":"%s","force_authn":%t}`, id, name, domain, provider, forceAuthn)),
In: json.RawMessage(fmt.Sprintf(`{"name":"%s","domain":"%s","provider":"%s","force_authn":%t,"login_hint":{"mode":"%s","source":"%s"}}`, name, domain, provider, forceAuthn, loginHintMode, loginHintSource)),
Out: json.RawMessage(fmt.Sprintf(`{"id":"%s","name":"%s","domain":"%s","provider":"%s","force_authn":%t,"login_hint":{"mode":"%s","source":"%s"}}`, id, name, domain, provider, forceAuthn, loginHintMode, loginHintSource)),
Method: http.MethodPost,
Path: "/v1/saml_connections",
},
Expand All @@ -36,6 +38,10 @@ func TestSAMLConnectionClientCreate(t *testing.T) {
Domain: clerk.String(domain),
Provider: clerk.String(provider),
ForceAuthn: clerk.Bool(forceAuthn),
LoginHint: &LoginHintParams{
Mode: clerk.String(loginHintMode),
Source: clerk.String(loginHintSource),
},
})
require.NoError(t, err)
require.Equal(t, id, samlConnection.ID)
Expand All @@ -44,6 +50,10 @@ func TestSAMLConnectionClientCreate(t *testing.T) {
require.Equal(t, domain, samlConnection.Domain)
require.Equal(t, provider, samlConnection.Provider)
require.Equal(t, forceAuthn, samlConnection.ForceAuthn)
require.NotNil(t, samlConnection.LoginHint)
require.Equal(t, loginHintMode, samlConnection.LoginHint.Mode)
require.NotNil(t, samlConnection.LoginHint.Source)
require.Equal(t, loginHintSource, *samlConnection.LoginHint.Source)
}

// TestSAMLConnectionClientCreate_WithBothDomainAndDomains tests that the client can not create a SAML connection
Expand Down Expand Up @@ -142,11 +152,12 @@ func TestSAMLConnectionClientGet(t *testing.T) {
provider := "saml_custom"
disableAdditionalIdentifications := true
forceAuthn := false
loginHintMode := "off"
config := &clerk.ClientConfig{}
config.HTTPClient = &http.Client{
Transport: &clerktest.RoundTripper{
T: t,
Out: json.RawMessage(fmt.Sprintf(`{"id":"%s","name":"%s","domain":"%s","provider":"%s", "disable_additional_identifications": %t, "force_authn": %t, "enterprise_connection_id": "entconn_2abc123def456", "custom_attributes": [{"name": "custom_attribute_name", "key": "custom_attribute_key", "sso_path": "custom_attribute_sso_path", "scim_path": "custom_attribute_scim_path"}]}`, id, name, domain, provider, disableAdditionalIdentifications, forceAuthn)),
Out: json.RawMessage(fmt.Sprintf(`{"id":"%s","name":"%s","domain":"%s","provider":"%s", "disable_additional_identifications": %t, "force_authn": %t, "login_hint": {"mode": "%s"}, "enterprise_connection_id": "entconn_2abc123def456", "custom_attributes": [{"name": "custom_attribute_name", "key": "custom_attribute_key", "sso_path": "custom_attribute_sso_path", "scim_path": "custom_attribute_scim_path"}]}`, id, name, domain, provider, disableAdditionalIdentifications, forceAuthn, loginHintMode)),
Method: http.MethodGet,
Path: "/v1/saml_connections/" + id,
},
Expand All @@ -161,6 +172,9 @@ func TestSAMLConnectionClientGet(t *testing.T) {
require.Equal(t, provider, samlConnection.Provider)
require.Equal(t, disableAdditionalIdentifications, samlConnection.DisableAdditionalIdentifications)
require.Equal(t, forceAuthn, samlConnection.ForceAuthn)
require.NotNil(t, samlConnection.LoginHint)
require.Equal(t, loginHintMode, samlConnection.LoginHint.Mode)
require.Nil(t, samlConnection.LoginHint.Source)
require.Equal(t, &[]clerk.CustomAttribute{
{
Name: clerk.String("custom_attribute_name"),
Expand All @@ -179,12 +193,13 @@ func TestSAMLConnectionClientUpdate(t *testing.T) {
provider := "saml_custom"
disableAdditionalIdentifications := true
forceAuthn := true
loginHintMode := "email_address"
config := &clerk.ClientConfig{}
config.HTTPClient = &http.Client{
Transport: &clerktest.RoundTripper{
T: t,
In: json.RawMessage(fmt.Sprintf(`{"name":"%s", "disable_additional_identifications": %t, "organization_id": "", "force_authn": %t, "custom_attributes": [{"name": "custom_attribute_name", "key": "custom_attribute_key", "sso_path": "custom_attribute_sso_path", "scim_path": "custom_attribute_scim_path"}]}`, name, disableAdditionalIdentifications, forceAuthn)),
Out: json.RawMessage(fmt.Sprintf(`{"id":"%s","name":"%s","domain":"%s","provider":"%s","disable_additional_identifications": %t,"force_authn": %t, "enterprise_connection_id": null, "custom_attributes": [{"name": "custom_attribute_name", "key": "custom_attribute_key", "sso_path": "custom_attribute_sso_path", "scim_path": "custom_attribute_scim_path"}]}`, id, name, domain, provider, disableAdditionalIdentifications, forceAuthn)),
In: json.RawMessage(fmt.Sprintf(`{"name":"%s", "disable_additional_identifications": %t, "organization_id": "", "force_authn": %t, "login_hint": {"mode": "%s"}, "custom_attributes": [{"name": "custom_attribute_name", "key": "custom_attribute_key", "sso_path": "custom_attribute_sso_path", "scim_path": "custom_attribute_scim_path"}]}`, name, disableAdditionalIdentifications, forceAuthn, loginHintMode)),
Out: json.RawMessage(fmt.Sprintf(`{"id":"%s","name":"%s","domain":"%s","provider":"%s","disable_additional_identifications": %t,"force_authn": %t, "login_hint": {"mode": "%s"}, "enterprise_connection_id": null, "custom_attributes": [{"name": "custom_attribute_name", "key": "custom_attribute_key", "sso_path": "custom_attribute_sso_path", "scim_path": "custom_attribute_scim_path"}]}`, id, name, domain, provider, disableAdditionalIdentifications, forceAuthn, loginHintMode)),
Method: http.MethodPatch,
Path: "/v1/saml_connections/" + id,
},
Expand All @@ -195,6 +210,9 @@ func TestSAMLConnectionClientUpdate(t *testing.T) {
DisableAdditionalIdentifications: clerk.Bool(disableAdditionalIdentifications),
OrganizationID: clerk.String(""),
ForceAuthn: clerk.Bool(forceAuthn),
LoginHint: &LoginHintParams{
Mode: clerk.String(loginHintMode),
},
CustomAttributes: &[]clerk.CustomAttribute{
{
Name: clerk.String("custom_attribute_name"),
Expand All @@ -217,6 +235,9 @@ func TestSAMLConnectionClientUpdate(t *testing.T) {
require.Equal(t, name, samlConnection.Name)
require.Equal(t, disableAdditionalIdentifications, samlConnection.DisableAdditionalIdentifications)
require.Equal(t, forceAuthn, samlConnection.ForceAuthn)
require.NotNil(t, samlConnection.LoginHint)
require.Equal(t, loginHintMode, samlConnection.LoginHint.Mode)
require.Nil(t, samlConnection.LoginHint.Source)
}

func TestSAMLConnectionClientUpdate_DisableJITProvisioning(t *testing.T) {
Expand Down
Loading