@@ -28,6 +28,10 @@ type ManagedIdentityAuthorizerOptions struct {
28
28
// CustomManagedIdentityEndpoint is an optional endpoint from which to obtain an access
29
29
// token. When blank, the default is used.
30
30
CustomManagedIdentityEndpoint string
31
+
32
+ // CustomManagedIdentityAPIVersion is an optional API version to use when requesting a token.
33
+ // This is required when using an endpoint that does not support the default API version such as Azure Container Apps.
34
+ CustomManagedIdentityAPIVersion string
31
35
}
32
36
33
37
// NewManagedIdentityAuthorizer returns an authorizer using a Managed Identity for authentication.
@@ -36,7 +40,7 @@ func NewManagedIdentityAuthorizer(ctx context.Context, options ManagedIdentityAu
36
40
if err != nil {
37
41
return nil , fmt .Errorf ("determining resource for api %q: %+v" , options .Api .Name (), err )
38
42
}
39
- conf , err := newManagedIdentityConfig (* resource , options .ClientId , options .CustomManagedIdentityEndpoint )
43
+ conf , err := newManagedIdentityConfig (* resource , options .ClientId , options .CustomManagedIdentityEndpoint , options . CustomManagedIdentityAPIVersion )
40
44
if err != nil {
41
45
return nil , err
42
46
}
@@ -70,9 +74,9 @@ func (a *ManagedIdentityAuthorizer) Token(ctx context.Context, _ *http.Request)
70
74
query ["client_id" ] = []string {a .conf .ClientID }
71
75
}
72
76
73
- url := fmt .Sprintf ("%s?%s" , a .conf .MsiEndpoint , query .Encode ())
77
+ u := fmt .Sprintf ("%s?%s" , a .conf .MsiEndpoint , query .Encode ())
74
78
75
- body , err := azureMetadata (ctx , url )
79
+ body , err := azureMetadata (ctx , u )
76
80
if err != nil {
77
81
return nil , fmt .Errorf ("ManagedIdentityAuthorizer: failed to request token from metadata endpoint: %v" , err )
78
82
}
@@ -135,16 +139,21 @@ type managedIdentityConfig struct {
135
139
136
140
// newManagedIdentityConfig returns a new managedIdentityConfig with a configured metadata endpoint and resource.
137
141
// clientId and objectId can be left blank when a single managed identity is available
138
- func newManagedIdentityConfig (resource , clientId , customManagedIdentityEndpoint string ) (* managedIdentityConfig , error ) {
142
+ func newManagedIdentityConfig (resource , clientId , customManagedIdentityEndpoint string , customManagedIdentityAPIVersion string ) (* managedIdentityConfig , error ) {
139
143
endpoint := msiDefaultEndpoint
140
144
if customManagedIdentityEndpoint != "" {
141
145
endpoint = customManagedIdentityEndpoint
142
146
}
143
147
148
+ apiVersion := msiDefaultApiVersion
149
+ if customManagedIdentityAPIVersion != "" {
150
+ apiVersion = customManagedIdentityAPIVersion
151
+ }
152
+
144
153
return & managedIdentityConfig {
145
154
ClientID : clientId ,
146
155
Resource : resource ,
147
- MsiApiVersion : msiDefaultApiVersion ,
156
+ MsiApiVersion : apiVersion ,
148
157
MsiEndpoint : endpoint ,
149
158
}, nil
150
159
}
0 commit comments