-
Notifications
You must be signed in to change notification settings - Fork 5
/
GetBearerTokenAuthWithUserCredentials.go
50 lines (41 loc) · 1.26 KB
/
GetBearerTokenAuthWithUserCredentials.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package main
import (
"fmt"
"log"
"github.com/deploymenttheory/go-api-sdk-jamfpro/sdk/http_client"
)
func main() {
// Manually set your client credentials
username := "your-jamf-api-account"
password := "your-jamf-api-account-password"
instanceName := "your-jamf-instance" // e.g., "yourcompany.jamfcloud.com"
// Instantiate the default logger and set the desired log level
logLevel := http_client.LogLevelDebug // LogLevelNone // LogLevelWarning // LogLevelInfo // LogLevelDebug
// Configuration for the jamfpro
config := http_client.Config{
InstanceName: instanceName,
LogLevel: logLevel,
Auth: http_client.AuthConfig{
Username: username,
Password: password,
},
}
// Create a new client instance using the provided BaseURL
client, err := http_client.NewClient(config)
if err != nil {
log.Fatalf("Failed to create new client: %v", err)
}
// Set BearerTokenAuthCredentials
client.SetBearerTokenAuthCredentials(http_client.BearerTokenAuthCredentials{
Username: username,
Password: password,
})
// Call the ObtainToken function to get a bearer token
err = client.ObtainToken()
if err != nil {
fmt.Println("Error obtaining token:", err)
return
}
// Print the obtained token
fmt.Println("Successfully obtained token:", client.Token)
}