2

I have the following code:

var authority = "https://login.microsoftonline.com/XXX-XXXX-XXXXX-XXXXXX/oauth2/authorize";
var clientId = "YYY-YYYY-YYYYY-YYYYYY";
var appKey = "xxxxxxxxxxxxx";
var resource = "https://management.core.windows.net/";
var authContext = new AuthenticationContext(authority, true);
var clientCredential = new ClientCredential(clientId, appKey);
var result = authContext.AcquireToken(resource, clientCredential);
var token = result.AccessToken;
var creds = new TokenCloudCredentials("ZZZ-ZZZZ-ZZZZZ-ZZZZZZ", token);
var client = new WebSiteManagementClient(creds);
var data = client.WebSites.Get("eastuswebspace", "some-site", new WebSiteGetParameters());

I am getting this error on the client.WebSites.Get() call:

The server failed to authenticate the request. Verify that the certificate is valid and is associated with this subscription

But I am not using a certificate, I am using AuthenticationContext.

What am I doing wrong?

Brendan Green
  • 11,676
  • 5
  • 44
  • 76
  • Looks like a site-specific error. Do they really support authentication through the M$'s library? Maybe for another URL? Looking at the raw packets data may shed some light on what exactly is happening. – ivan_pozdeev Jun 08 '16 at 01:09
  • https://msdn.microsoft.com/en-us/library/azure/dn645542.aspx shows how OAuth authentication works at network level. If it indeed looks like this and the 3rd party server rejects your token, this means it doesn't support OAuth or you provide incorrect codes or something. – ivan_pozdeev Jun 08 '16 at 01:15
  • Please see my answer here: http://stackoverflow.com/questions/35190866/error-making-azure-management-library-api-call-when-authenticating-with-azure-ac/35194706#35194706. – Gaurav Mantri Jun 08 '16 at 02:42
  • What is the specific nuget and version that you're using? – juvchan Jun 08 '16 at 23:42

0 Answers0