Merge branch 'master' into fix-docs-links
This commit is contained in:
		
						commit
						c941f3ce0d
					
				|  | @ -96,6 +96,7 @@ | ||||||
| - [#159](https://github.com/pusher/oauth2_proxy/pull/159) Add option to skip the OIDC provider verified email check: `--insecure-oidc-allow-unverified-email` | - [#159](https://github.com/pusher/oauth2_proxy/pull/159) Add option to skip the OIDC provider verified email check: `--insecure-oidc-allow-unverified-email` | ||||||
| - [#210](https://github.com/pusher/oauth2_proxy/pull/210) Update base image from Alpine 3.9 to 3.10 (@steakunderscore) | - [#210](https://github.com/pusher/oauth2_proxy/pull/210) Update base image from Alpine 3.9 to 3.10 (@steakunderscore) | ||||||
| - [#211](https://github.com/pusher/oauth2_proxy/pull/211) Switch from dep to go modules (@steakunderscore) | - [#211](https://github.com/pusher/oauth2_proxy/pull/211) Switch from dep to go modules (@steakunderscore) | ||||||
|  | - [#145](https://github.com/pusher/oauth2_proxy/pull/145) Add support for OIDC UserInfo endpoint email verification (@rtluckie) | ||||||
| 
 | 
 | ||||||
| # v3.2.0 | # v3.2.0 | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -82,8 +82,8 @@ Usage of oauth2_proxy: | ||||||
|   -redeem-url string: Token redemption endpoint |   -redeem-url string: Token redemption endpoint | ||||||
|   -redirect-url string: the OAuth Redirect URL. ie: "https://internalapp.yourcompany.com/oauth2/callback" |   -redirect-url string: the OAuth Redirect URL. ie: "https://internalapp.yourcompany.com/oauth2/callback" | ||||||
|   -redis-connection-url string: URL of redis server for redis session storage (eg: redis://HOST[:PORT]) |   -redis-connection-url string: URL of redis server for redis session storage (eg: redis://HOST[:PORT]) | ||||||
|   -redis-sentinel-master-name string: Redis sentinel master name. Used in conjuction with --redis-use-sentinel |   -redis-sentinel-master-name string: Redis sentinel master name. Used in conjunction with --redis-use-sentinel | ||||||
|   -redis-sentinel-connection-urls: List of Redis sentinel conneciton URLs (eg redis://HOST[:PORT]). Used in conjuction with --redis-use-sentinel |   -redis-sentinel-connection-urls: List of Redis sentinel connection URLs (eg redis://HOST[:PORT]). Used in conjunction with --redis-use-sentinel | ||||||
|   -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) |   -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) | ||||||
|   -request-logging: Log requests to stdout (default true) |   -request-logging: Log requests to stdout (default true) | ||||||
|   -request-logging-format: Template for request log lines (see "Logging Configuration" paragraph below) |   -request-logging-format: Template for request log lines (see "Logging Configuration" paragraph below) | ||||||
|  |  | ||||||
							
								
								
									
										4
									
								
								main.go
								
								
								
								
							
							
						
						
									
										4
									
								
								main.go
								
								
								
								
							|  | @ -86,8 +86,8 @@ func main() { | ||||||
| 	flagSet.String("session-store-type", "cookie", "the session storage provider to use") | 	flagSet.String("session-store-type", "cookie", "the session storage provider to use") | ||||||
| 	flagSet.String("redis-connection-url", "", "URL of redis server for redis session storage (eg: redis://HOST[:PORT])") | 	flagSet.String("redis-connection-url", "", "URL of redis server for redis session storage (eg: redis://HOST[:PORT])") | ||||||
| 	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") | 	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") | ||||||
| 	flagSet.String("redis-sentinel-master-name", "", "Redis sentinel master name. Used in conjuction with --redis-use-sentinel") | 	flagSet.String("redis-sentinel-master-name", "", "Redis sentinel master name. Used in conjunction with --redis-use-sentinel") | ||||||
| 	flagSet.Var(&redisSentinelConnectionURLs, "redis-sentinel-connection-urls", "List of Redis sentinel connection URLs (eg redis://HOST[:PORT]). Used in conjuction with --redis-use-sentinel") | 	flagSet.Var(&redisSentinelConnectionURLs, "redis-sentinel-connection-urls", "List of Redis sentinel connection URLs (eg redis://HOST[:PORT]). Used in conjunction with --redis-use-sentinel") | ||||||
| 
 | 
 | ||||||
| 	flagSet.String("logging-filename", "", "File to log requests to, empty for stdout") | 	flagSet.String("logging-filename", "", "File to log requests to, empty for stdout") | ||||||
| 	flagSet.Int("logging-max-size", 100, "Maximum size in megabytes of the log file before rotation") | 	flagSet.Int("logging-max-size", 100, "Maximum size in megabytes of the log file before rotation") | ||||||
|  |  | ||||||
|  | @ -898,7 +898,7 @@ func isAjax(req *http.Request) bool { | ||||||
| 	return false | 	return false | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // ErrorJSON returns the error code witht an application/json mime type
 | // ErrorJSON returns the error code with an application/json mime type
 | ||||||
| func (p *OAuthProxy) ErrorJSON(rw http.ResponseWriter, code int) { | func (p *OAuthProxy) ErrorJSON(rw http.ResponseWriter, code int) { | ||||||
| 	rw.Header().Set("Content-Type", applicationJSON) | 	rw.Header().Set("Content-Type", applicationJSON) | ||||||
| 	rw.WriteHeader(code) | 	rw.WriteHeader(code) | ||||||
|  |  | ||||||
|  | @ -3,10 +3,13 @@ package providers | ||||||
| import ( | import ( | ||||||
| 	"context" | 	"context" | ||||||
| 	"fmt" | 	"fmt" | ||||||
|  | 	"net/http" | ||||||
| 	"time" | 	"time" | ||||||
| 
 | 
 | ||||||
| 	oidc "github.com/coreos/go-oidc" | 	oidc "github.com/coreos/go-oidc" | ||||||
| 	"github.com/pusher/oauth2_proxy/pkg/apis/sessions" | 	"github.com/pusher/oauth2_proxy/pkg/apis/sessions" | ||||||
|  | 	"github.com/pusher/oauth2_proxy/pkg/requests" | ||||||
|  | 
 | ||||||
| 	"golang.org/x/oauth2" | 	"golang.org/x/oauth2" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
|  | @ -117,8 +120,31 @@ func (p *OIDCProvider) createSessionState(ctx context.Context, token *oauth2.Tok | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	if claims.Email == "" { | 	if claims.Email == "" { | ||||||
| 		// TODO: Try getting email from /userinfo before falling back to Subject
 | 		if p.ProfileURL.String() == "" { | ||||||
| 		claims.Email = claims.Subject | 			return nil, fmt.Errorf("id_token did not contain an email") | ||||||
|  | 		} | ||||||
|  | 
 | ||||||
|  | 		// If the userinfo endpoint profileURL is defined, then there is a chance the userinfo
 | ||||||
|  | 		// contents at the profileURL contains the email.
 | ||||||
|  | 		// Make a query to the userinfo endpoint, and attempt to locate the email from there.
 | ||||||
|  | 
 | ||||||
|  | 		req, err := http.NewRequest("GET", p.ProfileURL.String(), nil) | ||||||
|  | 		if err != nil { | ||||||
|  | 			return nil, err | ||||||
|  | 		} | ||||||
|  | 		req.Header = getOIDCHeader(token.AccessToken) | ||||||
|  | 
 | ||||||
|  | 		respJSON, err := requests.Request(req) | ||||||
|  | 		if err != nil { | ||||||
|  | 			return nil, err | ||||||
|  | 		} | ||||||
|  | 
 | ||||||
|  | 		email, err := respJSON.Get("email").String() | ||||||
|  | 		if err != nil { | ||||||
|  | 			return nil, fmt.Errorf("Neither id_token nor userinfo endpoint contained an email") | ||||||
|  | 		} | ||||||
|  | 
 | ||||||
|  | 		claims.Email = email | ||||||
| 	} | 	} | ||||||
| 	if !p.AllowUnverifiedEmail && claims.Verified != nil && !*claims.Verified { | 	if !p.AllowUnverifiedEmail && claims.Verified != nil && !*claims.Verified { | ||||||
| 		return nil, fmt.Errorf("email in id_token (%s) isn't verified", claims.Email) | 		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 { | ||||||
| 
 | 
 | ||||||
| 	return true | 	return true | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | func getOIDCHeader(accessToken string) http.Header { | ||||||
|  | 	header := make(http.Header) | ||||||
|  | 	header.Set("Accept", "application/json") | ||||||
|  | 	header.Set("Authorization", fmt.Sprintf("Bearer %s", accessToken)) | ||||||
|  | 	return header | ||||||
|  | } | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue