Skip to content
Snippets Groups Projects
Commit 24f11d0e authored by Rohith's avatar Rohith
Browse files

- fixing the refresh token bug in the forwarding

- adding some extra debugging and logging
parent c03e4e25
No related branches found
No related tags found
No related merge requests found
...@@ -96,7 +96,7 @@ func (r *oauthProxy) forwardProxyHandler() func(*http.Request, *http.Response) { ...@@ -96,7 +96,7 @@ func (r *oauthProxy) forwardProxyHandler() func(*http.Request, *http.Response) {
if state.login { if state.login {
log.WithFields(log.Fields{ log.WithFields(log.Fields{
"username": r.config.ForwardingUsername, "username": r.config.ForwardingUsername,
}).Debugf("requesting access token for user") }).Infof("requesting access token for user")
// step: login into the service // step: login into the service
resp, err := client.UserCredsToken(r.config.ForwardingUsername, r.config.ForwardingPassword) resp, err := client.UserCredsToken(r.config.ForwardingUsername, r.config.ForwardingPassword)
...@@ -127,6 +127,7 @@ func (r *oauthProxy) forwardProxyHandler() func(*http.Request, *http.Response) { ...@@ -127,6 +127,7 @@ func (r *oauthProxy) forwardProxyHandler() func(*http.Request, *http.Response) {
state.identity = identity state.identity = identity
state.expiration = identity.ExpiresAt state.expiration = identity.ExpiresAt
state.wait = true state.wait = true
state.login = false
state.refresh = resp.RefreshToken state.refresh = resp.RefreshToken
log.WithFields(log.Fields{ log.WithFields(log.Fields{
...@@ -139,7 +140,7 @@ func (r *oauthProxy) forwardProxyHandler() func(*http.Request, *http.Response) { ...@@ -139,7 +140,7 @@ func (r *oauthProxy) forwardProxyHandler() func(*http.Request, *http.Response) {
log.WithFields(log.Fields{ log.WithFields(log.Fields{
"subject": state.identity.ID, "subject": state.identity.ID,
"email": state.identity.Email, "email": state.identity.Email,
}).Debugf("access token is about to expiry") }).Infof("access token is about to expiry")
// step: if we a have a refresh token, we need to login again // step: if we a have a refresh token, we need to login again
if state.refresh != "" { if state.refresh != "" {
...@@ -147,7 +148,7 @@ func (r *oauthProxy) forwardProxyHandler() func(*http.Request, *http.Response) { ...@@ -147,7 +148,7 @@ func (r *oauthProxy) forwardProxyHandler() func(*http.Request, *http.Response) {
"subject": state.identity.ID, "subject": state.identity.ID,
"email": state.identity.Email, "email": state.identity.Email,
"expires": state.expiration.Format(time.RFC822Z), "expires": state.expiration.Format(time.RFC822Z),
}).Debugf("attempting to refresh the access token") }).Infof("attempting to refresh the access token")
// step: attempt to refresh the access // step: attempt to refresh the access
token, expiration, err := getRefreshedToken(r.client, state.refresh) token, expiration, err := getRefreshedToken(r.client, state.refresh)
...@@ -173,7 +174,19 @@ func (r *oauthProxy) forwardProxyHandler() func(*http.Request, *http.Response) { ...@@ -173,7 +174,19 @@ func (r *oauthProxy) forwardProxyHandler() func(*http.Request, *http.Response) {
state.wait = true state.wait = true
state.login = false state.login = false
// step: add some debugging
log.WithFields(log.Fields{
"subject": state.identity.ID,
"email": state.identity.Email,
"expires": state.expiration.Format(time.RFC822Z),
}).Infof("successfully refreshed the access token")
} else { } else {
log.WithFields(log.Fields{
"subject": state.identity.ID,
"email": state.identity.Email,
}).Infof("session does not support refresh token, acquiring new token")
// step: we don't have a refresh token, we must perform a login again // step: we don't have a refresh token, we must perform a login again
state.wait = false state.wait = false
state.login = true state.login = true
...@@ -189,6 +202,7 @@ func (r *oauthProxy) forwardProxyHandler() func(*http.Request, *http.Response) { ...@@ -189,6 +202,7 @@ func (r *oauthProxy) forwardProxyHandler() func(*http.Request, *http.Response) {
log.WithFields(log.Fields{ log.WithFields(log.Fields{
"token_expiration": state.expiration.Format(time.RFC822Z), "token_expiration": state.expiration.Format(time.RFC822Z),
"token_renewel": waiting.Format(time.RFC822Z), "token_renewel": waiting.Format(time.RFC822Z),
"duration": duration.String(),
}).Debugf("waiting for expiration of access token") }).Debugf("waiting for expiration of access token")
<-time.After(duration) <-time.After(duration)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment