Skip to content

Commit

Permalink
oidc: Fix the way we call UserInfo
Browse files Browse the repository at this point in the history
The UserInfo endpoint is called with an OAuth2 access token. The access
token expires after a while and then we must renew it with the refresh
token. Update the code so that it takes care of renewing the access
token.

Closes #32
Github-PR: #31

Signed-off-by: Yannis Zarkadas <[email protected]>
  • Loading branch information
yanniszark authored and apyrgio committed Jul 13, 2020
1 parent ad88556 commit 7154591
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (s *server) authenticate(w http.ResponseWriter, r *http.Request) {
// Check if the OAuth token has expired and if it has, delete the
// user's session
var reqErr *requestError
if errors.As(err, reqErr) && reqErr.StatusCode == http.StatusUnauthorized {
if errors.As(err, &reqErr) && reqErr.StatusCode == http.StatusUnauthorized {
logger.Warn("UserInfo token has expired")
session.Options.MaxAge = -1
if err := sessions.Save(r, w); err != nil {
Expand Down Expand Up @@ -187,7 +187,7 @@ func (s *server) callback(w http.ResponseWriter, r *http.Request) {

// UserInfo endpoint to get claims
claims := map[string]interface{}{}
userInfo, err := GetUserInfo(ctx, s.provider, oauth2.StaticTokenSource(oauth2Tokens))
userInfo, err := GetUserInfo(ctx, s.provider, s.oauth2Config.TokenSource(ctx, oauth2Tokens))
if err != nil {
logger.Errorf("Not able to fetch userinfo: %v", err)
returnMessage(w, http.StatusInternalServerError, "Not able to fetch userinfo.")
Expand Down

0 comments on commit 7154591

Please sign in to comment.