1

Azure AD を使用して、ロール ベースの承認 mvc アプリケーションを作成しようとしています。

Azure ポータルから、次のことができます。

  • ユーザーとグループを作成します。
  • ユーザーをグループに割り当てます。
  • アプリケーションの役割を作成します。
  • アプリケーション ロールを作成するには (マニフェストを変更して)
  • ユーザーにアプリケーション ロールを割り当てるには。

無料の Azure Active Directory エディションを入手したばかりで、 Microsoft Azure Active Directoryを使用してこれらのアクションを実行できることを読みました。

  • 複数のアプリケーション ロールをユーザーに割り当てる。
  • 複数のアプリケーション ロールをグループに割り当てる。

Microsoft はAAD を照会するための優れたサンプルを提供しており、私はそれを使い始めましたが、アプリケーションをグループに割り当てる方法がわかりません。

グループを取得するための擬似コードは次のとおりです。

ActiveDirectoryClient client = AuthenticationHelper.GetActiveDirectoryClient();
var app = (await client.Applications.GetByObjectId("applicationObjectId").ExecuteAsync());
var servicePrincipal = await client.ServicePrincipals.GetByObjectId("servicePrincipalObjectId").ExecuteAsync();
var appRole = app.AppRoles.First(r => r.DisplayName == "my role");
var mygroup = (await client.Groups.ExecuteAsync()).CurrentPage.FirstOrDefault();           

私がやりたいことはそのようなものです:

mygroup .AppRoleAssignments.Add(new AppRoleAssignment()
{
    ResourceId = Guid.Parse(servicePrincipal.ObjectId),
    Id = appRole.Id,
    PrincipalType = "Group",
    PrincipalId = Guid.Parse(mygroup .ObjectId),
});
await group.UpdateAsync();

しかし、AppRoleAssignments の型は でIPagedCollection<IAppRoleAssignment>あり、Add メソッドはありません。

私のコードで何を変更する必要があるか知っている人はいますか?

4

1 に答える 1

2

実際、それは簡単でした... IGroup を次のようにキャストする必要がありましたGroup

ActiveDirectoryClient client = AuthenticationHelper.GetActiveDirectoryClient();
var app = (await client.Applications.GetByObjectId("applicationObjectId").ExecuteAsync());
var servicePrincipal = await client.ServicePrincipals.GetByObjectId("servicePrincipalObjectId").ExecuteAsync();
var appRole = app.AppRoles.First(r => r.DisplayName == "my role");
var mygroup = (Group)(await client.Groups.ExecuteAsync()).CurrentPage.FirstOrDefault();  

そして、それは正常に動作します^^:

mygroup .AppRoleAssignments.Add(new AppRoleAssignment()
{
    ResourceId = Guid.Parse(servicePrincipal.ObjectId),
    Id = appRole.Id,
    PrincipalType = "Group",
    PrincipalId = Guid.Parse(mygroup .ObjectId),
});
await group.UpdateAsync();
于 2016-01-17T23:00:06.377 に答える