Skip to content

Commit

Permalink
removal of debug, small logic updates, bugfix on bad token req login …
Browse files Browse the repository at this point in the history
…in oauth
  • Loading branch information
thejoeker12 committed Jun 21, 2024
1 parent aec2c78 commit 9766ac4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 22 deletions.
13 changes: 3 additions & 10 deletions jamf/jamfprointegration/auth_basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type basicAuth struct {
logger logger.Logger

// Computed
basicToken string
// basicToken string
bearerToken string
bearerTokenExpiryTime time.Time
}
Expand Down Expand Up @@ -119,11 +119,7 @@ func (a *basicAuth) tokenExpired() bool {
// Returns:
// - bool: True if the bearer token is within the buffer period, false otherwise.
func (a *basicAuth) tokenInBuffer() bool {
if time.Until(a.bearerTokenExpiryTime) <= a.bufferPeriod {
return true
}

return false
return time.Until(a.bearerTokenExpiryTime) <= a.bufferPeriod
}

// tokenEmpty checks if the current bearer token is empty.
Expand All @@ -132,8 +128,5 @@ func (a *basicAuth) tokenInBuffer() bool {
// Returns:
// - bool: True if the bearer token is empty, false otherwise.
func (a *basicAuth) tokenEmpty() bool {
if a.bearerToken == "" {
return true
}
return false
return a.bearerToken == ""
}
16 changes: 4 additions & 12 deletions jamf/jamfprointegration/auth_oauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,10 @@ func (a *oauth) getNewToken() error {
return err
}

if resp.StatusCode < 200 && resp.StatusCode > 299 {
return fmt.Errorf("bad request: %v", resp)
if resp.StatusCode < 200 || resp.StatusCode > 299 {
return fmt.Errorf("bad request getting auth token: %v", resp)
}

return fmt.Errorf("ERROR CODE: %v", resp.StatusCode)

defer resp.Body.Close()

bodyBytes, err := io.ReadAll(resp.Body)
Expand Down Expand Up @@ -104,18 +102,12 @@ func (a *oauth) getExpiryTime() time.Time {

// TODO migrate strings
func (a *oauth) tokenExpired() bool {
if a.expiryTime.Before(time.Now()) {
return true
}
return false
return a.expiryTime.Before(time.Now())
}

// TODO migrate strings
func (a *oauth) tokenInBuffer() bool {
if time.Until(a.expiryTime) <= a.bufferPeriod {
return true
}
return false
return time.Until(a.expiryTime) <= a.bufferPeriod
}

// TODO migrate strings
Expand Down

0 comments on commit 9766ac4

Please sign in to comment.