Skip to content

Commit c3cd920

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

File tree

7 files changed

+39
-38
lines changed

7 files changed

+39
-38
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ graph TD
178178
B -->|Yes| C{System Assigned?}
179179
B -->|No| D{Client Credentials?}
180180
C -->|Yes| E[SystemAssignedIdentity]
181-
C -->|No| F[UserAssignedIdentity]
181+
C -->|No| F[UserAssignedObjectID]
182182
D -->|Yes| G{Client Secret?}
183183
D -->|No| H[DefaultAzureIdentity]
184184
G -->|Yes| I[ClientSecret]
@@ -276,10 +276,10 @@ Options for managed identity authentication:
276276
```go
277277
type ManagedIdentityProviderOptions struct {
278278
// Required: Type of managed identity
279-
ManagedIdentityType ManagedIdentityType // SystemAssignedIdentity or UserAssignedIdentity
279+
ManagedIdentityType ManagedIdentityType // SystemAssignedIdentity or UserAssignedObjectID
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"]
@@ -426,8 +426,8 @@ provider, err := entraid.NewManagedIdentityCredentialsProvider(entraid.ManagedId
426426
ClientID: os.Getenv("AZURE_CLIENT_ID"),
427427
},
428428
ManagedIdentityProviderOptions: identity.ManagedIdentityProviderOptions{
429-
ManagedIdentityType: identity.UserAssignedIdentity,
430-
UserAssignedClientID: os.Getenv("AZURE_USER_ASSIGNED_MANAGED_ID"),
429+
ManagedIdentityType: identity.UserAssignedObjectID,
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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ func main() {
2828
ClientID: cfg.AzureClientID,
2929
},
3030
ManagedIdentityProviderOptions: identity.ManagedIdentityProviderOptions{
31-
ManagedIdentityType: "UserAssigned",
32-
UserAssignedClientID: cfg.AzureUserAssignedManagedID,
31+
ManagedIdentityType: identity.UserAssignedObjectID,
32+
UserAssignedObjectID: cfg.AzureUserAssignedManagedID,
3333
Scopes: cfg.GetRedisScopes(),
3434
},
3535
})

identity/managed_identity_provider.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ 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.
28-
// This can be either SystemAssigned or UserAssigned.
28+
// This can be either SystemAssigned or UserAssignedObjectID.
2929
ManagedIdentityType string
3030
// Scopes is a list of scopes that the identity has access to.
3131
// This is used to specify the permissions that the identity has when requesting a token.
@@ -34,12 +34,12 @@ 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.
42-
// This can be either SystemAssigned or UserAssigned.
42+
// This can be either SystemAssigned or UserAssignedObjectID.
4343
managedIdentityType string
4444

4545
// scopes is a list of scopes that the identity has access to.
@@ -64,7 +64,7 @@ func (c *realManagedIdentityClient) AcquireToken(ctx context.Context, resource s
6464
func NewManagedIdentityProvider(opts ManagedIdentityProviderOptions) (*ManagedIdentityProvider, error) {
6565
var client ManagedIdentityClient
6666

67-
if opts.ManagedIdentityType != SystemAssignedIdentity && opts.ManagedIdentityType != UserAssignedIdentity {
67+
if opts.ManagedIdentityType != SystemAssignedIdentity && opts.ManagedIdentityType != UserAssignedObjectID {
6868
return nil, errors.New("invalid managed identity type")
6969
}
7070

@@ -78,21 +78,21 @@ func NewManagedIdentityProvider(opts ManagedIdentityProviderOptions) (*ManagedId
7878
return nil, fmt.Errorf("couldn't create managed identity client: %w", err)
7979
}
8080
client = &realManagedIdentityClient{client: miClient}
81-
case UserAssignedIdentity:
82-
// 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")
81+
case UserAssignedObjectID:
82+
// UserAssignedObjectID is required to be specified when using a user assigned identity.
83+
if opts.UserAssignedObjectID == "" {
84+
return nil, errors.New("user assigned object ID is required when using user assigned identity")
8585
}
86-
// UserAssignedIdentity is the type of identity that is managed by the user.
87-
miClient, err := mi.New(mi.UserAssignedClientID(opts.UserAssignedClientID))
86+
// UserAssignedObjectID is the type of identity that is managed by the user.
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: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,19 @@ func TestNewManagedIdentityProvider(t *testing.T) {
3939
{
4040
name: "User assigned identity with client ID",
4141
opts: ManagedIdentityProviderOptions{
42-
ManagedIdentityType: UserAssignedIdentity,
43-
UserAssignedClientID: "test-client-id",
42+
ManagedIdentityType: UserAssignedObjectID,
43+
UserAssignedObjectID: "test-client-id",
4444
Scopes: []string{"https://redis.azure.com"},
4545
},
4646
expectedError: "",
4747
},
4848
{
4949
name: "User assigned identity without client ID",
5050
opts: ManagedIdentityProviderOptions{
51-
ManagedIdentityType: UserAssignedIdentity,
51+
ManagedIdentityType: UserAssignedObjectID,
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
}

identity/providers.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ package identity
55
const (
66
// SystemAssignedIdentity is the type of identity that is automatically managed by Azure.
77
SystemAssignedIdentity = "SystemAssigned"
8-
// UserAssignedIdentity is the type of identity that is managed by the user.
9-
UserAssignedIdentity = "UserAssigned"
8+
// UserAssignedObjectID is the type of identity that is managed by the user.
9+
UserAssignedObjectID = "UserAssignedObjectID"
10+
1011

1112
// ClientSecretCredentialType is the type of credentials that uses a client secret to authenticate.
1213
ClientSecretCredentialType = "ClientSecret"

identity/providers_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ func TestConstants(t *testing.T) {
1616
expected: "SystemAssigned",
1717
},
1818
{
19-
name: "UserAssignedIdentity",
20-
got: UserAssignedIdentity,
19+
name: "UserAssignedObjectID",
20+
got: UserAssignedObjectID,
2121
expected: "UserAssigned",
2222
},
2323
{

providers_test.go

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

0 commit comments

Comments
 (0)