【问题标题】:Graph API to get Password expiry用于获取密码到期的图形 API
【发布时间】:2020-03-26 19:08:48
【问题描述】:

几天以来,我一直在努力解决 ADAL/MSAL Graph API 实现的一个问题,以获取用户密码到期日期。我试过下面的代码,

var authContext = new Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext(ADsettings.AADInstance + ADsettings.Tenant);

var clientCred = new Microsoft.IdentityModel.Clients.ActiveDirectory.ClientCredential(ADsettings.AppTokenClientID, ADsettings.ClientSecret);

Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationResult resulttoken = await authContext.AcquireTokenAsync(ADsettings.ResourceId, clientCred);

但幸运的是,这不起作用,因为“resulttoken.UserInfo”返回了空值。 我还尝试通过开放 id api 使用用户信息端点。

https://login.microsoftonline.com/ceppr.onmicrosoft.com/.well-known/openid-configuration

Openid用户信息端点api如下,

https://login.microsoftonline.com/87268ca1-*************************9cf131cc33ac/openid/userinfo

但这对我也不起作用。 我需要您的帮助才能从 Azure AD 中检索密码到期日期。请 提供一些意见或解决方案。

【问题讨论】:

    标签: c# adal msal


    【解决方案1】:

    没有。您无法从“resulttoken.UserInfo”中获取密码到期日期。

    首先,您应该无法从令牌中获取用户信息。其次,即使你得到了用户信息,你也不会得到密码的有效期。

    我认为我们目前无法通过 Microsoft Graph API 获得它。

    相关信息只能从Powershell获取。

    您可以使用Get-MsolUser -UserPrincipalName 'Username' |Select LastPasswordChangeTimestamp 获取LastPasswordChangeTimestamp,这表示此 Azure AD 用户上次更改密码的时间。

    那么你需要从密码策略中获取密码有效性:

    $PasswordPolicy = Get-MsolPasswordPolicy
    $UserPrincipal  = Get-MsolUser -UserPrincipalName 'Username'
    
    $PasswordExpirationDate = $UserPrincipal.LastPasswordChangeTimestamp.AddDays($PasswordPolicy.ValidityPeriod)
    

    您可以参考类似的帖子here

    【讨论】:

      【解决方案2】:

      您可以考虑使用以下 Graph API 调用;

      请求:

      获取 https://graph.microsoft.com/beta/users/{userPrincipalName}?$select=displayName,lastPasswordChangeDateTime

      回应:

      {
      
          "@odata.context": "https://graph.microsoft.com/beta/$metadata#users(displayName,lastPasswordChangeDateTime)/$entity",
      
          "displayName": "User 1",
      
          "lastPasswordChangeDateTime": "2017-11-09T07:29:09Z"
      
      }
      

      您可以找到有关此here.的详细信息

      希望这会有所帮助。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-05-07
        • 2016-04-09
        • 1970-01-01
        • 1970-01-01
        • 2017-09-03
        相关资源
        最近更新 更多