Skip to content
This repository has been archived by the owner on Sep 8, 2020. It is now read-only.

Commit

Permalink
Pass the raw token along in the Authorization header
Browse files Browse the repository at this point in the history
This makes it work with the kubernetes dashboard.
  • Loading branch information
benley committed Jun 3, 2017
1 parent 2b23bcc commit 5a27234
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
1 change: 1 addition & 0 deletions oauthproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,7 @@ func (p *OAuthProxy) Authenticate(rw http.ResponseWriter, req *http.Request) int
}
if p.PassAccessToken && session.AccessToken != "" {
req.Header["X-Forwarded-Access-Token"] = []string{session.AccessToken}
req.Header["Authorization"] = []string{"Bearer " + session.RawIDToken}
}
if session.Email == "" {
rw.Header().Set("GAP-Auth", session.User)
Expand Down
1 change: 1 addition & 0 deletions providers/oidc.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ func (p *OIDCProvider) Redeem(redirectURL, code string) (s *SessionState, err er
RefreshToken: token.RefreshToken,
ExpiresOn: token.Expiry,
Email: claims.Email,
RawIDToken: rawIDToken,
}

return
Expand Down
21 changes: 18 additions & 3 deletions providers/session_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type SessionState struct {
RefreshToken string
Email string
User string
RawIDToken string
}

func (s *SessionState) IsExpired() bool {
Expand Down Expand Up @@ -72,7 +73,14 @@ func (s *SessionState) EncryptedString(c *cookie.Cipher) (string, error) {
return "", err
}
}
return fmt.Sprintf("%s|%s|%d|%s", s.userOrEmail(), a, s.ExpiresOn.Unix(), r), nil
rawIDToken := s.RawIDToken
if rawIDToken != "" {
rawIDToken, err = c.Encrypt(rawIDToken)
if err != nil {
return "", err
}
}
return fmt.Sprintf("%s|%s|%d|%s|%s", s.userOrEmail(), a, s.ExpiresOn.Unix(), r, rawIDToken), nil
}

func DecodeSessionState(v string, c *cookie.Cipher) (s *SessionState, err error) {
Expand All @@ -85,8 +93,8 @@ func DecodeSessionState(v string, c *cookie.Cipher) (s *SessionState, err error)
return &SessionState{User: v}, nil
}

if len(chunks) != 4 {
err = fmt.Errorf("invalid number of fields (got %d expected 4)", len(chunks))
if len(chunks) != 5 {
err = fmt.Errorf("invalid number of fields (got %d expected 5)", len(chunks))
return
}

Expand All @@ -111,5 +119,12 @@ func DecodeSessionState(v string, c *cookie.Cipher) (s *SessionState, err error)
}
ts, _ := strconv.Atoi(chunks[2])
s.ExpiresOn = time.Unix(int64(ts), 0)

if c != nil && chunks[4] != "" {
s.RawIDToken, err = c.Decrypt(chunks[4])
if err != nil {
return nil, err
}
}
return
}

0 comments on commit 5a27234

Please sign in to comment.