【发布时间】:2014-05-15 14:21:12
【问题描述】:
这是我在这里的第一篇文章,所以请对我温柔一点! :)
我正在尝试使用 Azure ACS(即 Office 365)作为身份验证系统来开发应用程序。事物的身份验证方面似乎运行良好,我被重定向到 Office 365 登录页面并且可以成功登录。然后我的代码使用 Graph API 获取有关该用户的其他信息。
我正在努力获取登录人所属的 AD 组的列表。当我请求组列表时,仅取回 Office 365 安全角色。
这是我所做的(我希望我已经包含了所有相关的内容)
从 Azure 内部;
- 进入活动目录
- 选择了我的域(来自本地 AD 的 DirSync)
- 创建了一个新应用程序
- 允许读取目录数据并启用登录和读取用户配置文件
- 创建了一个新密钥
在我的测试应用中;
- 创建了一个新的 Web 应用程序(标准 Web 表单)
- 使用身份和访问设置来指定“用户提供企业身份”
- 将 clientID 和密码添加到 app.settings 文件中
- 添加了 Windows Azure Active Directory Graph Helper 项目
这是我的相关代码
IPrincipal myPrincipal = this.User;
//get the tenantName
string tenantName = ClaimsPrincipal.Current.FindFirst("http://schemas.microsoft.com/identity/claims/tenantid").Value;
// retrieve the clientId and password values from the Web.config file
string clientId = Properties.Settings.Default.ClientID;
string password = Properties.Settings.Default.Password;
// get a token using the helper
AADJWTToken token = DirectoryDataServiceAuthorizationHelper.GetAuthorizationToken(tenantName, clientId, password);
// initialize a graphService instance using the token acquired from previous step
DirectoryDataService graphService = new DirectoryDataService(tenantName, token);
User myUser = graphService.users.Where(it => (it.userPrincipalName == myPrincipal.Identity.Name)).SingleOrDefault();
graphService.LoadProperty(myUser, "memberOf");
List<Role> currentRoles = myUser.memberOf.OfType<Role>().ToList();
当我运行我的代码时,currentRoles 只包含“公司管理员”而不是我所属的其他组。
我已经阅读了很多关于如何通过命名空间添加规则的文章,但这似乎与使用 Windows ACS 有关。
我可能错过了一个非常基本的步骤,并且会永远感激朝着正确方向轻推:)
谢谢, 达伦
【问题讨论】:
标签: c# authentication azure adfs2.0 acs