Skip to content
This repository was archived by the owner on Dec 7, 2020. It is now read-only.

Commit 0395e26

Browse files
author
Bruno Oliveira da Silva
committed
Update OAuth2 dependency #518
- package "crypto/rand" is being imported twice - Remove unused reference - Upgrade to golang/x/oauth2 Resolves #518
1 parent b48a022 commit 0395e26

File tree

12 files changed

+142
-123
lines changed

12 files changed

+142
-123
lines changed

doc.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -438,10 +438,10 @@ type userContext struct {
438438

439439
// tokenResponse
440440
type tokenResponse struct {
441-
TokenType string `json:"token_type"`
442-
AccessToken string `json:"access_token"`
443-
IDToken string `json:"id_token"`
444-
RefreshToken string `json:"refresh_token,omitempty"`
445-
ExpiresIn int `json:"expires_in"`
446-
Scope string `json:"scope,omitempty"`
441+
TokenType string `json:"token_type"`
442+
AccessToken string `json:"access_token"`
443+
IDToken string `json:"id_token"`
444+
RefreshToken string `json:"refresh_token,omitempty"`
445+
ExpiresIn float64 `json:"expires_in"`
446+
Scope string `json:"scope,omitempty"`
447447
}

forwarding.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ limitations under the License.
1616
package main
1717

1818
import (
19+
"context"
1920
"fmt"
2021
"net/http"
2122
"time"
@@ -86,10 +87,9 @@ func (r *oauthProxy) proxyMiddleware(next http.Handler) http.Handler {
8687

8788
// forwardProxyHandler is responsible for signing outbound requests
8889
func (r *oauthProxy) forwardProxyHandler() func(*http.Request, *http.Response) {
89-
client, err := r.client.OAuthClient()
90-
if err != nil {
91-
r.log.Fatal("failed to create oauth client", zap.Error(err))
92-
}
90+
ctx := context.Background()
91+
conf := r.newOAuth2Config(r.config.RedirectionURL)
92+
9393
// the loop state
9494
var state struct {
9595
// the access token
@@ -118,7 +118,7 @@ func (r *oauthProxy) forwardProxyHandler() func(*http.Request, *http.Response) {
118118
zap.String("username", r.config.ForwardingUsername))
119119

120120
// step: login into the service
121-
resp, err := client.UserCredsToken(r.config.ForwardingUsername, r.config.ForwardingPassword)
121+
resp, err := conf.PasswordCredentialsToken(ctx, r.config.ForwardingUsername, r.config.ForwardingPassword)
122122
if err != nil {
123123
r.log.Error("failed to login to authentication service", zap.Error(err))
124124
// step: back-off and reschedule
@@ -160,7 +160,7 @@ func (r *oauthProxy) forwardProxyHandler() func(*http.Request, *http.Response) {
160160
zap.String("expires", state.expiration.Format(time.RFC3339)))
161161

162162
// step: attempt to refresh the access
163-
token, newRefreshToken, expiration, _, err := getRefreshedToken(r.client, state.refresh)
163+
token, newRefreshToken, expiration, _, err := getRefreshedToken(conf, state.refresh)
164164
if err != nil {
165165
state.login = true
166166
switch err {

go.mod

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,18 @@ require (
1919
github.com/onsi/ginkgo v1.8.0 // indirect
2020
github.com/onsi/gomega v1.5.0 // indirect
2121
github.com/pkg/errors v0.8.1 // indirect
22-
github.com/pmezard/go-difflib v1.0.0 // indirect
2322
github.com/prometheus/client_golang v0.9.2
2423
github.com/rs/cors v1.6.0
25-
github.com/stretchr/testify v1.2.2
24+
github.com/stretchr/testify v1.5.1
2625
github.com/unrolled/secure v0.0.0-20181221173256-0d6b5bb13069
2726
github.com/urfave/cli v0.0.0-20181029213200-b67dcf995b6a
2827
go.etcd.io/bbolt v1.3.3 // indirect
2928
go.uber.org/atomic v1.3.2 // indirect
3029
go.uber.org/multierr v1.1.0 // indirect
3130
go.uber.org/zap v1.9.1
32-
golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9
33-
golang.org/x/net v0.0.0-20181201002055-351d144fa1fc
31+
golang.org/x/crypto v0.0.0-20190911031432-227b76d455e7
32+
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3
33+
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d
3434
golang.org/x/sys v0.0.0-20200302083256-062a44052db1 // indirect
3535
gopkg.in/bsm/ratelimit.v1 v1.0.0-20160220154919-db14e161995a // indirect
3636
gopkg.in/redis.v4 v4.2.4

go.sum

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
12
github.com/PuerkitoBio/purell v1.1.0 h1:rmGxhojJlM0tuKtfdvliR84CFHljx9ag64t2xmVkjK4=
23
github.com/PuerkitoBio/purell v1.1.0/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0=
34
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 h1:d+Bc7a5rLufV/sSk/8dngufqelfh6jnri85riMAaF/M=
@@ -12,6 +13,7 @@ github.com/coreos/go-oidc v0.0.0-20171020180921-e860bd55bfa7 h1:UeXD8Kli+SWhDlj1
1213
github.com/coreos/go-oidc v0.0.0-20171020180921-e860bd55bfa7/go.mod h1:CgnwVTmzoESiwO9qyAFEMiHoZ1nMCKZlZ9V6mm3/LKc=
1314
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f h1:lBNOc5arjvs8E5mO2tbpBpLoyyu8B6e44T7hJy6potg=
1415
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
16+
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
1517
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
1618
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
1719
github.com/elazarl/goproxy v0.0.0-20181111060418-2ce16c963a8a h1:A4wNiqeKqU56ZhtnzJCTyPZ1+cyu8jKtIchQ3TtxHgw=
@@ -55,8 +57,9 @@ github.com/prometheus/procfs v0.0.0-20181204211112-1dc9a6cbc91a h1:9a8MnZMP0X2nL
5557
github.com/prometheus/procfs v0.0.0-20181204211112-1dc9a6cbc91a/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
5658
github.com/rs/cors v1.6.0 h1:G9tHG9lebljV9mfp9SNPDL36nCDxmo3zTlAf1YgvzmI=
5759
github.com/rs/cors v1.6.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU=
58-
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
59-
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
60+
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
61+
github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4=
62+
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
6063
github.com/unrolled/secure v0.0.0-20181221173256-0d6b5bb13069 h1:RKeYksgIwGE8zFJTvXI1WWx09QPrGyaVFMy0vpU7j/o=
6164
github.com/unrolled/secure v0.0.0-20181221173256-0d6b5bb13069/go.mod h1:mnPT77IAdsi/kV7+Es7y+pXALeV3h7G6dQF6mNYjcLA=
6265
github.com/urfave/cli v0.0.0-20181029213200-b67dcf995b6a h1:qzVPM2q9ifOxaIVx4kyJvCHXsMNDTLgzu/29aqIuyB8=
@@ -69,20 +72,31 @@ go.uber.org/multierr v1.1.0 h1:HoEmRHQPVSqub6w2z2d2EOVs2fjyFRGyofhKuyDq0QI=
6972
go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
7073
go.uber.org/zap v1.9.1 h1:XCJQEf3W6eZaVwhRBof6ImoYGJSITeKWsyeh3HFu/5o=
7174
go.uber.org/zap v1.9.1/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
72-
golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9 h1:mKdxBk7AujPs8kU4m80U72y/zjbZ3UcXC7dClwKbUI0=
73-
golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
75+
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
76+
golang.org/x/crypto v0.0.0-20190911031432-227b76d455e7 h1:0hQKqeLdqlt5iIwVOBErRisrHJAN57yOiPRQItI20fU=
77+
golang.org/x/crypto v0.0.0-20190911031432-227b76d455e7/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
78+
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
7479
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
7580
golang.org/x/net v0.0.0-20181011144130-49bb7cea24b1/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
7681
golang.org/x/net v0.0.0-20181201002055-351d144fa1fc h1:a3CU5tJYVj92DY2LaA1kUkrsqD5/3mLDhx2NcNqyW+0=
7782
golang.org/x/net v0.0.0-20181201002055-351d144fa1fc/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
83+
golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
84+
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
85+
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d h1:TzXSXBo42m9gQenoE3b9BGiEpg5IG2JkU5FkPIawgtw=
86+
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
7887
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
7988
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f h1:Bl/8QSvNqXvPGPGXa2z5xUTmV7VDcZyvRZ+QQXkXTZQ=
8089
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
90+
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
8191
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
92+
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
93+
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
8294
golang.org/x/sys v0.0.0-20200302083256-062a44052db1 h1:trYYa2hBaTeei9Bq2uAXwsfNYW4r+xD/tztngRsT0cQ=
8395
golang.org/x/sys v0.0.0-20200302083256-062a44052db1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
8496
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
8597
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
98+
google.golang.org/appengine v1.4.0 h1:/wp5JvzpHIxhs/dumFmF7BXTf3Z+dd4uXta4kVyO508=
99+
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
86100
gopkg.in/bsm/ratelimit.v1 v1.0.0-20160220154919-db14e161995a h1:stTHdEoWg1pQ8riaP5ROrjS6zy6wewH/Q2iwnLCQUXY=
87101
gopkg.in/bsm/ratelimit.v1 v1.0.0-20160220154919-db14e161995a/go.mod h1:KF9sEfUPAXdG8Oev9e99iLGnl2uJMjc5B+4y3O7x610=
88102
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=

handlers.go

Lines changed: 41 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package main
1717

1818
import (
1919
"bytes"
20+
"context"
2021
"encoding/base64"
2122
"encoding/json"
2223
"errors"
@@ -31,8 +32,8 @@ import (
3132
"strings"
3233
"time"
3334

34-
"github.com/coreos/go-oidc/oauth2"
3535
"github.com/coreos/go-oidc/oidc"
36+
"golang.org/x/oauth2"
3637

3738
"github.com/go-chi/chi"
3839
"go.uber.org/zap"
@@ -72,22 +73,17 @@ func (r *oauthProxy) oauthAuthorizationHandler(w http.ResponseWriter, req *http.
7273
w.WriteHeader(http.StatusNotAcceptable)
7374
return
7475
}
75-
client, err := r.getOAuthClient(r.getRedirectionURL(w, req), getClientAuthMethod(r.config.ClientAuthMethod))
76-
if err != nil {
77-
r.log.Error("failed to retrieve the oauth client for authorization", zap.Error(err))
78-
w.WriteHeader(http.StatusInternalServerError)
79-
return
80-
}
76+
conf := r.newOAuth2Config(r.getRedirectionURL(w, req))
8177

8278
// step: set the access type of the session
83-
var accessType string
79+
accessType := oauth2.AccessTypeOnline
8480
if containedIn("offline", r.config.Scopes) {
85-
accessType = "offline"
81+
accessType = oauth2.AccessTypeOffline
8682
}
8783

88-
authURL := client.AuthCodeURL(req.URL.Query().Get("state"), accessType, "")
84+
authURL := conf.AuthCodeURL(req.URL.Query().Get("state"), accessType)
8985
r.log.Debug("incoming authorization request from client address",
90-
zap.String("access_type", accessType),
86+
zap.Any("access_type", accessType),
9187
zap.String("auth_url", authURL),
9288
zap.String("client_ip", req.RemoteAddr))
9389

@@ -104,18 +100,6 @@ func (r *oauthProxy) oauthAuthorizationHandler(w http.ResponseWriter, req *http.
104100
r.redirectToURL(authURL, w, req, http.StatusSeeOther)
105101
}
106102

107-
// getClientAuthMethod maps the config value CLIENT_AUTH_METHOD to valid OAuth2 auth method keys
108-
func getClientAuthMethod(authMethod string) string {
109-
switch authMethod {
110-
case authMethodBasic:
111-
return oauth2.AuthMethodClientSecretBasic
112-
case authMethodBody:
113-
return oauth2.AuthMethodClientSecretPost
114-
default:
115-
return ""
116-
}
117-
}
118-
119103
// oauthCallbackHandler is responsible for handling the response from oauth service
120104
func (r *oauthProxy) oauthCallbackHandler(w http.ResponseWriter, req *http.Request) {
121105
if r.config.SkipTokenVerification {
@@ -129,14 +113,9 @@ func (r *oauthProxy) oauthCallbackHandler(w http.ResponseWriter, req *http.Reque
129113
return
130114
}
131115

132-
client, err := r.getOAuthClient(r.getRedirectionURL(w, req), getClientAuthMethod(r.config.ClientAuthMethod))
133-
if err != nil {
134-
r.log.Error("unable to create a oauth2 client", zap.Error(err))
135-
w.WriteHeader(http.StatusInternalServerError)
136-
return
137-
}
116+
conf := r.newOAuth2Config(r.getRedirectionURL(w, req))
138117

139-
resp, err := exchangeAuthenticationCode(client, code)
118+
resp, err := exchangeAuthenticationCode(conf, code)
140119
if err != nil {
141120
r.log.Error("unable to exchange code for access token", zap.Error(err))
142121
r.accessForbidden(w, req)
@@ -146,12 +125,20 @@ func (r *oauthProxy) oauthCallbackHandler(w http.ResponseWriter, req *http.Reque
146125
// Flow: once we exchange the authorization code we parse the ID Token; we then check for an access token,
147126
// if an access token is present and we can decode it, we use that as the session token, otherwise we default
148127
// to the ID Token.
149-
token, identity, err := parseToken(resp.IDToken)
128+
rawIDToken, ok := resp.Extra("id_token").(string)
129+
if !ok {
130+
r.log.Error("unable to obtain id token", zap.Error(err))
131+
r.accessForbidden(w, req)
132+
return
133+
}
134+
135+
token, identity, err := parseToken(rawIDToken)
150136
if err != nil {
151137
r.log.Error("unable to parse id token for identity", zap.Error(err))
152138
r.accessForbidden(w, req)
153139
return
154140
}
141+
155142
access, id, err := parseToken(resp.AccessToken)
156143
if err == nil {
157144
token = access
@@ -195,7 +182,7 @@ func (r *oauthProxy) oauthCallbackHandler(w http.ResponseWriter, req *http.Reque
195182
return
196183
}
197184
// drop in the access token - cookie expiration = access token
198-
r.dropAccessTokenCookie(req, w, accessToken, r.getAccessCookieExpiration(token, resp.RefreshToken))
185+
r.dropAccessTokenCookie(req, w, accessToken, r.getAccessCookieExpiration(resp.RefreshToken))
199186

200187
var expiration time.Duration
201188
// notes: not all idp refresh tokens are readable, google for example, so we attempt to decode into
@@ -235,6 +222,8 @@ func (r *oauthProxy) oauthCallbackHandler(w http.ResponseWriter, req *http.Reque
235222
// loginHandler provide's a generic endpoint for clients to perform a user_credentials login to the provider
236223
func (r *oauthProxy) loginHandler(w http.ResponseWriter, req *http.Request) {
237224
errorMsg, code, err := func() (string, int, error) {
225+
ctx := context.Background()
226+
238227
if !r.config.EnableLoginHandler {
239228
return "attempt to login when login handler is disabled", http.StatusNotImplemented, errors.New("login handler disabled")
240229
}
@@ -244,15 +233,13 @@ func (r *oauthProxy) loginHandler(w http.ResponseWriter, req *http.Request) {
244233
return "request does not have both username and password", http.StatusBadRequest, errors.New("no credentials")
245234
}
246235

247-
client, err := r.client.OAuthClient()
248-
if err != nil {
249-
return "unable to create the oauth client for user_credentials request", http.StatusInternalServerError, err
250-
}
236+
conf := r.newOAuth2Config(r.getRedirectionURL(w, req))
251237

252238
start := time.Now()
253-
token, err := client.UserCredsToken(username, password)
239+
token, err := conf.PasswordCredentialsToken(ctx, username, password)
240+
254241
if err != nil {
255-
if strings.HasPrefix(err.Error(), oauth2.ErrorInvalidGrant) {
242+
if !token.Valid() {
256243
return "invalid user credentials provided", http.StatusUnauthorized, err
257244
}
258245
return "unable to request the access token via grant_type 'password'", http.StatusInternalServerError, err
@@ -271,12 +258,21 @@ func (r *oauthProxy) loginHandler(w http.ResponseWriter, req *http.Request) {
271258
oauthTokensMetric.WithLabelValues("login").Inc()
272259

273260
w.Header().Set("Content-Type", "application/json")
261+
idToken, ok := token.Extra("id_token").(string)
262+
if !ok {
263+
return "", http.StatusInternalServerError, fmt.Errorf("token response does not contain an id_token")
264+
}
265+
expiresIn, ok := token.Extra("expires_in").(float64)
266+
if !ok {
267+
return "", http.StatusInternalServerError, fmt.Errorf("token response does not contain expires_in")
268+
}
269+
scope, _ := token.Extra("scope").(string)
274270
if err := json.NewEncoder(w).Encode(tokenResponse{
275-
IDToken: token.IDToken,
271+
IDToken: idToken,
276272
AccessToken: token.AccessToken,
277273
RefreshToken: token.RefreshToken,
278-
ExpiresIn: token.Expires,
279-
Scope: token.Scope,
274+
ExpiresIn: expiresIn,
275+
Scope: scope,
280276
}); err != nil {
281277
return "", http.StatusInternalServerError, err
282278
}
@@ -321,6 +317,7 @@ func (r *oauthProxy) logoutHandler(w http.ResponseWriter, req *http.Request) {
321317

322318
// step: can either use the id token or the refresh token
323319
identityToken := user.token.Encode()
320+
//nolint:vetshadow
324321
if refresh, _, err := r.retrieveRefreshToken(req, user); err == nil {
325322
identityToken = refresh
326323
}
@@ -332,7 +329,7 @@ func (r *oauthProxy) logoutHandler(w http.ResponseWriter, req *http.Request) {
332329
// step: check if the user has a state session and if so revoke it
333330
if r.useStore() {
334331
go func() {
335-
if err := r.DeleteRefreshToken(user.token); err != nil {
332+
if err = r.DeleteRefreshToken(user.token); err != nil {
336333
r.log.Error("unable to remove the refresh token from store", zap.Error(err))
337334
}
338335
}()
@@ -366,13 +363,12 @@ func (r *oauthProxy) logoutHandler(w http.ResponseWriter, req *http.Request) {
366363

367364
// step: do we have a revocation endpoint?
368365
if revocationURL != "" {
369-
client, err := r.client.OAuthClient()
366+
client := &http.Client{Timeout: 5 * time.Second}
370367
if err != nil {
371368
r.log.Error("unable to retrieve the openid client", zap.Error(err))
372369
w.WriteHeader(http.StatusInternalServerError)
373370
return
374371
}
375-
376372
// step: add the authentication headers
377373
encodedID := url.QueryEscape(r.config.ClientID)
378374
encodedSecret := url.QueryEscape(r.config.ClientSecret)
@@ -390,7 +386,7 @@ func (r *oauthProxy) logoutHandler(w http.ResponseWriter, req *http.Request) {
390386
request.Header.Set("Content-Type", "application/x-www-form-urlencoded")
391387

392388
start := time.Now()
393-
response, err := client.HttpClient().Do(request)
389+
response, err := client.Do(request)
394390
if err != nil {
395391
r.log.Error("unable to post to revocation endpoint", zap.Error(err))
396392
return

middleware.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,8 @@ func (r *oauthProxy) authenticationMiddleware() func(http.Handler) http.Handler
241241
//
242242
// exp: expiration of the access token
243243
// expiresIn: expiration of the ID token
244-
token, newRefreshToken, accessExpiresAt, refreshExpiresIn, err := getRefreshedToken(r.client, refresh)
244+
conf := r.newOAuth2Config(r.config.RedirectionURL)
245+
token, newRefreshToken, accessExpiresAt, refreshExpiresIn, err := getRefreshedToken(conf, refresh)
245246
if err != nil {
246247
switch err {
247248
case ErrRefreshTokenExpired:
@@ -266,7 +267,7 @@ func (r *oauthProxy) authenticationMiddleware() func(http.Handler) http.Handler
266267
}
267268
if refreshExpiresIn == 0 {
268269
// refresh token expiry claims not available: try to parse refresh token
269-
refreshExpiresIn = r.getAccessCookieExpiration(token, refresh)
270+
refreshExpiresIn = r.getAccessCookieExpiration(refresh)
270271
}
271272

272273
r.log.Info("injecting the refreshed access token cookie",

misc.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323
"strings"
2424
"time"
2525

26-
"github.com/coreos/go-oidc/jose"
2726
"go.uber.org/zap"
2827
)
2928

@@ -113,7 +112,7 @@ func (r *oauthProxy) redirectToAuthorization(w http.ResponseWriter, req *http.Re
113112
}
114113

115114
// getAccessCookieExpiration calculates the expiration of the access token cookie
116-
func (r *oauthProxy) getAccessCookieExpiration(token jose.JWT, refresh string) time.Duration {
115+
func (r *oauthProxy) getAccessCookieExpiration(refresh string) time.Duration {
117116
// notes: by default the duration of the access token will be the configuration option, if
118117
// however we can decode the refresh token, we will set the duration to the duration of the
119118
// refresh token

0 commit comments

Comments
 (0)