How to authenticate Azure Service management requests through AAD

I tried 3 ways with no result:

var context = new AuthenticationContext($"https://login.windows.net/{tenantId}"); var result = context.AcquireToken("https://management.core.windows.net/", clientId, new Uri(redirectUri)); 

but the failure is ruled out:

 Microsoft.IdentityModel.Clients.ActiveDirectory.AdalServiceException was unhandled Message: An unhandled exception of type 'Microsoft.IdentityModel.Clients.ActiveDirectory.AdalServiceException' occurred in Microsoft.IdentityModel.Clients.ActiveDirectory.dll Additional information: AADSTS90014: The request body must contain the following parameter: 'client_secret or client_assertion'. Trace ID: aa2d6962-5aea-4f8e-bed4-9e83c7631887 Correlation ID: f7f1a61e-1720-4243-96fa-cff182150931 
  1. Also I tried:
  var context = new AuthenticationContext($"https://login.windows.net/{tenantId}"); var result = context.AcquireToken("https://management.core.windows.net/", new ClientCredential(clientId, clientSecret)); 

where clientSecret is the application secret key of my application. This version returns a token, but requests with this token are returned 403 Forbidden: the server was unable to authenticate the request. Verify that the certificate is valid and associated with this subscription.

  1. Last, I found http://blogs.msdn.com/b/cloud_solution_architect/archive/2015/03/02/authenticating-azure-service-management-api-with-azure-ad-user-credentials.aspx which recommends :
  var context = new AuthenticationContext(string.Format("https://login.windows.net/{0}", tenantId)); // TODO: Replace with your Azure AD user credentials (ie admin@contoso.onmicrosoft.com ) string user = "{YOUR-USERID]"; string pwd = "{YOUR-USER-PASSWORD}"; var userCred = new UserCredential(user, pwd); AuthenticationResult result = await context.AcquireTokenAsync("https://management.core.windows.net/", clientId, userCred); 

but he also fails with the same exception as in the first case ...

Could you help me?

+7
authentication c # azure azure-active-directory azure-management-api
source share
1 answer

When creating an application on the Azure portal, you must change the "Application Type" to "APPLY A NATIONAL CLIENT."

+7
source share

All Articles