git.iko.soy/typeable/oauth2-proxy
on master help sign in
add azure china support (#2269)

* add azure china support Signed-off-by: Markus Blaschke <mblaschke82@gmail.com> * update changelog Signed-off-by: Markus Blaschke <mblaschke82@gmail.com> * fix lint Signed-off-by: Markus Blaschke <mblaschke82@gmail.com> --------- Signed-off-by: Markus Blaschke <mblaschke82@gmail.com> Co-authored-by: Joel Speed <Joel.speed@hotmail.co.uk>

commit66bfd8ebd57d6ef7d51d2e1ecbf0d3a1091c7308 authorMarkus Blaschke <mblaschke82@gmail.com> dateWed 1 Nov 2023, 11:12 (3 years ago) parent66a81e6
2 files changed+11−8
CHANGELOG.md+3−1 providers/azure.go+8−7
CHANGELOG.md+3−1
@@ -8,13 +8,15 @@
88
99## Changes since v7.5.1
1010
11+- [#2128](https://github.com/oauth2-proxy/oauth2-proxy/pull/2128) Update dependencies (@vllvll)
12+- [#2269](https://github.com/oauth2-proxy/oauth2-proxy/pull/2269) Added Azure China (and other air gaped cloud) support (@mblaschke)
1113- [#2237](https://github.com/oauth2-proxy/oauth2-proxy/pull/2237) adds an option to append CA certificates (@emsixteeen)
1214- [#2128](https://github.com/oauth2-proxy/oauth2-proxy/pull/2128) Update dependencies (@vllvll)
1315- [#2274](https://github.com/oauth2-proxy/oauth2-proxy/pull/2274) Upgrade golang.org/x/net to v0.17.0 (@pierluigilenoci)
1416- [#2282](https://github.com/oauth2-proxy/oauth2-proxy/pull/2282) Fixed checking Google Groups membership using Google Application Credentials (@kvanzuijlen)
1517- [#2183](https://github.com/oauth2-proxy/oauth2-proxy/pull/2183) Allowing relative redirect url though an option
1618- [#1866](https://github.com/oauth2-proxy/oauth2-proxy/pull/1866) Add support for unix socker as upstream (@babs)
17−-
19+
1820# V7.5.1
1921
2022## Release Highlights
providers/azure.go+8−7
@@ -12,6 +12,7 @@ import (
1212 "golang.org/x/exp/slices"
1313
1414 "github.com/bitly/go-simplejson"
15+
1516 "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/apis/options"
1617 "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/apis/sessions"
1718 "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/logger"
@@ -33,7 +34,6 @@ const (
3334 azureProviderName = "Azure"
3435 azureDefaultScope = "openid"
3536 azureDefaultGraphGroupField = "id"
36− azureV2Scope = "https://graph.microsoft.com/.default"
3737)
3838
3939var (
@@ -90,15 +90,16 @@ func NewAzureProvider(p *ProviderData, opts options.AzureOptions) *AzureProvider
9090 isV2Endpoint := false
9191 if strings.Contains(p.LoginURL.String(), "v2.0") {
9292 isV2Endpoint = true
93+ azureV2GraphScope := fmt.Sprintf("https://%s/.default", p.ProfileURL.Host)
9394
9495 if strings.Contains(p.Scope, " groups") {
9596 logger.Print("WARNING: `groups` scope is not an accepted scope when using Azure OAuth V2 endpoint. Removing it from the scope list")
9697 p.Scope = strings.ReplaceAll(p.Scope, " groups", "")
9798 }
9899
99− if !strings.Contains(p.Scope, " "+azureV2Scope) {
100+ if !strings.Contains(p.Scope, " "+azureV2GraphScope) {
100101 // In order to be able to query MS Graph we must pass the ms graph default endpoint
101− p.Scope += " " + azureV2Scope
102+ p.Scope += " " + azureV2GraphScope
102103 }
103104
104105 if p.ProtectedResource != nil && p.ProtectedResource.String() != "" {
@@ -118,12 +119,12 @@ func overrideTenantURL(current, defaultURL *url.URL, tenant, path string) {
118119 if current == nil || current.String() == "" || current.String() == defaultURL.String() {
119120 *current = url.URL{
120121 Scheme: "https",
121− Host: "login.microsoftonline.com",
122+ Host: current.Host,
122123 Path: "/" + tenant + "/oauth2/" + path}
123124 }
124125}
125126
126−func getMicrosoftGraphGroupsURL(graphGroupField string) *url.URL {
127+func getMicrosoftGraphGroupsURL(profileURL *url.URL, graphGroupField string) *url.URL {
127128
128129 selectStatement := "$select=displayName,id"
129130 if !slices.Contains([]string{"displayName", "id"}, graphGroupField) {
@@ -133,7 +134,7 @@ func getMicrosoftGraphGroupsURL(graphGroupField string) *url.URL {
133134 // Select only security groups. Due to the filter option, count param is mandatory even if unused otherwise
134135 return &url.URL{
135136 Scheme: "https",
136− Host: "graph.microsoft.com",
137+ Host: profileURL.Host,
137138 Path: "/v1.0/me/transitiveMemberOf",
138139 RawQuery: "$count=true&$filter=securityEnabled+eq+true&" + selectStatement,
139140 }
@@ -368,7 +369,7 @@ func (p *AzureProvider) getGroupsFromProfileAPI(ctx context.Context, s *sessions
368369 return nil, fmt.Errorf("missing access token")
369370 }
370371
371− groupsURL := getMicrosoftGraphGroupsURL(p.GraphGroupField).String()
372+ groupsURL := getMicrosoftGraphGroupsURL(p.ProfileURL, p.GraphGroupField).String()
372373
373374 // Need and extra header while talking with MS Graph. For more context see
374375 // https://docs.microsoft.com/en-us/graph/api/group-list-transitivememberof?view=graph-rest-1.0&tabs=http#request-headers