Skip to content

Commit 56e95d2

Browse files
authored
feat: update support for /v3/sso (sso-settings) (#780)
* feat: update SSO settings to v3 * update SSO settings struct to use pointers for nested configurations * add /v3/sso/dependencies * deprecate v2 functions
1 parent 06dbd6a commit 56e95d2

File tree

6 files changed

+319
-54
lines changed

6 files changed

+319
-54
lines changed
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
// jamfproapi_sso_settings.go
2+
// Jamf Pro Api - SSO Settings
3+
// api reference: https://developer.jamf.com/jamf-pro/reference/get_v2-sso
4+
// Jamf Pro API requires the structs to support a JSON data structure.
5+
6+
package jamfpro
7+
8+
import "fmt"
9+
10+
const uriSsoSettings = "/api/v2/sso"
11+
const uriSsoDependencies = "/api/v2/sso/dependencies"
12+
13+
// Structs
14+
15+
// SSO Settings
16+
// Resource
17+
18+
type ResourceSsoSettings struct {
19+
SsoForEnrollmentEnabled bool `json:"ssoForEnrollmentEnabled"`
20+
SsoBypassAllowed bool `json:"ssoBypassAllowed"`
21+
SsoEnabled bool `json:"ssoEnabled"`
22+
SsoForMacOsSelfServiceEnabled bool `json:"ssoForMacOsSelfServiceEnabled"`
23+
TokenExpirationDisabled bool `json:"tokenExpirationDisabled"`
24+
UserAttributeEnabled bool `json:"userAttributeEnabled"`
25+
UserAttributeName string `json:"userAttributeName"`
26+
UserMapping string `json:"userMapping"`
27+
EnrollmentSsoForAccountDrivenEnrollmentEnabled bool `json:"enrollmentSsoForAccountDrivenEnrollmentEnabled"`
28+
EnrollmentSsoConfig SsoSettingsSubsetEnrollmentSsoConfig `json:"enrollmentSsoConfig"`
29+
GroupEnrollmentAccessEnabled bool `json:"groupEnrollmentAccessEnabled"`
30+
GroupAttributeName string `json:"groupAttributeName"`
31+
GroupRdnKey string `json:"groupRdnKey"`
32+
GroupEnrollmentAccessName string `json:"groupEnrollmentAccessName"`
33+
IdpProviderType string `json:"idpProviderType"`
34+
IdpUrl string `json:"idpUrl"`
35+
EntityId string `json:"entityId"`
36+
MetadataFileName string `json:"metadataFileName"`
37+
OtherProviderTypeName string `json:"otherProviderTypeName"`
38+
FederationMetadataFile string `json:"federationMetadataFile"`
39+
MetadataSource string `json:"metadataSource"`
40+
SessionTimeout int `json:"sessionTimeout"`
41+
}
42+
43+
// Subsets
44+
45+
type SsoSettingsSubsetEnrollmentSsoConfig struct {
46+
Hosts []string `json:"hosts"`
47+
ManagementHint string `json:"managementHint"`
48+
}
49+
50+
// Enrollment Customizations Using SSO
51+
// Resource
52+
53+
type ResponseSsoSubsetEnrollmentCustomizationDependencyList struct {
54+
Dependencies []SsoSubsetSubsetEnrollmentCustomizationDependency
55+
}
56+
57+
// Subset
58+
59+
type SsoSubsetSubsetEnrollmentCustomizationDependency struct {
60+
Name string `json:"name"`
61+
HumanReadableName string `json:"humanReadableName"`
62+
Hyperlink string `json:"hyperlink"`
63+
}
64+
65+
// CRUD
66+
67+
// GetSsoSettings retrieves current Jamf Sso settings
68+
func (c *Client) GetSsoSettings() (*ResourceSsoSettings, error) {
69+
endpoint := uriSsoSettings
70+
var out ResourceSsoSettings
71+
resp, err := c.HTTP.DoRequest("GET", endpoint, nil, &out)
72+
if err != nil {
73+
return nil, fmt.Errorf(errMsgFailedGet, "sso settings", err)
74+
}
75+
76+
if resp != nil && resp.Body != nil {
77+
defer resp.Body.Close()
78+
}
79+
80+
return &out, nil
81+
}
82+
83+
// UpdateSsoSettings Updates SSO Settings with ResourceSsoSettings struct data
84+
func (c *Client) UpdateSsoSettings(updatedSettings ResourceSsoSettings) (*ResourceSsoSettings, error) {
85+
endpoint := uriSsoSettings
86+
var out ResourceSsoSettings
87+
resp, err := c.HTTP.DoRequest("PUT", endpoint, updatedSettings, &out)
88+
if err != nil {
89+
return nil, fmt.Errorf(errMsgFailedUpdate, "sso settings", err)
90+
}
91+
92+
if resp != nil && resp.Body != nil {
93+
defer resp.Body.Close()
94+
}
95+
96+
return &out, nil
97+
}
98+
99+
// GetSsoEnrollmentCustomizationDependencies shows which enrollment customizations are dependent on which sso settings // NOTE I think?
100+
func (c *Client) GetSsoEnrollmentCustomizationDependencies() (*ResponseSsoSubsetEnrollmentCustomizationDependencyList, error) {
101+
endpoint := uriSsoDependencies
102+
var out ResponseSsoSubsetEnrollmentCustomizationDependencyList
103+
resp, err := c.HTTP.DoRequest("GET", endpoint, nil, &out)
104+
if err != nil {
105+
return nil, fmt.Errorf(errMsgFailedGet, "sso enrollment customization dependencies", err)
106+
}
107+
108+
if resp != nil && resp.Body != nil {
109+
defer resp.Body.Close()
110+
}
111+
112+
return &out, nil
113+
}
114+
115+
// QUERY What other endpoints do we need to cover here? It's a bit of a mix mash

examples/sso_settings/GetSsoECDependencies/GetSsoECDependencies.go

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package main
2+
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
"log"
7+
8+
"github.com/deploymenttheory/go-api-sdk-jamfpro/sdk/jamfpro"
9+
)
10+
11+
func main() {
12+
// Define the path to the JSON configuration file
13+
configFilePath := "/Users/Shared/GitHub/go-api-sdk-jamfpro/localtesting/clientconfig.json"
14+
15+
// Initialize the Jamf Pro client with the HTTP client configuration
16+
client, err := jamfpro.BuildClientWithConfigFile(configFilePath)
17+
if err != nil {
18+
log.Fatalf("Failed to initialize Jamf Pro client: %v", err)
19+
}
20+
21+
// Fetch SSO dependencies
22+
fmt.Println("Fetching SSO dependencies...")
23+
ssoDependencies, err := client.GetSsoEnrollmentCustomizationDependencies()
24+
if err != nil {
25+
fmt.Printf("Error fetching SSO dependencies: %v\n", err)
26+
return
27+
}
28+
29+
// Pretty print the JSON response for SSO dependencies
30+
dependenciesJSON, err := json.MarshalIndent(ssoDependencies, "", " ")
31+
if err != nil {
32+
log.Fatalf("Failed to marshal SSO dependencies JSON: %v", err)
33+
}
34+
fmt.Printf("SSO Dependencies:\n%s\n", dependenciesJSON)
35+
}
Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,35 @@
1-
// TODO
2-
31
package main
2+
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
"log"
7+
8+
"github.com/deploymenttheory/go-api-sdk-jamfpro/sdk/jamfpro"
9+
)
10+
11+
func main() {
12+
// Define the path to the JSON configuration file
13+
configFilePath := "/Users/Shared/GitHub/go-api-sdk-jamfpro/localtesting/clientconfig.json"
14+
15+
// Initialize the Jamf Pro client with the HTTP client configuration
16+
client, err := jamfpro.BuildClientWithConfigFile(configFilePath)
17+
if err != nil {
18+
log.Fatalf("Failed to initialize Jamf Pro client: %v", err)
19+
}
20+
21+
// Fetch SSO settings
22+
fmt.Println("Fetching SSO settings...")
23+
ssoSettings, err := client.GetSsoSettings()
24+
if err != nil {
25+
fmt.Printf("Error fetching SSO settings: %v\n", err)
26+
return
27+
}
28+
29+
// Pretty print the JSON response for SSO settings
30+
jsonData, err := json.MarshalIndent(ssoSettings, "", " ")
31+
if err != nil {
32+
log.Fatalf("Failed to marshal JSON: %v", err)
33+
}
34+
fmt.Printf("SSO Settings: %s\n", jsonData)
35+
}
Lines changed: 83 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,84 @@
1-
// TODO
2-
31
package main
2+
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
"log"
7+
8+
"github.com/deploymenttheory/go-api-sdk-jamfpro/sdk/jamfpro"
9+
)
10+
11+
// prettyPrintJSON converts a struct to a pretty-printed JSON string
12+
func prettyPrintJSON(prefix string, data interface{}) {
13+
jsonData, err := json.MarshalIndent(data, "", " ")
14+
if err != nil {
15+
log.Printf("Error marshaling JSON: %v", err)
16+
return
17+
}
18+
fmt.Printf("%s:\n%s\n", prefix, string(jsonData))
19+
}
20+
21+
func main() {
22+
// Define the path to the JSON configuration file
23+
configFilePath := "/Users/Shared/GitHub/go-api-sdk-jamfpro/localtesting/clientconfig.json"
24+
25+
// Initialize the Jamf Pro client with the HTTP client configuration
26+
client, err := jamfpro.BuildClientWithConfigFile(configFilePath)
27+
if err != nil {
28+
log.Fatalf("Failed to initialize Jamf Pro client: %v", err)
29+
}
30+
31+
// Define the SSO settings to update
32+
updateSettings := &jamfpro.ResourceSsoSettings{
33+
ConfigurationType: "SAML",
34+
OidcSettings: &jamfpro.OidcSettings{
35+
UserMapping: "USERNAME",
36+
},
37+
SamlSettings: &jamfpro.SamlSettings{
38+
TokenExpirationDisabled: false,
39+
UserAttributeEnabled: false,
40+
UserAttributeName: " ",
41+
UserMapping: "USERNAME",
42+
GroupAttributeName: "http://schemas.xmlsoap.org/claims/Group",
43+
GroupRdnKey: " ",
44+
IdpProviderType: "ADFS",
45+
IdpUrl: "https://example.idp.com/app/id/sso/saml/metadata",
46+
EntityId: "saml/metadata",
47+
MetadataFileName: "if MetadataSource is set to URL, remove this field",
48+
OtherProviderTypeName: " ",
49+
FederationMetadataFile: "WlhoaGJYQnNaU0J2WmlCaElHSmhjMlUyTkNCbGJtTnZaR1ZrSUhaaGJHbGtJSEF4TWk0Z2EyVjVjM1J2Y21VZ1ptbHNaUT09",
50+
MetadataSource: "URL",
51+
SessionTimeout: 480,
52+
},
53+
SsoForEnrollmentEnabled: false,
54+
SsoBypassAllowed: false,
55+
SsoEnabled: false,
56+
SsoForMacOsSelfServiceEnabled: false,
57+
EnrollmentSsoForAccountDrivenEnrollmentEnabled: false,
58+
EnrollmentSsoConfig: &jamfpro.EnrollmentSsoConfig{
59+
Hosts: []string{
60+
"dev-12324233.okta.com",
61+
"example.okta.com",
62+
},
63+
ManagementHint: "",
64+
},
65+
GroupEnrollmentAccessEnabled: false,
66+
GroupEnrollmentAccessName: " ",
67+
}
68+
69+
// Update SSO settings
70+
fmt.Println("Updating SSO settings...")
71+
updatedSettings, err := client.UpdateSsoSettings(*updateSettings)
72+
if err != nil {
73+
fmt.Printf("Error updating SSO settings: %v\n", err)
74+
prettyPrintJSON("Request Body:", updateSettings)
75+
return
76+
}
77+
78+
// Print the JSON response for the updated SSO settings
79+
jsonData, err := json.MarshalIndent(updatedSettings, "", " ")
80+
if err != nil {
81+
log.Fatalf("Failed to marshal JSON: %v", err)
82+
}
83+
fmt.Printf("Updated SSO Settings: %s\n", jsonData)
84+
}

0 commit comments

Comments
 (0)