图 API 获取密码过期

Graph API to get Password expiry

几天前,我一直在努力解决 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" 返回了 null 值。 我还尝试通过 open id apis.

使用用户信息端点
https://login.microsoftonline.com/ceppr.onmicrosoft.com/.well-known/openid-configuration

Openid用户信息端点api在下方,

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

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

没有。您无法从 "resulttoken.UserInfo".

获取密码到期日期

首先,您应该无法从令牌中获取用户信息。其次,即使获取了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)

类似的可以参考post .

可以考虑用下面的图API调用;

要求:

GET 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.

希望这对您有所帮助。