0
Microsoft apiを使用してOffice 365でユーザーを作成できるC#.netのサンプルアプリケーションが必要です。私はコードでそれをやってみたい、電源シェルを使用していません。動的にC#.netコードを使用してOffice 365でユーザーアカウントを作成する
Microsoft apiを使用してOffice 365でユーザーを作成できるC#.netのサンプルアプリケーションが必要です。私はコードでそれをやってみたい、電源シェルを使用していません。動的にC#.netコードを使用してOffice 365でユーザーアカウントを作成する
あなたはMicrosoftグラフAPIを使用することができます - Create User:
許可「ディレクトリデータを読み書き」>「マイクロソフトグラフ」を割り当てる、アズールAD上でネイティブクライアントアプリケーションを登録します。
string authority = "https://login.windows.net/yourdomain.onmicrosoft.com";
string clientId = "{app_client_id}";
Uri redirectUri = new Uri("http://localhost");
string resourceUrl = "https://graph.microsoft.com";
HttpClient client = new HttpClient();
AuthenticationContext authenticationContext = new AuthenticationContext(authority, false);
AuthenticationResult authenticationResult = authenticationContext.AcquireToken(resourceUrl,
clientId, redirectUri, PromptBehavior.Always);
client.DefaultRequestHeaders.Add("Authorization", "Bearer " + authenticationResult.AccessToken);
string content = @"{
'accountEnabled': true,
'displayName': 'testuser',
'mailNickname': 'test',
'passwordProfile': {
'forceChangePasswordNextSignIn': true,
'password': '[email protected]'
},
'userPrincipalName': '[email protected]'
}";
var httpContent = new StringContent(content, Encoding.GetEncoding("utf-8"), "application/json");
var response = client.PostAsync("https://graph.microsoft.com/v1.0/users", httpContent).Result;
Console.WriteLine(response.Content.ReadAsStringAsync().Result);
タイプ「にSystem.FormatException」の未処理の例外はMicrosoft.IdentityModel.Clients.ActiveDirectory.dll – bijupranavam
で発生しました追加情報:インデックス(ゼロベースの)はゼロ以上でなければならず、引数リストのサイズより小さい – bijupranavam
"app_client_id"を実際のアプリクライアントID(例:dcd68e75-54d4-xxxx-9dfb-xxxx3833ec1a、 '{'と '}'なし)に置き換えてください。そして、あなたの実際のドメイン名で 'yourdomain'を置き換えてください。 –