Microsoft Graph クライアントを使用して、"ActivityFeed.Read" アクセス許可を持つ Azure AD アプリケーションを作成しようとしています。以下のサンプルではアプリケーションが正常に作成されますが、このアプリケーションから生成されたトークンにはロール「ActivityFeed.Read」が含まれていません。Azure ポータルに移動し、新しく作成したアプリケーションに簡単な変更を加えて手動で保存し、1 分間待つと、生成されたトークンに必要なロールが含まれます。
public static void AddApplication()
{
ActiveDirectoryClient activeDirectoryClient = AuthenticationHelper.GetActiveDirectoryClientAsUser();
Application appObject = new Application { DisplayName = "MyNewTest" };
appObject.IdentifierUris.Add("https://localhost/MyNewTest/" + Guid.NewGuid());
appObject.ReplyUrls.Add("https://localhost/MyNewTest");
appObject.Homepage = "https://localhost/MyNewTest/home";
// Add Office 365 Management APIs
RequiredResourceAccess app1 = new RequiredResourceAccess();
app1.ResourceAppId = "c5393580-f805-4401-95e8-94b7a6ef2fc2";
//ActivityFeed.Read Role
app1.ResourceAccess.Add(new ResourceAccess() { Id = Guid.Parse("594c1fb6-4f81-4475-ae41-0c394909246c"), Type = "Role" });
appObject.RequiredResourceAccess.Add(app1);
PasswordCredential passWordCredential = new PasswordCredential
{
StartDate = DateTime.UtcNow,
EndDate = DateTime.UtcNow.AddYears(1),
Value = "xxxxxxxxxx"
};
appObject.PasswordCredentials.Add(passWordCredential);
activeDirectoryClient.Applications.AddApplicationAsync(appObject).Wait();
ServicePrincipal newServicePrincpal = new ServicePrincipal();
if (appObject != null)
{
newServicePrincpal.DisplayName = appObject.DisplayName;
newServicePrincpal.AccountEnabled = true;
newServicePrincpal.AppId = appObject.AppId;
activeDirectoryClient.ServicePrincipals.AddServicePrincipalAsync(newServicePrincpal).Wait();
}
}
以下は、新しいアプリケーションを作成した直後の oauth2 認証用のデコードされた jwt トークン データです。
{
"aud": "https://manage.office.com",
"iss": "https://sts.windows.net/de473ccc-dbc5-4625-8006-11e0e3ea8b7d/",
"iat": 1455531167,
"nbf": 1455531167,
"exp": 1455535067,
"appid": "71da9ffb-b583-43c4-bb7a-9c6e1fe30624",
"appidacr": "1",
"idp": "https://sts.windows.net/de473ccc-dbc5-4625-8006-11e0e3ea8b7d/",
"oid": "36a47844-98e8-44d5-b69e-cf114772d1d3",
"sub": "36a47844-98e8-44d5-b69e-cf114772d1d3",
"tid": "de473ccc-dbc5-4625-8006-11e0e3ea8b7d",
"ver": "1.0"
}
以下は、手動で変更を加えて保存した後、oauth2 認証用にデコードされた jwt トークン データです。
{
"aud": "https://manage.office.com",
"iss": "https://sts.windows.net/de473ccc-dbc5-4625-8006-11e0e3ea8b7d/",
"iat": 1455531317,
"nbf": 1455531317,
"exp": 1455535217,
"appid": "71da9ffb-b583-43c4-bb7a-9c6e1fe30624",
"appidacr": "1",
"idp": "https://sts.windows.net/de473ccc-dbc5-4625-8006-11e0e3ea8b7d/",
"oid": "36a47844-98e8-44d5-b69e-cf114772d1d3",
"roles": [
"ActivityFeed.Read"
],
"sub": "36a47844-98e8-44d5-b69e-cf114772d1d3",
"tid": "de473ccc-dbc5-4625-8006-11e0e3ea8b7d",
"ver": "1.0"
}
必要な役割を持つアプリケーションをプログラムで作成する方法を教えてください。