in pkg/internal/token/devicecodecredential.go [21:61]
func newDeviceCodeCredential(opts *Options, record azidentity.AuthenticationRecord) (CredentialProvider, error) {
if opts.ClientID == "" {
return nil, fmt.Errorf("client ID cannot be empty")
}
if opts.TenantID == "" {
return nil, fmt.Errorf("tenant ID cannot be empty")
}
var (
c azidentity.Cache
err error
)
if opts.UsePersistentCache {
c, err = cache.New(nil)
if err != nil {
klog.V(5).Infof("failed to create cache: %v", err)
}
}
azOpts := &azidentity.DeviceCodeCredentialOptions{
ClientOptions: azcore.ClientOptions{Cloud: opts.GetCloudConfiguration()},
AuthenticationRecord: record,
Cache: c,
ClientID: opts.ClientID,
TenantID: opts.TenantID,
DisableInstanceDiscovery: opts.DisableInstanceDiscovery,
UserPrompt: func(ctx context.Context, dcm azidentity.DeviceCodeMessage) error {
_, err := fmt.Fprintln(os.Stderr, dcm.Message)
return err
},
}
if opts.httpClient != nil {
azOpts.ClientOptions.Transport = opts.httpClient
}
cred, err := azidentity.NewDeviceCodeCredential(azOpts)
if err != nil {
return nil, fmt.Errorf("failed to create device code credential: %w", err)
}
return &DeviceCodeCredential{cred: cred}, nil
}