Tag: active directory

如何将AcquireTokenAsync中收到的令牌与Active Directory一起存储

问题陈述 我正在使用.NET Core,我正在尝试将Web应用程序与Web API进行对话。 两者都要求使用所有类的[Authorize]属性进行身份validation。 为了能够在服务器到服务器之间进行通信,我需要检索validation令牌。 由于Microsoft教程 ,我已经能够做到这一点。 问题 在本教程中,他们使用对AcquireTokenByAuthorizationCodeAsync的调用来将令牌保存在缓存中,以便在其他地方,代码可以只执行AcquireTokenSilentAsync ,这不需要去管理局validation用户。 此方法不查找令牌缓存,而是将结果存储在其中,因此可以使用其他方法(如AcquireTokenSilentAsync)查找它 当用户已经登录时会出现问题。由于没有收到授权, OpenIdConnectEvents.OnAuthorizationCodeReceived永远不会调用存储在OpenIdConnectEvents.OnAuthorizationCodeReceived的方法。 只有在重新登录时才会调用该方法。 当用户仅通过cookievalidation时,还有另一个事件叫做: CookieAuthenticationEvents.OnValidatePrincipal 。 这是有效的,我可以获得令牌,但我必须使用AcquireTokenAsync ,因为那时我没有授权码。 根据文件,它 从权限获取安全令牌。 这使得调用AcquireTokenSilentAsync失败,因为令牌尚未缓存。 而且我宁愿不总是使用AcquireTokenAsync ,因为这总是发给管理局。 题 如何判断AcquireTokenAsync的令牌AcquireTokenAsync被缓存,以便我可以在其他地方使用AcquireTokenSilentAsync ? 相关代码 这一切都来自主Web应用程序项目中的Startup.cs文件。 这是事件处理的完成方式: app.UseCookieAuthentication(new CookieAuthenticationOptions() { Events = new CookieAuthenticationEvents() { OnValidatePrincipal = OnValidatePrincipal, } }); app.UseOpenIdConnectAuthentication(new OpenIdConnectOptions { ClientId = ClientId, Authority = Authority, PostLogoutRedirectUri = […]

c#检查一个组的用户成员?

我有一个代码,用于检查用户是否是AD的成员,工作得很好, 现在我想添加检查用户是否也是组成员的可能性! 我需要修改什么来实现这一点,我做了一些工作,但它失败了! 所以这是我的代码: //Authenticate a User Against the Directory private bool Authenticate(string userName,string password, string domain) { if (userName == “” || password == “”) { return false; } bool authentic = false; try { DirectoryEntry entry = new DirectoryEntry(“LDAP://” + domain,userName, password); object nativeObject = entry.NativeObject; authentic = true; } catch (DirectoryServicesCOMException) { […]

在.NET Web应用程序中获取登录用户的UPN或电子邮件

我不是.NET开发人员,我觉得这对于以下人员来说是微不足道的: 我有一个C#Web应用程序,它使用户获得登录用户的用户凭据。 目前它使用来自的SID System.Security.Principal.WindowsIdentity.GetCurrent().User.Value 我需要获取用户UPN登录或电子邮件地址(在活动目录中定义)而不是SID。 GetCurrent()返回一个WindowsIdentity类型的对象; 查看WindowsIdentity成员的详细信息: MSDN:WindowsIdentity成员 我看不到任何看起来会给我UPN或电子邮件的内容。 如何通过将SID提供给其他function或首先调用不同的function来提取要使用的信息。

如何获取UserPrincipal类未表示的Active Directory属性

我的意思是,现在我正在使用System.DirectoryServices.AccountManagement,如果我使用UserPrincipal类,我只看到名称,中间名等 所以在我的代码中它就像 UserPrincipal myUser = new UserPrincipal(pc); myUser.Name = “aaaaaa”; myUser.SamAccountName = “aaaaaaa”; . . . . myUser.Save(); 我怎样才能看到像移动或信息这样的属性?

从给定AD组中的Active Directory获取用户列表

我有搜索部门中所有用户的代码: string Department = “Billing”; DirectorySearcher LdapSearcher = new DirectorySearcher(); LdapSearcher.PropertiesToLoad.Add(“displayName”); LdapSearcher.PropertiesToLoad.Add(“cn”); LdapSearcher.PropertiesToLoad.Add(“department”); LdapSearcher.PropertiesToLoad.Add(“title”); LdapSearcher.PropertiesToLoad.Add(“memberOf”); LdapSearcher.Filter = string.Format(“(&(objectClass=user)(department={0}))”, Department); SearchResultCollection src = LdapSearcher.FindAll(); 如果我只想要“经理只读”AD组中的每个人,filter需要看起来像什么? 我错了吗?

从LDAP查询用户组

如何从C#.NET for ASP中的LDAP活动目录中获取用户组用户。 在我的场景中,我想将用户名传递给从LDAP Active目录查询的方法,并告诉我我的用户是此用户组的成员。 请帮帮我

如何从Active Directory获取用户的电子邮件地址?

我试图在AD中获取用户的电子邮件地址但没有成功。 String account = userAccount.Replace(@”Domain\”, “”); DirectoryEntry entry = new DirectoryEntry(); try { DirectorySearcher search = new DirectorySearcher(entry); search.PropertiesToLoad.Add(“mail”); // e-mail addressead SearchResult result = search.FindOne(); if (result != null) { return result.Properties[“mail”][0].ToString(); } else { return “Unknown User”; } } catch (Exception ex) { return ex.Message; } 任何人都可以看到问题或指向正确的方向吗?

列出活动目录中的所有计算机

我想知道如何从活动目录中获取所有计算机/机器/ PC的列表? (试图让这个页面成为搜索引擎诱饵,会回复自己。如果有人有更好的回复,我会接受)

如何从AD DirectoryEntry获取DOMAIN \ USER?

如何从Active Directory DirectoryEntry(SchemaClassName =“user”)对象获取Windows用户和域? 用户名在sAMAccountName属性中,但在哪里可以查找域名? (我不能假设一个固定的域名,因为用户来自不同的子域名。)

在Active Directory中创建用户:连接到系统的设备无法运行

请考虑此代码尝试创建Active Directory帐户。 它在这里使用一组特定数据生成exception。 目前尚不清楚导致exception的原因。 var user = new UserPrincipal(someValidUserContext, “.x-xyz-t-FooFooBarTest”, “somePwd”, true); user.UserPrincipalName = “.x-xyz-t-FooFooBarTest@foobarbatbaz.net”; user.SamAccountName = “.x-xyz-t-FooFooBarTest”; user.DisplayName = “Some String 16 chars long”; user.Name = “Some String 16 chars long”; user.Description = “Foo BarBaz 12 more characters”; user.AccountExpirationDate = someDateInFuture; user.UserCannotChangePassword = true; user.Save(); // exception thrown on Save(): // A device attached […]