Stop shadowing GetEmailAddress errors in redeemCode

This commit is contained in:
Nick Meves 2020-09-23 16:04:54 -07:00
parent 3371284a36
commit e0d915cc03
No known key found for this signature in database
GPG Key ID: 93BA8A3CEDCDD1CF
2 changed files with 11 additions and 6 deletions

View File

@ -17,6 +17,7 @@
- [#575](https://github.com/oauth2-proxy/oauth2-proxy/pull/575) Stop accepting legacy SHA1 signed cookies (@NickMeves)
- [#722](https://github.com/oauth2-proxy/oauth2-proxy/pull/722) Validate Redis configuration options at startup (@NickMeves)
- [#791](https://github.com/oauth2-proxy/oauth2-proxy/pull/791) Remove GetPreferredUsername method from provider interface (@NickMeves)
- [#764](https://github.com/oauth2-proxy/oauth2-proxy/pull/764) Document bcrypt encryption for htpasswd (and hide SHA) (@lentzi90)
- [#616](https://github.com/oauth2-proxy/oauth2-proxy/pull/616) Add support to ensure user belongs in required groups when using the OIDC provider (@stefansedich)

View File

@ -296,27 +296,31 @@ func (p *OAuthProxy) GetRedirectURI(host string) string {
return u.String()
}
func (p *OAuthProxy) redeemCode(ctx context.Context, host, code string) (s *sessionsapi.SessionState, err error) {
func (p *OAuthProxy) redeemCode(ctx context.Context, host, code string) (*sessionsapi.SessionState, error) {
if code == "" {
return nil, errors.New("missing code")
}
redirectURI := p.GetRedirectURI(host)
s, err = p.provider.Redeem(ctx, redirectURI, code)
s, err := p.provider.Redeem(ctx, redirectURI, code)
if err != nil {
return
return nil, err
}
if s.Email == "" {
s.Email, err = p.provider.GetEmailAddress(ctx, s)
if err != nil && err.Error() != "not implemented" {
return nil, err
}
}
if s.User == "" {
s.User, err = p.provider.GetUserName(ctx, s)
if err != nil && err.Error() == "not implemented" {
err = nil
if err != nil && err.Error() != "not implemented" {
return nil, err
}
}
return
return s, nil
}
// MakeCSRFCookie creates a cookie for CSRF