git.iko.soy/typeable/oauth2-proxy
on master help sign in
Merge branch 'master' into fix-docs-links
commitc941f3ce0de6ac9917afe8dd5cf79cd0f8be4e2f authorHenry Jenkins <henry@henryjenkins.name> dateTue 13 Aug 2019, 21:23 (7 years ago) parent8b615599240538
5 files changed+41−7
CHANGELOG.md+1 docs/configuration/configuration.md+2−2 main.go+2−2 oauthproxy.go+1−1 providers/oidc.go+35−2
CHANGELOG.md+1
@@ -96,6 +96,7 @@
9696- [#159](https://github.com/pusher/oauth2_proxy/pull/159) Add option to skip the OIDC provider verified email check: `--insecure-oidc-allow-unverified-email`
9797- [#210](https://github.com/pusher/oauth2_proxy/pull/210) Update base image from Alpine 3.9 to 3.10 (@steakunderscore)
9898- [#211](https://github.com/pusher/oauth2_proxy/pull/211) Switch from dep to go modules (@steakunderscore)
99+- [#145](https://github.com/pusher/oauth2_proxy/pull/145) Add support for OIDC UserInfo endpoint email verification (@rtluckie)
99100
100101# v3.2.0
101102
docs/configuration/configuration.md+2−2
@@ -82,8 +82,8 @@ Usage of oauth2_proxy:
8282 -redeem-url string: Token redemption endpoint
8383 -redirect-url string: the OAuth Redirect URL. ie: "https://internalapp.yourcompany.com/oauth2/callback"
8484 -redis-connection-url string: URL of redis server for redis session storage (eg: redis://HOST[:PORT])
85− -redis-sentinel-master-name string: Redis sentinel master name. Used in conjuction with --redis-use-sentinel
86− -redis-sentinel-connection-urls: List of Redis sentinel conneciton URLs (eg redis://HOST[:PORT]). Used in conjuction with --redis-use-sentinel
85+ -redis-sentinel-master-name string: Redis sentinel master name. Used in conjunction with --redis-use-sentinel
86+ -redis-sentinel-connection-urls: List of Redis sentinel connection URLs (eg redis://HOST[:PORT]). Used in conjunction with --redis-use-sentinel
8787 -redis-use-sentinel: Connect to redis via sentinels. Must set --redis-sentinel-master-name and --redis-sentinel-connection-urls to use this feature (default: false)
8888 -request-logging: Log requests to stdout (default true)
8989 -request-logging-format: Template for request log lines (see "Logging Configuration" paragraph below)
main.go+2−2
@@ -86,8 +86,8 @@ func main() {
8686 flagSet.String("session-store-type", "cookie", "the session storage provider to use")
8787 flagSet.String("redis-connection-url", "", "URL of redis server for redis session storage (eg: redis://HOST[:PORT])")
8888 flagSet.Bool("redis-use-sentinel", false, "Connect to redis via sentinels. Must set --redis-sentinel-master-name and --redis-sentinel-connection-urls to use this feature")
89− flagSet.String("redis-sentinel-master-name", "", "Redis sentinel master name. Used in conjuction with --redis-use-sentinel")
90− flagSet.Var(&redisSentinelConnectionURLs, "redis-sentinel-connection-urls", "List of Redis sentinel connection URLs (eg redis://HOST[:PORT]). Used in conjuction with --redis-use-sentinel")
89+ flagSet.String("redis-sentinel-master-name", "", "Redis sentinel master name. Used in conjunction with --redis-use-sentinel")
90+ flagSet.Var(&redisSentinelConnectionURLs, "redis-sentinel-connection-urls", "List of Redis sentinel connection URLs (eg redis://HOST[:PORT]). Used in conjunction with --redis-use-sentinel")
9191
9292 flagSet.String("logging-filename", "", "File to log requests to, empty for stdout")
9393 flagSet.Int("logging-max-size", 100, "Maximum size in megabytes of the log file before rotation")
oauthproxy.go+1−1
@@ -898,7 +898,7 @@ func isAjax(req *http.Request) bool {
898898 return false
899899}
900900
901−// ErrorJSON returns the error code witht an application/json mime type
901+// ErrorJSON returns the error code with an application/json mime type
902902func (p *OAuthProxy) ErrorJSON(rw http.ResponseWriter, code int) {
903903 rw.Header().Set("Content-Type", applicationJSON)
904904 rw.WriteHeader(code)
providers/oidc.go+35−2
@@ -3,10 +3,13 @@ package providers
33import (
44 "context"
55 "fmt"
6+ "net/http"
67 "time"
78
89 oidc "github.com/coreos/go-oidc"
910 "github.com/pusher/oauth2_proxy/pkg/apis/sessions"
11+ "github.com/pusher/oauth2_proxy/pkg/requests"
12+
1013 "golang.org/x/oauth2"
1114)
1215
@@ -117,8 +120,31 @@ func (p *OIDCProvider) createSessionState(ctx context.Context, token *oauth2.Tok
117120 }
118121
119122 if claims.Email == "" {
120− // TODO: Try getting email from /userinfo before falling back to Subject
121− claims.Email = claims.Subject
123+ if p.ProfileURL.String() == "" {
124+ return nil, fmt.Errorf("id_token did not contain an email")
125+ }
126+
127+ // If the userinfo endpoint profileURL is defined, then there is a chance the userinfo
128+ // contents at the profileURL contains the email.
129+ // Make a query to the userinfo endpoint, and attempt to locate the email from there.
130+
131+ req, err := http.NewRequest("GET", p.ProfileURL.String(), nil)
132+ if err != nil {
133+ return nil, err
134+ }
135+ req.Header = getOIDCHeader(token.AccessToken)
136+
137+ respJSON, err := requests.Request(req)
138+ if err != nil {
139+ return nil, err
140+ }
141+
142+ email, err := respJSON.Get("email").String()
143+ if err != nil {
144+ return nil, fmt.Errorf("Neither id_token nor userinfo endpoint contained an email")
145+ }
146+
147+ claims.Email = email
122148 }
123149 if !p.AllowUnverifiedEmail && claims.Verified != nil && !*claims.Verified {
124150 return nil, fmt.Errorf("email in id_token (%s) isn't verified", claims.Email)
@@ -145,3 +171,10 @@ func (p *OIDCProvider) ValidateSessionState(s *sessions.SessionState) bool {
145171
146172 return true
147173}
174+
175+func getOIDCHeader(accessToken string) http.Header {
176+ header := make(http.Header)
177+ header.Set("Accept", "application/json")
178+ header.Set("Authorization", fmt.Sprintf("Bearer %s", accessToken))
179+ return header
180+}