-
Notifications
You must be signed in to change notification settings - Fork 8
/
GetBearerTokenAuthWithUserCredentialConfigFile.go
51 lines (41 loc) · 1.47 KB
/
GetBearerTokenAuthWithUserCredentialConfigFile.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
51
package main
import (
"fmt"
"log"
"github.com/deploymenttheory/go-api-sdk-jamfpro/sdk/http_client"
)
func main() {
// Define the path to the JSON configuration file inside the main function
configFilePath := "/Users/dafyddwatkins/GitHub/deploymenttheory/go-api-sdk-jamfpro/userauth.json"
// Load the client authentication details from the configuration file
authConfig, err := http_client.LoadClientAuthConfig(configFilePath)
if err != nil {
log.Fatalf("Failed to load client authentication configuration: %v", err)
}
// Instantiate the default logger and set the desired log level
logger := http_client.NewDefaultLogger()
logLevel := http_client.LogLevelDebug // LogLevelNone // LogLevelWarning // LogLevelInfo // LogLevelDebug
// Configuration for the jamfpro
config := http_client.Config{
LogLevel: logLevel,
Logger: logger,
}
// Create a new client instance using the loaded InstanceName
client, err := http_client.NewClient(authConfig.InstanceName, config, nil)
if err != nil {
log.Fatalf("Failed to create new client: %v", err)
}
// Set BearerTokenAuthCredentials
client.SetBearerTokenAuthCredentials(http_client.BearerTokenAuthCredentials{
Username: authConfig.Username,
Password: authConfig.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)
}