Espacio de nombres: microsoft.graph
Importante
Las API de la versión /beta de Microsoft Graph están sujetas a cambios. No se admite el uso de estas API en aplicaciones de producción. Para determinar si una API está disponible en la versión 1.0, use el selector de Versión.
Actualice las propiedades de los estados del método de autenticación de un usuario. Use esta API para actualizar la siguiente información:
Esta API está disponible en las siguientes implementaciones en la nube nacional.
| Servicio global |
Administración pública de EE. UU. |
Gobierno de EE. UU. L5 (DOD) |
China operado por 21Vianet |
| ✅ |
✅ |
✅ |
✅ |
Permissions
Elija el permiso o los permisos marcados como con privilegios mínimos para esta API. Use uno o varios permisos con privilegios más altos solo si la aplicación lo requiere. Para obtener más información sobre los permisos delegados y de aplicación, consulte Tipos de permisos. Para obtener más información sobre estos permisos, consulte la referencia de permisos.
Permisos para actualizar la MFA preferida por el sistema
| Tipo de permiso |
Permisos con privilegios mínimos |
Permisos con privilegios más altos |
| Delegado (cuenta profesional o educativa) |
UserAuthenticationMethod.ReadWrite |
UserAuthenticationMethod.ReadWrite.All |
| Delegado (cuenta personal de Microsoft) |
No admitida. |
No admitida. |
| Aplicación |
UserAuthenticationMethod.ReadWrite |
UserAuthenticationMethod.ReadWrite.All |
Importante
Para el acceso delegado mediante cuentas profesionales o educativas en las que el usuario que ha iniciado sesión actúa sobre otro usuario, se le debe asignar un rol compatible de Microsoft Entra o un rol personalizado que conceda los permisos necesarios para esta operación. Esta operación admite los siguientes roles integrados, que proporcionan solo el privilegio mínimo necesario:
- Administrador de autenticación
- Administrador de autenticación con privilegios
Cuando los usuarios administran sus propios métodos de autenticación, el sistema les pide que completen la autenticación multifactor (MFA) si se autenticaron por última vez hace más de 10 minutos en la sesión actual.
Permisos para actualizar el estado de MFA por usuario
Permisos que actúan sobre sí mismos
| Tipo de permiso |
Permisos con privilegios mínimos |
Permisos con privilegios más altos |
| Delegado (cuenta profesional o educativa) |
Policy.ReadWrite.AuthenticationMethod |
No disponible. |
| Delegado (cuenta personal de Microsoft) |
No admitida. |
No admitida. |
| Aplicación |
No admitida. |
No admitida. |
Permisos que actúan sobre otros
| Tipo de permiso |
Permisos con privilegios mínimos |
Permisos con privilegios más altos |
| Delegado (cuenta profesional o educativa) |
Policy.ReadWrite.AuthenticationMethod |
No disponible. |
| Delegado (cuenta personal de Microsoft) |
No admitida. |
No admitida. |
| Aplicación |
Policy.ReadWrite.AuthenticationMethod |
No disponible. |
Importante
Para el acceso delegado con cuentas profesionales o educativas, el usuario que ha iniciado sesión debe tener asignado un rol compatible de Microsoft Entra o un rol personalizado que conceda los permisos necesarios para esta operación.
El administrador de directivas de autenticación es el rol con privilegios mínimos admitido para esta operación.
Solicitud HTTP
Para actualizar las preferencias de inicio de sesión (MFA preferida por el sistema) de un usuario:
PATCH /users/{id | userPrincipalName}/authentication/signInPreferences
Para actualizar el estado de autenticación multifactor por usuario para el usuario que ha iniciado sesión:
PATCH /me/authentication/requirements
Nota:
Para llamar al punto de conexión /me, se requiere un usuario con la sesión iniciada y, por lo tanto, un permiso delegado. Los permisos de aplicación no se admiten al usar el /me punto de conexión.
Para actualizar el estado de autenticación multifactor por usuario para un usuario:
PATCH /users/{id | userPrincipalName}/authentication/requirements
| Nombre |
Descripción |
| Authorization |
{token} de portador. Obligatorio. Obtenga más información sobre autenticación y autorización. |
| Content-Type |
application/json. Obligatorio. |
Cuerpo de la solicitud
En el cuerpo de la solicitud, proporcione solo los valores de las propiedades que se van a actualizar. Las propiedades existentes que no están incluidas en el cuerpo de la solicitud mantienen sus valores anteriores o se recalculan en función de los cambios realizados en otros valores de propiedad.
En la tabla siguiente se especifican las propiedades que se pueden actualizar.
| Propiedad |
Tipo |
Descripción |
| isSystemPreferredAuthenticationMethodEnabled |
Booleano |
Indica si las preferencias de credenciales del sistema están habilitadas. |
| userPreferredMethodForSecondaryAuthentication |
userDefaultAuthenticationMethodType |
El método de segundo factor predeterminado que usa el usuario al iniciar sesión. Si un usuario está habilitado para la autenticación preferida por el sistema, este valor se omite, excepto en algunos escenarios en los que un usuario se autentica a través de la extensión NPS o el adaptador ADFS. Los valores posibles son push, oath, voiceMobile, voiceAlternateMobilevoiceOfficesms, , yunknownFutureValue |
| perUserMfaState |
perUserMfaState |
El estado del usuario para la autenticación multifactor por usuario. Los valores posibles son enforced, enabled y disabled. |
Respuesta
Si se ejecuta correctamente, este método devuelve un código de respuesta 204 No Content.
Ejemplos
Ejemplo 1: Actualización del método de MFA preferido por el sistema de un usuario
Solicitud
En el ejemplo siguiente se muestra la solicitud.
PATCH https://graph.microsoft.com/beta/users/071cc716-8147-4397-a5ba-b2105951cc0b/authentication/signInPreferences
Content-Type: application/json
{
"userPreferredMethodForSecondaryAuthentication": "oath"
}
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Beta.Models;
var requestBody = new SignInPreferences
{
UserPreferredMethodForSecondaryAuthentication = UserDefaultAuthenticationMethodType.Oath,
};
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
var result = await graphClient.Users["{user-id}"].Authentication.SignInPreferences.PatchAsync(requestBody);
// Code snippets are only available for the latest major version. Current major version is $v0.*
// Dependencies
import (
"context"
msgraphsdk "github.com/microsoftgraph/msgraph-beta-sdk-go"
graphmodels "github.com/microsoftgraph/msgraph-beta-sdk-go/models"
//other-imports
)
requestBody := graphmodels.NewSignInPreferences()
userPreferredMethodForSecondaryAuthentication := graphmodels.OATH_USERDEFAULTAUTHENTICATIONMETHODTYPE
requestBody.SetUserPreferredMethodForSecondaryAuthentication(&userPreferredMethodForSecondaryAuthentication)
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
signInPreferences, err := graphClient.Users().ByUserId("user-id").Authentication().SignInPreferences().Patch(context.Background(), requestBody, nil)
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
SignInPreferences signInPreferences = new SignInPreferences();
signInPreferences.setUserPreferredMethodForSecondaryAuthentication(UserDefaultAuthenticationMethodType.Oath);
SignInPreferences result = graphClient.users().byUserId("{user-id}").authentication().signInPreferences().patch(signInPreferences);
const options = {
authProvider,
};
const client = Client.init(options);
const signInPreferences = {
userPreferredMethodForSecondaryAuthentication: 'oath'
};
await client.api('/users/071cc716-8147-4397-a5ba-b2105951cc0b/authentication/signInPreferences')
.version('beta')
.update(signInPreferences);
<?php
use Microsoft\Graph\Beta\GraphServiceClient;
use Microsoft\Graph\Beta\Generated\Models\SignInPreferences;
use Microsoft\Graph\Beta\Generated\Models\UserDefaultAuthenticationMethodType;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new SignInPreferences();
$requestBody->setUserPreferredMethodForSecondaryAuthentication(new UserDefaultAuthenticationMethodType('oath'));
$result = $graphServiceClient->users()->byUserId('user-id')->authentication()->signInPreferences()->patch($requestBody)->wait();
Import-Module Microsoft.Graph.Beta.Identity.SignIns
$params = @{
userPreferredMethodForSecondaryAuthentication = "oath"
}
Update-MgBetaUserAuthenticationSignInPreference -UserId $userId -BodyParameter $params
# Code snippets are only available for the latest version. Current version is 1.x
from msgraph_beta import GraphServiceClient
from msgraph_beta.generated.models.sign_in_preferences import SignInPreferences
from msgraph_beta.generated.models.user_default_authentication_method_type import UserDefaultAuthenticationMethodType
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
request_body = SignInPreferences(
user_preferred_method_for_secondary_authentication = UserDefaultAuthenticationMethodType.Oath,
)
result = await graph_client.users.by_user_id('user-id').authentication.sign_in_preferences.patch(request_body)
Respuesta
HTTP/1.1 204 No Content
Ejemplo 2: Actualizar el estado de MFA de un usuario
Solicitud
En el ejemplo siguiente se muestra la solicitud.
PATCH https://graph.microsoft.com/beta/users/071cc716-8147-4397-a5ba-b2105951cc0b/authentication/requirements
Content-Type: application/json
{
"perUserMfaState": "disabled"
}
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Beta.Models;
var requestBody = new StrongAuthenticationRequirements
{
PerUserMfaState = PerUserMfaState.Disabled,
};
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
var result = await graphClient.Users["{user-id}"].Authentication.Requirements.PatchAsync(requestBody);
// Code snippets are only available for the latest major version. Current major version is $v0.*
// Dependencies
import (
"context"
msgraphsdk "github.com/microsoftgraph/msgraph-beta-sdk-go"
graphmodels "github.com/microsoftgraph/msgraph-beta-sdk-go/models"
//other-imports
)
requestBody := graphmodels.NewStrongAuthenticationRequirements()
perUserMfaState := graphmodels.DISABLED_PERUSERMFASTATE
requestBody.SetPerUserMfaState(&perUserMfaState)
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
requirements, err := graphClient.Users().ByUserId("user-id").Authentication().Requirements().Patch(context.Background(), requestBody, nil)
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
StrongAuthenticationRequirements strongAuthenticationRequirements = new StrongAuthenticationRequirements();
strongAuthenticationRequirements.setPerUserMfaState(PerUserMfaState.Disabled);
StrongAuthenticationRequirements result = graphClient.users().byUserId("{user-id}").authentication().requirements().patch(strongAuthenticationRequirements);
const options = {
authProvider,
};
const client = Client.init(options);
const strongAuthenticationRequirements = {
perUserMfaState: 'disabled'
};
await client.api('/users/071cc716-8147-4397-a5ba-b2105951cc0b/authentication/requirements')
.version('beta')
.update(strongAuthenticationRequirements);
<?php
use Microsoft\Graph\Beta\GraphServiceClient;
use Microsoft\Graph\Beta\Generated\Models\StrongAuthenticationRequirements;
use Microsoft\Graph\Beta\Generated\Models\PerUserMfaState;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new StrongAuthenticationRequirements();
$requestBody->setPerUserMfaState(new PerUserMfaState('disabled'));
$result = $graphServiceClient->users()->byUserId('user-id')->authentication()->requirements()->patch($requestBody)->wait();
Import-Module Microsoft.Graph.Beta.Identity.SignIns
$params = @{
perUserMfaState = "disabled"
}
Update-MgBetaUserAuthenticationRequirement -UserId $userId -BodyParameter $params
# Code snippets are only available for the latest version. Current version is 1.x
from msgraph_beta import GraphServiceClient
from msgraph_beta.generated.models.strong_authentication_requirements import StrongAuthenticationRequirements
from msgraph_beta.generated.models.per_user_mfa_state import PerUserMfaState
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
request_body = StrongAuthenticationRequirements(
per_user_mfa_state = PerUserMfaState.Disabled,
)
result = await graph_client.users.by_user_id('user-id').authentication.requirements.patch(request_body)
Respuesta
HTTP/1.1 204 No Content