Skip to content

Commit 44890d0

Browse files
authored
fix: resolving azure overage claim should include api-version=1.6 query parameter (#2000)
As unfortunately documented almost nowhere, sending a request to the Microsoft Graph API requires a query parameter to specify an undocumented `api-version` with value `1.6`. Source: https://stackoverflow.com/questions/51085863/retrieve-group-claims-using-claim-sources-returns-the-specified-api-version-is
1 parent 29f3440 commit 44890d0

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

internal/api/provider/azure.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"fmt"
88
"io"
99
"net/http"
10+
"net/url"
1011
"regexp"
1112
"strings"
1213
"unicode/utf8"
@@ -198,7 +199,19 @@ func (c *AzureIDTokenClaims) ResolveIndirectClaims(ctx context.Context, httpClie
198199
continue
199200
}
200201

201-
claimEndpoint := claimEndpointObject.Endpoint
202+
u, err := url.ParseRequestURI(claimEndpointObject.Endpoint)
203+
if err != nil {
204+
return nil, fmt.Errorf("azure: failed to parse endpoint URL %q (resolving overage claim %q): %w", claimEndpointObject.Endpoint, claimName, err)
205+
}
206+
207+
queryParams := u.Query()
208+
if !queryParams.Has("api-version") {
209+
// https://stackoverflow.com/questions/51085863/retrieve-group-claims-using-claim-sources-returns-the-specified-api-version-is
210+
queryParams.Add("api-version", "1.6")
211+
u.RawQuery = queryParams.Encode()
212+
}
213+
214+
claimEndpoint := u.String()
202215

203216
req, err := http.NewRequestWithContext(ctx, http.MethodPost, claimEndpoint, strings.NewReader(`{"securityEnabledOnly":true}`))
204217
if err != nil {

internal/api/provider/azure_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func TestAzureResolveIndirectClaimsFailures(t *testing.T) {
9999
{
100100
name: "invalid url",
101101
urlSuffix: "\000",
102-
expectedError: "azure: failed to create POST request to \"SERVER-URL\\x00\" (resolving overage claim \"groups\"): parse \"SERVER-URL\\x00\": net/url: invalid control character in URL",
102+
expectedError: "azure: failed to parse endpoint URL \"SERVER-URL\\x00\" (resolving overage claim \"groups\"): parse \"SERVER-URL\\x00\": net/url: invalid control character in URL",
103103
},
104104
{
105105
name: "no such server",
@@ -141,6 +141,8 @@ func TestAzureResolveIndirectClaimsFailures(t *testing.T) {
141141
for _, example := range examples {
142142
t.Run(example.name, func(t *testing.T) {
143143
server := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
144+
require.Equal(t, "1.6", r.URL.Query().Get("api-version"))
145+
144146
w.WriteHeader(example.statusCode)
145147

146148
w.Write(example.body)
@@ -164,7 +166,7 @@ func TestAzureResolveIndirectClaimsFailures(t *testing.T) {
164166
resolvedClaims, err := claims.ResolveIndirectClaims(context.Background(), server.Client(), "access-token")
165167
require.Nil(t, resolvedClaims)
166168
require.Error(t, err)
167-
require.Equal(t, example.expectedError, strings.ReplaceAll(strings.ReplaceAll(err.Error(), server.URL, "SERVER-URL"), u.Port(), "PORT"))
169+
require.Equal(t, example.expectedError, strings.ReplaceAll(strings.ReplaceAll(strings.ReplaceAll(err.Error(), server.URL, "SERVER-URL"), u.Port(), "PORT"), "?api-version=1.6", ""))
168170
})
169171
}
170172

0 commit comments

Comments
 (0)