diff --git a/agent.go b/agent.go index 02f55ff..7f52482 100644 --- a/agent.go +++ b/agent.go @@ -114,27 +114,15 @@ func (a *Agent) callbackHandler(w http.ResponseWriter, r *http.Request) { http.Redirect(w, r, rootURL, 302) } +// renewHandler will initiate the auth challenge. Leases renewal will be handled +// in the callback handler. func (a *Agent) renewHandler(w http.ResponseWriter, r *http.Request) { - token, err := a.oa.getTokenFromFile() - if err != nil || token.AccessToken == "" || token.Expiry.Before(time.Now()) { - logger.Errorf("cannot get a valid cached token, need a new one") - // Get a url for the token challenge and redirect there - url, err := a.oa.prepareTokenWebChalenge(w) - if err != nil { - fmt.Fprintf( - w, - "error creating web url to get token: %v", - err, - ) - return - } - http.Redirect(w, r, url, 302) + url, err := a.oa.prepareTokenWebChalenge(w) + if err != nil { + fmt.Fprintf(w, "error creating web url to get token: %v", err) return } - a.renewAllLeases(token.AccessToken) - // Redirect to / after renewing leases - rootURL := fmt.Sprintf("http://%s/", r.Host) - http.Redirect(w, r, rootURL, 302) + http.Redirect(w, r, url, 302) } func (a *Agent) mainHandler(w http.ResponseWriter, r *http.Request) { diff --git a/agent_http.go b/agent_http.go index b6f402e..ba0c02a 100644 --- a/agent_http.go +++ b/agent_http.go @@ -54,7 +54,7 @@ var htmlStatusTemplate = `
No token found, please hit Renew Leases button bellow.
+No token found, please hit Renew button below.
{{else}} {{ if .TokenActive }}Active until: {{.TokenExpiry}}
@@ -63,8 +63,9 @@ var htmlStatusTemplate = `Please use renew button bellow.
{{end}} {{end}} + Fetches a new token before renewing leases.