forked from baron/baron-sso
Update dev workflow and org chart settings
This commit is contained in:
@@ -21,9 +21,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
defaultWorksmobileAPIBaseURL = "https://www.worksapis.com"
|
||||
defaultWorksmobileOAuthTokenURL = "https://auth.worksmobile.com/oauth2/v2.0/token"
|
||||
defaultWorksmobileOAuthScope = "directory"
|
||||
defaultWorksmobileOAuthScope = "directory"
|
||||
)
|
||||
|
||||
type WorksmobileDirectoryClient interface {
|
||||
@@ -74,9 +72,6 @@ func (c WorksmobileOAuthConfig) normalized() WorksmobileOAuthConfig {
|
||||
c.Scope = defaultWorksmobileOAuthScope
|
||||
}
|
||||
c.TokenURL = strings.TrimSpace(c.TokenURL)
|
||||
if c.TokenURL == "" {
|
||||
c.TokenURL = defaultWorksmobileOAuthTokenURL
|
||||
}
|
||||
return c
|
||||
}
|
||||
|
||||
@@ -87,6 +82,9 @@ func (c WorksmobileOAuthConfig) validate() error {
|
||||
if strings.TrimSpace(c.ServiceAccount) == "" || strings.TrimSpace(c.PrivateKey) == "" {
|
||||
return fmt.Errorf("worksmobile oauth service account is not configured")
|
||||
}
|
||||
if strings.TrimSpace(c.TokenURL) == "" {
|
||||
return fmt.Errorf("worksmobile oauth token url is not configured")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -163,14 +161,12 @@ func (e WorksmobileHTTPError) Error() string {
|
||||
|
||||
func NewWorksmobileHTTPClient(scimToken string) *WorksmobileHTTPClient {
|
||||
return &WorksmobileHTTPClient{
|
||||
BaseURL: defaultWorksmobileAPIBaseURL,
|
||||
SCIMToken: strings.Trim(strings.TrimSpace(scimToken), `"`),
|
||||
}
|
||||
}
|
||||
|
||||
func NewWorksmobileHTTPClientWithTokens(directoryToken string, scimToken string) *WorksmobileHTTPClient {
|
||||
return &WorksmobileHTTPClient{
|
||||
BaseURL: defaultWorksmobileAPIBaseURL,
|
||||
DirectoryToken: strings.Trim(strings.TrimSpace(directoryToken), `"`),
|
||||
SCIMToken: strings.Trim(strings.TrimSpace(scimToken), `"`),
|
||||
}
|
||||
@@ -178,7 +174,6 @@ func NewWorksmobileHTTPClientWithTokens(directoryToken string, scimToken string)
|
||||
|
||||
func NewWorksmobileHTTPClientWithAuth(directoryToken string, scimToken string, oauthConfig WorksmobileOAuthConfig) *WorksmobileHTTPClient {
|
||||
return &WorksmobileHTTPClient{
|
||||
BaseURL: defaultWorksmobileAPIBaseURL,
|
||||
DirectoryToken: strings.Trim(strings.TrimSpace(directoryToken), `"`),
|
||||
SCIMToken: strings.Trim(strings.TrimSpace(scimToken), `"`),
|
||||
OAuthConfig: oauthConfig.normalized(),
|
||||
@@ -437,7 +432,11 @@ func (c *WorksmobileHTTPClient) getJSON(ctx context.Context, path string, target
|
||||
if token == "" {
|
||||
return fmt.Errorf("worksmobile read token is not configured")
|
||||
}
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, strings.TrimRight(c.baseURL(), "/")+path, nil)
|
||||
requestURL, err := c.requestURL(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, requestURL, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -461,7 +460,11 @@ func (c *WorksmobileHTTPClient) getDirectoryJSON(ctx context.Context, path strin
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, strings.TrimRight(c.baseURL(), "/")+path, nil)
|
||||
requestURL, err := c.requestURL(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, requestURL, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -672,7 +675,11 @@ func (c *WorksmobileHTTPClient) sendJSONWithToken(ctx context.Context, method st
|
||||
body = bytes.NewReader(data)
|
||||
}
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, method, strings.TrimRight(c.baseURL(), "/")+path, body)
|
||||
requestURL, err := c.requestURL(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
req, err := http.NewRequestWithContext(ctx, method, requestURL, body)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -1117,12 +1124,17 @@ func boolPointerFromMap(values map[string]any, keys ...string) *bool {
|
||||
}
|
||||
|
||||
func (c *WorksmobileHTTPClient) baseURL() string {
|
||||
if strings.TrimSpace(c.BaseURL) == "" {
|
||||
return defaultWorksmobileAPIBaseURL
|
||||
}
|
||||
return c.BaseURL
|
||||
}
|
||||
|
||||
func (c *WorksmobileHTTPClient) requestURL(path string) (string, error) {
|
||||
baseURL := strings.TrimSpace(c.baseURL())
|
||||
if baseURL == "" {
|
||||
return "", fmt.Errorf("worksmobile api base url is not configured")
|
||||
}
|
||||
return strings.TrimRight(baseURL, "/") + path, nil
|
||||
}
|
||||
|
||||
func (c *WorksmobileHTTPClient) httpClient() *http.Client {
|
||||
if c.HTTPClient != nil {
|
||||
return c.HTTPClient
|
||||
|
||||
Reference in New Issue
Block a user