Hello guys,
My company is participant of Microsoft Cloud Solution Parther program. Now we are investigating how to admin AD users of our clients. The first task is reset a password for user from client's AD. We have an access to all our clients via Partner web application
(https://portal.office.com/Partner/Default.aspx) Using my company admin's credentials it is possible to open admin center for each client. It is turned out that being logged as my company admin I can manage users from client's AD. For example, I logged as
admin@mycompanysb.onmicrosoft.com but can manage any user from
customer1mycompanysb.onmicrosoft.com domain. (mycompanysb
is partner for customer1). Now I want to reset a password for one user in customer1mycompanysb.onmicrosoft.com domain programmatically. Here is the code:
string authString = string.Format("https://login.windows.net/{0}", "mycompanysb.onmicrosoft.com");
var authenticationContext = new AuthenticationContext(authString, false);
var clientCred = new ClientCredential(clientId, clientSecret);
string resource = "https://graph.windows.net";
AuthenticationResult authenticationResult = authenticationContext.AcquireToken(resource, clientCred);
string adToken = authenticationResult.AccessToken;
Customer.ResetAdminPassword("cust1mycompanysb.onmicrosoft.com", adToken);
...
public static void ResetAdminPassword(string domain, string saToken)
{
var client = new RestJsonClient(string.Format("https://graph.windows.net/{0}/users/admin@{0}?api-version={1}", domain, "1.6"));
var request = new RestRequest(Method.PATCH);
request.AddHeader("Authorization", " Bearer " + saToken);
dynamic body =
new {
passwordProfile = new
{
password = "Password1",
forceChangePasswordNextLogin = false
}
};
request.AddJsonBody(body);
client.Execute(request);
}
and I got a 400 response with message "Invalid domain name in the request url." in
Customer.ResetAdminPassword("cust1mycompanysb.onmicrosoft.com", adToken);
however the password can be set for mycompany without error:
Customer.ResetAdminPassword("mycompanysb.onmicrosoft.com", adToken);
How I should obtain token that would be applicable for cust1mycompanysb.onmicrosoft.com domain too?