You need to make sure you specify the AzureEnvironment.AzureUSGovernment
for your AzureCredentials
(line #2 below) like this:
var servicePrincipal = new ServicePrincipalLoginInformation { ClientId = "<your-client-id>", ClientSecret = "<your-client-secret" };
var creds = new AzureCredentials(servicePrincipal, tenantId: "<your-tenant-id>", AzureEnvironment.AzureUSGovernment);
var azure = Azure.Configure().Authenticate(creds).WithDefaultSubscription();
var rgs = await azure.ResourceGroups.ListAsync();
Alternatively, you can use ResourceManagementClient
to do the same as the code above, though the ResourceManagementClient
code is more verbose so my recommendation is in most cases you want to use the code above, but here is the alternative:
var servicePrincipal = new ServicePrincipalLoginInformation { ClientId = "<your-client-id>", ClientSecret = "<your-client-secret" };
var creds = new AzureCredentials(servicePrincipal, tenantId: "<your-tenant-id>", AzureEnvironment.AzureUSGovernment);
var restClient = RestClient
.Configure()
.WithEnvironment(AzureEnvironment.AzureUSGovernment)
.WithCredentials(creds)
.Build();
var resourceManagementClient = new ResourceManagementClient(restClient);
resourceManagementClient.SubscriptionId = "<your-subscription-id>";
var rgs = await resourceManagementClient.ResourceGroups.ListAsync();