Skip to content

Commit a3add67

Browse files
committed
wip(examples): use object id for user assigned
1 parent 31f7b95 commit a3add67

File tree

5 files changed

+18
-18
lines changed

5 files changed

+18
-18
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ type ManagedIdentityProviderOptions struct {
279279
ManagedIdentityType ManagedIdentityType // SystemAssignedIdentity or UserAssignedIdentity
280280

281281
// Optional: Client ID for user-assigned identity
282-
UserAssignedClientID string
282+
UserAssignedObjectID string
283283

284284
// Optional: Scopes for token access
285285
// Default: ["https://redis.azure.com/.default"]
@@ -427,7 +427,7 @@ provider, err := entraid.NewManagedIdentityCredentialsProvider(entraid.ManagedId
427427
},
428428
ManagedIdentityProviderOptions: identity.ManagedIdentityProviderOptions{
429429
ManagedIdentityType: identity.UserAssignedIdentity,
430-
UserAssignedClientID: os.Getenv("AZURE_USER_ASSIGNED_MANAGED_ID"),
430+
UserAssignedObjectID: os.Getenv("AZURE_USER_ASSIGNED_MANAGED_ID"),
431431
Scopes: []string{"https://redis.azure.com/.default"},
432432
},
433433
})

examples/entraid/managedidentity_user/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func main() {
2929
},
3030
ManagedIdentityProviderOptions: identity.ManagedIdentityProviderOptions{
3131
ManagedIdentityType: "UserAssigned",
32-
UserAssignedClientID: cfg.AzureUserAssignedManagedID,
32+
UserAssignedObjectID: cfg.AzureUserAssignedManagedID,
3333
Scopes: cfg.GetRedisScopes(),
3434
},
3535
})

