現在、新しい環境の要求があるたびに、Azure Active Directory でアプリケーションを手動で作成しています。REST API を介してコードからこれらのアプリケーションを作成する方法を模索していました。示されているように、「client_credentials」を使用して、既存のアプリケーションでユーザーとグループを作成することに成功しました。
ClientCredential clientCred = new ClientCredential(clientID, clientSecret);
AuthenticationResult authenticationResult = await authenticationContext.AcquireTokenAsync(resAzureGraphAPI, clientCred);
同様の方法で、上から生成された「access_token」を使用して、新しいアプリケーション adClient.Applications.AddApplicationAsync(newApplication).Wait() を作成しようとしました
しかし、これは「操作を完了するのに十分な権限がありません」というエラーをスローします。
他のスレッドと Azure AD msdn ページを調べたところ、client_credentials フローがアプリケーションの作成/更新をサポートしていないことがわかりました。
クライアント資格情報フローを使用して Azure AD にプログラムでアプリケーションを追加する
上記のスレッドでは、「grant_type=password」フローを使用することによる回避策についても言及されています。提案どおりに試しましたが、意味をなさない次のエラーが引き続き発生します。
"error": "invalid_grant",
"error_description": "AADSTS50034: To sign into this application the account must be added to the 1283y812-2u3u-u293u91-u293u1 directory.\r\nTrace ID: 66da9cf9-603f-4f4e-817a-cd4774619631\r\nCorrelation ID: 7990c26f-b8ef-4054-9c0b-a346aa7b5035\r\nTimestamp: 2016-02-21 23:36:52Z",
"error_codes": [
50034
],
これが、私がヒットしているペイロードとエンドポイントです。渡されるユーザーは、アプリケーションを作成する AD の所有者です
endpoint:https://login.windows.net/mytenantID/oauth2/token
post data
resource 00000002-0000-0000-c000-000000000000
client_id id
client_secret secret
grant_type password
username principal@mydomain.com
password password
scope openid
私が間違っている可能性がある場所についての考えや提案をいただければ幸いです。