private static TokenCredential[] GetDefaultAzureCredentialChain(DefaultAzureCredentialFactory factory, DefaultAzureCredentialOptions options)
        {
            if (options is null)
            {
                return(s_defaultCredentialChain);
            }

            int i = 0;

            TokenCredential[] chain = new TokenCredential[7];

            if (!options.ExcludeEnvironmentCredential)
            {
                chain[i++] = factory.CreateEnvironmentCredential();
            }

            if (!options.ExcludeManagedIdentityCredential)
            {
                chain[i++] = factory.CreateManagedIdentityCredential(options.ManagedIdentityClientId);
            }

            if (!options.ExcludeSharedTokenCacheCredential)
            {
                chain[i++] = factory.CreateSharedTokenCacheCredential(options.SharedTokenCacheTenantId, options.SharedTokenCacheUsername);
            }

            if (!options.ExcludeVisualStudioCredential)
            {
                chain[i++] = factory.CreateVisualStudioCredential(options.VisualStudioTenantId);
            }

            if (!options.ExcludeVisualStudioCodeCredential)
            {
                chain[i++] = factory.CreateVisualStudioCodeCredential(options.VisualStudioCodeTenantId);
            }

            if (!options.ExcludeAzureCliCredential)
            {
                chain[i++] = factory.CreateAzureCliCredential();
            }

            if (!options.ExcludeInteractiveBrowserCredential)
            {
                chain[i++] = factory.CreateInteractiveBrowserCredential(options.InteractiveBrowserTenantId);
            }

            if (i == 0)
            {
                throw new ArgumentException("At least one credential type must be included in the authentication flow.", nameof(options));
            }

            return(chain);
        }
        private static IExtendedTokenCredential[] GetDefaultAzureCredentialChain(DefaultAzureCredentialFactory factory, DefaultAzureCredentialOptions options)
        {
            if (options is null)
            {
                return(s_defaultCredentialChain);
            }

            int i = 0;

            IExtendedTokenCredential[] chain = new IExtendedTokenCredential[4];

            if (!options.ExcludeEnvironmentCredential)
            {
                chain[i++] = factory.CreateEnvironmentCredential();
            }

            if (!options.ExcludeManagedIdentityCredential)
            {
                chain[i++] = factory.CreateManagedIdentityCredential(options.ManagedIdentityClientId);
            }

            if (!options.ExcludeSharedTokenCacheCredential)
            {
                chain[i++] = factory.CreateSharedTokenCacheCredential(options.SharedTokenCacheUsername ?? EnvironmentVariables.Username);
            }

            if (!options.ExcludeInteractiveBrowserCredential)
            {
                chain[i++] = factory.CreateInteractiveBrowserCredential();
            }

            if (i == 0)
            {
                throw new ArgumentException("At least one credential type must be included in the authentication flow.", nameof(options));
            }

            return(chain);
        }
 internal DefaultAzureCredential(DefaultAzureCredentialFactory factory, DefaultAzureCredentialOptions options)
 {
     _pipeline       = factory.Pipeline;
     _sources        = GetDefaultAzureCredentialChain(factory, options);
     _credentialLock = new AsyncLockWithValue <TokenCredential>();
 }
Ejemplo n.º 4
0
        internal DefaultAzureCredential(DefaultAzureCredentialFactory factory, DefaultAzureCredentialOptions options)
        {
            _pipeline = factory.Pipeline;

            _sources = GetDefaultAzureCredentialChain(factory, options);
        }