private async Task <AzureCredentials> GetCredentialsAsync() { try { if (string.IsNullOrEmpty(azureSessionOptions.TenantId) && azureSessionOptions == AzureSessionOptions.Default) { var identity = await GetIdentityAsync(AzureEndpoint.ResourceManagerEndpoint) .ConfigureAwait(false); if ((identity?.TenantId).HasValue) { ((AzureSessionOptions)azureSessionOptions).TenantId = identity.TenantId.ToString(); } } var credentialsFactory = new RMFluent.Authentication.AzureCredentialsFactory(); if (string.IsNullOrEmpty(azureSessionOptions.ClientId)) { if (IsAzureEnvironment) { return(credentialsFactory .FromSystemAssignedManagedServiceIdentity(MSIResourceType.AppService, Environment, azureSessionOptions.TenantId)); } else { return(new AzureCredentials( new TokenCredentials(new DevelopmentTokenProvider(this, AzureEndpoint.ResourceManagerEndpoint)), new TokenCredentials(new DevelopmentTokenProvider(this, AzureEndpoint.GraphEndpoint)), azureSessionOptions.TenantId, Environment)); } } else if (string.IsNullOrEmpty(azureSessionOptions.ClientSecret)) { return(credentialsFactory .FromUserAssigedManagedServiceIdentity(azureSessionOptions.ClientId, MSIResourceType.AppService, this.Environment, azureSessionOptions.TenantId)); } else { return(credentialsFactory .FromServicePrincipal(azureSessionOptions.ClientId, azureSessionOptions.ClientSecret, azureSessionOptions.TenantId, this.Environment)); } } catch (Exception exc) { throw new TypeInitializationException(typeof(AzureCredentials).FullName, exc); } }
private AzureCredentials InitCredentials() { try { var credentialsFactory = new RMFluent.Authentication.AzureCredentialsFactory(); if (string.IsNullOrEmpty(azureSessionOptions.ClientId)) { if (IsAzureEnvironment) { return(credentialsFactory .FromSystemAssignedManagedServiceIdentity(MSIResourceType.AppService, Environment, azureSessionOptions.TenantId)); } else { return(new AzureCredentials( new TokenCredentials(new DevelopmentTokenProvider(this, AzureEndpoint.ResourceManagerEndpoint)), new TokenCredentials(new DevelopmentTokenProvider(this, AzureEndpoint.GraphEndpoint)), azureSessionOptions.TenantId, Environment)); } } else if (string.IsNullOrEmpty(azureSessionOptions.ClientSecret)) { return(credentialsFactory .FromUserAssigedManagedServiceIdentity(azureSessionOptions.ClientId, MSIResourceType.AppService, this.Environment, azureSessionOptions.TenantId)); } else { return(credentialsFactory .FromServicePrincipal(azureSessionOptions.ClientId, azureSessionOptions.ClientSecret, azureSessionOptions.TenantId, this.Environment)); } } catch (Exception exc) { throw new TypeInitializationException(typeof(AzureCredentials).FullName, exc); } }