identity/managed_identity_provider.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ type ManagedIdentityClient interface {
2121
// ManagedIdentityProviderOptions represents the options for the managed identity provider.
2222
// It is used to configure the identity provider when requesting a token.
2323
type ManagedIdentityProviderOptions struct {
24-
// UserAssignedClientID is the client ID of the user assigned identity.
24+
// UserAssignedObjectID is the object ID that is used to identify the user assigned identity.
2525
// This is used to identify the identity when requesting a token.
26-
UserAssignedClientID string
26+
UserAssignedObjectID string
2727
// ManagedIdentityType is the type of managed identity.
2828
// This can be either SystemAssigned or UserAssigned.
2929
ManagedIdentityType string
@@ -34,9 +34,9 @@ type ManagedIdentityProviderOptions struct {
3434

3535
// ManagedIdentityProvider represents a managed identity provider.
3636
type ManagedIdentityProvider struct {
37-
// userAssignedClientID is the client ID of the user assigned identity.
37+
// userAssignedObjectID is the client ID of the user assigned identity.
3838
// This is used to identify the identity when requesting a token.
39-
userAssignedClientID string
39+
userAssignedObjectID string
4040

4141
// managedIdentityType is the type of managed identity.
4242
// This can be either SystemAssigned or UserAssigned.
@@ -80,19 +80,19 @@ func NewManagedIdentityProvider(opts ManagedIdentityProviderOptions) (*ManagedId
8080
client = &realManagedIdentityClient{client: miClient}
8181
case UserAssignedIdentity:
8282
// UserAssignedIdentity is required to be specified when using a user assigned identity.
83-
if opts.UserAssignedClientID == "" {
84-
return nil, errors.New("user assigned client ID is required when using user assigned identity")
83+
if opts.UserAssignedObjectID == "" {
84+
return nil, errors.New("user assigned object ID is required when using user assigned identity")
8585
}
8686
// UserAssignedIdentity is the type of identity that is managed by the user.
87-
miClient, err := mi.New(mi.UserAssignedClientID(opts.UserAssignedClientID))
87+
miClient, err := mi.New(mi.UserAssignedObjectID(opts.UserAssignedObjectID))
8888
if err != nil {
8989
return nil, fmt.Errorf("couldn't create managed identity client: %w", err)
9090
}
9191
client = &realManagedIdentityClient{client: miClient}
9292
}
9393

9494
return &ManagedIdentityProvider{
95-
userAssignedClientID: opts.UserAssignedClientID,
95+
userAssignedObjectID: opts.UserAssignedObjectID,
9696
managedIdentityType: opts.ManagedIdentityType,
9797
scopes: opts.Scopes,
9898
client: client,

identity/managed_identity_provider_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func TestNewManagedIdentityProvider(t *testing.T) {
4040
name: "User assigned identity with client ID",
4141
opts: ManagedIdentityProviderOptions{
4242
ManagedIdentityType: UserAssignedIdentity,
43-
UserAssignedClientID: "test-client-id",
43+
UserAssignedObjectID: "test-client-id",
4444
Scopes: []string{"https://redis.azure.com"},
4545
},
4646
expectedError: "",
@@ -51,7 +51,7 @@ func TestNewManagedIdentityProvider(t *testing.T) {
5151
ManagedIdentityType: UserAssignedIdentity,
5252
Scopes: []string{"https://redis.azure.com"},
5353
},
54-
expectedError: "user assigned client ID is required when using user assigned identity",
54+
expectedError: "user assigned object ID is required when using user assigned identity",
5555
},
5656
{
5757
name: "Invalid identity type",
@@ -75,7 +75,7 @@ func TestNewManagedIdentityProvider(t *testing.T) {
7575
assert.NoError(t, err)
7676
assert.NotNil(t, provider)
7777
assert.Equal(t, tt.opts.ManagedIdentityType, provider.managedIdentityType)
78-
assert.Equal(t, tt.opts.UserAssignedClientID, provider.userAssignedClientID)
78+
assert.Equal(t, tt.opts.UserAssignedObjectID, provider.userAssignedObjectID)
7979
assert.Equal(t, tt.opts.Scopes, provider.scopes)
8080
assert.NotNil(t, provider.client)
8181
}

providers_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func TestNewManagedIdentityCredentialsProvider(t *testing.T) {
3030
},
3131
},
3232
ManagedIdentityProviderOptions: identity.ManagedIdentityProviderOptions{
33-
UserAssignedClientID: "test-client-id",
33+
UserAssignedObjectID: "test-client-id",
3434
ManagedIdentityType: identity.UserAssignedIdentity,
3535
Scopes: []string{identity.RedisScopeDefault},
3636
},
@@ -277,7 +277,7 @@ func TestCredentialsProviderInterface(t *testing.T) {
277277
},
278278
},
279279
ManagedIdentityProviderOptions: identity.ManagedIdentityProviderOptions{
280-
UserAssignedClientID: "test-client-id",
280+
UserAssignedObjectID: "test-client-id",
281281
ManagedIdentityType: identity.UserAssignedIdentity,
282282
Scopes: []string{identity.RedisScopeDefault},
283283
},
@@ -392,7 +392,7 @@ func TestNewManagedIdentityCredentialsProvider_TokenManagerFactoryError(t *testi
392392
},
393393
},
394394
ManagedIdentityProviderOptions: identity.ManagedIdentityProviderOptions{
395-
UserAssignedClientID: "test-client-id",
395+
UserAssignedObjectID: "test-client-id",
396396
ManagedIdentityType: identity.UserAssignedIdentity,
397397
Scopes: []string{identity.RedisScopeDefault},
398398
},
@@ -470,7 +470,7 @@ func TestNewManagedIdentityCredentialsProvider_TokenManagerStartError(t *testing
470470
},
471471
},
472472
ManagedIdentityProviderOptions: identity.ManagedIdentityProviderOptions{
473-
UserAssignedClientID: "test-client-id",
473+
UserAssignedObjectID: "test-client-id",
474474
ManagedIdentityType: identity.UserAssignedIdentity,
475475
Scopes: []string{identity.RedisScopeDefault},
476476
},

0 commit comments

Comments
 (0)