Azure AD B2C 密码过期

Azure AD B2C password expiration

我们在我们的解决方案中利用 Azure AD B2C 和 "sign up or sign in" 策略。定期(我没有计算确切的天数),当我尝试登录时,我得到:"invalid username or password"。我必须重设密码才能使其正常工作。

所以我有两个问题:

谢谢!

Is there a default password expiration policy?

对于 B2C 本地帐户:

注意:本地帐户只能通过注册或 AAD Graph API 创建。您不能通过在 B2C 租户的 AAD 中单击新用户来创建它。

本地账户默认没有密码过期策略。Azure AD B2C的注册、注册或登录和密码重置策略使用"strong" 密码强度,并且不要让 Azure AD B2C 中的本地帐户 的任何密码 过期。你可以在 this FAQ.

中看到这个

但是,在某些情况下,您可能会遇到 B2C 本地帐户用户密码过期的情况。

  • 默认情况下,如果本地帐户是通过内置密码策略创建的,则此策略会将 passwordPolicies 属性 设置为 DisablePasswordExpiration。所以B2C本地用户的密码不会过期

  • 但是,如果本地帐户是由自定义策略或 Azure AD Graph API 创建的,则必须将 passwordPolicies 属性 设置为手动 DisablePasswordExpiration

因此,如果您未将密码策略的 属性 设置为 DisablePasswordExpiration

,则如果您的本地用户的密码可能会在 90 天后过期,恕不另行通知

Is there any way to remove this default behavior (i.e. no expiration)? The message "invalid username or password" is misleading and should be "your password has expired". Any way to change that?

本地账户解析:

  1. 可参考this example通过AAD Graph创建B2C本地无密码过期用户API:

    POST https://graph.windows.net/contosob2c.onmicrosoft.com/users?api-version=1.6
    Authorization: Bearer eyJhbGciOiJSUzI1NiIsIng1dCI6IjdkRC1nZWNOZ1gxWmY3R0xrT3ZwT0IyZGNWQSIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJod...
    Content-Type: application/json
    Content-Length: 338
    {
    // All of these properties are required to create consumer users.
    "accountEnabled": true,
    "signInNames": [                            // controls which identifier the user uses to sign in to the account
        {
            "type": "emailAddress",             // can be 'emailAddress' or 'userName'
            "value": "joeconsumer@gmail.com"
        }
    ],
    "creationType": "LocalAccount",            // always set to 'LocalAccount'
    "displayName": "Joe Consumer",                // a value that can be used for displaying to the end user
    "mailNickname": "joec",                        // an email alias for the user
    "passwordProfile": {
        "password": "P@ssword!",
        "forceChangePasswordNextLogin": false   // always set to false
    },
    "passwordPolicies": "DisablePasswordExpiration"
    }
    
  2. 通过 AAD Graph PATCH 方法将受影响用户的密码策略 属性 更新为 DisablePasswordExpiration API,您可以参考this documentation更新您的b2c用户。

  3. 要求所有受影响的 B2C 用户更改密码。


对于社交帐户:

密码过期取决于身份提供商的密码策略。 AAD can also be an identity provider in AAD B2C.

仅适用于工作或学校帐户的 AAD 密码过期政策。可应用于在 Azure AD 中创建和管理的用户帐户的可用密码策略设置。

因此,如果您将 AAD 作为 AAD B2C 的社交帐户,密码过期策略将影响这些社交帐户。

AAD 社交帐户的解决方案:

如果您的帐户是 Azure AD 中的社交帐户,请使用您的公司管理员凭据连接到该租户。 执行以下命令之一:

  1. 要将一个用户的密码设置为永不过期,运行 使用用户主体名称 (UPN) 或用户 ID 的以下 cmdlet:Set-MsolUser -UserPrincipalName <user ID> -PasswordNeverExpires $true

  2. 要将组织中所有用户的密码设置为永不过期,运行 以下 cmdlet:Get-MSOLUser | Set-MsolUser -PasswordNeverExpires $true

您可以在 this document 中查看有关 Azure AD 密码策略的更多详细信息。