I am trying to get the configuration of one of my web apps using the C# .NET SDK. I want to use an Azure AD Application instead of a Management Certificate (which I have previously got working).
I have the following code:
var subscriptionId = "<subscription-guid>";
var appId = "<app-guid>";
var appKey = "<app-key>";
var tenantId = "<tenant-guid>";
var context = new AuthenticationContext("https://login.windows.net/" + tenantId);
ClientCredential clientCredential = new ClientCredential(appId, appKey);
var tokenResponse = context.AcquireTokenAsync("https://management.core.windows.net/", clientCredential).Result;
var accessToken = tokenResponse.AccessToken;
var myWebspace = "<my-webspace>";
var myWebsite = "<my-website>";
var client = new WebSiteManagementClient(new TokenCloudCredentials(subscriptionId, accessToken));
var config = client.WebSites.GetConfigurationAsync(myWebspace, myWebsite).Result;
...but it is throwing the following error on the last line:
Microsoft.WindowAzure.CloudException
ForbiddenError: The server failed to authenticate the request. Verify that the certificate is valid and is associated with this subscription.
What could be wrong? I have created the application and given it the following permissions:
Windows Azure Service Management
Application Permissions: 0
Delegated Permissions: 1
Access Azure Service Management as organization users (preview)
Windows Azure Active Directory
Application Permissions: 0
Delegated Permissions: 1
Sign in and read user profile
Thanks in advance
Chris