Escolha a permissão ou permissões marcadas como menos privilegiadas para esta API. Utilize uma permissão ou permissões com privilégios mais elevados apenas se a sua aplicação o exigir. Para obter detalhes sobre as permissões delegadas e de aplicação, veja Tipos de permissão. Para saber mais sobre estas permissões, veja a referência de permissões.
Tipo de permissão
Permissões com menos privilégios
Permissões com privilégios superiores
Delegada (conta corporativa ou de estudante)
Policy.ReadWrite.AuthenticationMethod
Indisponível.
Delegado (conta pessoal da Microsoft)
Sem suporte.
Sem suporte.
Aplicativo
Policy.ReadWrite.AuthenticationMethod
Indisponível.
Importante
Em cenários delegados com contas escolares ou profissionais, o utilizador com sessão iniciada tem de ter uma função de Microsoft Entra suportada ou uma função personalizada com uma permissão de função suportada.
O Administrador de Políticas de Autenticação é a função com menos privilégios suportada para esta operação.
No corpo do pedido, forneça apenas os valores das propriedades a atualizar. As propriedades existentes que não estão incluídas no corpo do pedido mantêm os valores anteriores ou são recalculadas com base em alterações a outros valores de propriedade.
A tabela a seguir especifica as propriedades que podem ser atualizadas.
Imponha o registo no tempo de início de sessão. Esta propriedade pode ser utilizada para pedir aos utilizadores que configurem métodos de autenticação direcionados.
Resposta
Se for bem-sucedido, este método devolve um 200 OK código de resposta e um objeto authenticationMethodsPolicy no corpo da resposta.
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Models;
var requestBody = new AuthenticationMethodsPolicy
{
RegistrationEnforcement = new RegistrationEnforcement
{
AuthenticationMethodsRegistrationCampaign = new AuthenticationMethodsRegistrationCampaign
{
SnoozeDurationInDays = 1,
State = AdvancedConfigState.Enabled,
ExcludeTargets = new List<ExcludeTarget>
{
},
IncludeTargets = new List<AuthenticationMethodsRegistrationCampaignIncludeTarget>
{
new AuthenticationMethodsRegistrationCampaignIncludeTarget
{
Id = "3ee3a9de-0a86-4e12-a287-9769accf1ba2",
TargetType = AuthenticationMethodTargetType.Group,
TargetedAuthenticationMethod = "microsoftAuthenticator",
},
},
},
},
};
// To initialize your graphClient, see https://video2.skills-academy.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
var result = await graphClient.Policies.AuthenticationMethodsPolicy.PatchAsync(requestBody);
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
AuthenticationMethodsPolicy authenticationMethodsPolicy = new AuthenticationMethodsPolicy();
RegistrationEnforcement registrationEnforcement = new RegistrationEnforcement();
AuthenticationMethodsRegistrationCampaign authenticationMethodsRegistrationCampaign = new AuthenticationMethodsRegistrationCampaign();
authenticationMethodsRegistrationCampaign.setSnoozeDurationInDays(1);
authenticationMethodsRegistrationCampaign.setState(AdvancedConfigState.Enabled);
LinkedList<ExcludeTarget> excludeTargets = new LinkedList<ExcludeTarget>();
authenticationMethodsRegistrationCampaign.setExcludeTargets(excludeTargets);
LinkedList<AuthenticationMethodsRegistrationCampaignIncludeTarget> includeTargets = new LinkedList<AuthenticationMethodsRegistrationCampaignIncludeTarget>();
AuthenticationMethodsRegistrationCampaignIncludeTarget authenticationMethodsRegistrationCampaignIncludeTarget = new AuthenticationMethodsRegistrationCampaignIncludeTarget();
authenticationMethodsRegistrationCampaignIncludeTarget.setId("3ee3a9de-0a86-4e12-a287-9769accf1ba2");
authenticationMethodsRegistrationCampaignIncludeTarget.setTargetType(AuthenticationMethodTargetType.Group);
authenticationMethodsRegistrationCampaignIncludeTarget.setTargetedAuthenticationMethod("microsoftAuthenticator");
includeTargets.add(authenticationMethodsRegistrationCampaignIncludeTarget);
authenticationMethodsRegistrationCampaign.setIncludeTargets(includeTargets);
registrationEnforcement.setAuthenticationMethodsRegistrationCampaign(authenticationMethodsRegistrationCampaign);
authenticationMethodsPolicy.setRegistrationEnforcement(registrationEnforcement);
AuthenticationMethodsPolicy result = graphClient.policies().authenticationMethodsPolicy().patch(authenticationMethodsPolicy);
<?php
use Microsoft\Graph\GraphServiceClient;
use Microsoft\Graph\Generated\Models\AuthenticationMethodsPolicy;
use Microsoft\Graph\Generated\Models\RegistrationEnforcement;
use Microsoft\Graph\Generated\Models\AuthenticationMethodsRegistrationCampaign;
use Microsoft\Graph\Generated\Models\AdvancedConfigState;
use Microsoft\Graph\Generated\Models\ExcludeTarget;
use Microsoft\Graph\Generated\Models\AuthenticationMethodsRegistrationCampaignIncludeTarget;
use Microsoft\Graph\Generated\Models\AuthenticationMethodTargetType;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new AuthenticationMethodsPolicy();
$registrationEnforcement = new RegistrationEnforcement();
$registrationEnforcementAuthenticationMethodsRegistrationCampaign = new AuthenticationMethodsRegistrationCampaign();
$registrationEnforcementAuthenticationMethodsRegistrationCampaign->setSnoozeDurationInDays(1);
$registrationEnforcementAuthenticationMethodsRegistrationCampaign->setState(new AdvancedConfigState('enabled'));
$registrationEnforcementAuthenticationMethodsRegistrationCampaign->setExcludeTargets([ ]);
$includeTargetsAuthenticationMethodsRegistrationCampaignIncludeTarget1 = new AuthenticationMethodsRegistrationCampaignIncludeTarget();
$includeTargetsAuthenticationMethodsRegistrationCampaignIncludeTarget1->setId('3ee3a9de-0a86-4e12-a287-9769accf1ba2');
$includeTargetsAuthenticationMethodsRegistrationCampaignIncludeTarget1->setTargetType(new AuthenticationMethodTargetType('group'));
$includeTargetsAuthenticationMethodsRegistrationCampaignIncludeTarget1->setTargetedAuthenticationMethod('microsoftAuthenticator');
$includeTargetsArray []= $includeTargetsAuthenticationMethodsRegistrationCampaignIncludeTarget1;
$registrationEnforcementAuthenticationMethodsRegistrationCampaign->setIncludeTargets($includeTargetsArray);
$registrationEnforcement->setAuthenticationMethodsRegistrationCampaign($registrationEnforcementAuthenticationMethodsRegistrationCampaign);
$requestBody->setRegistrationEnforcement($registrationEnforcement);
$result = $graphServiceClient->policies()->authenticationMethodsPolicy()->patch($requestBody)->wait();
# Code snippets are only available for the latest version. Current version is 1.x
from msgraph import GraphServiceClient
from msgraph.generated.models.authentication_methods_policy import AuthenticationMethodsPolicy
from msgraph.generated.models.registration_enforcement import RegistrationEnforcement
from msgraph.generated.models.authentication_methods_registration_campaign import AuthenticationMethodsRegistrationCampaign
from msgraph.generated.models.advanced_config_state import AdvancedConfigState
from msgraph.generated.models.exclude_target import ExcludeTarget
from msgraph.generated.models.authentication_methods_registration_campaign_include_target import AuthenticationMethodsRegistrationCampaignIncludeTarget
from msgraph.generated.models.authentication_method_target_type import AuthenticationMethodTargetType
# To initialize your graph_client, see https://video2.skills-academy.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
request_body = AuthenticationMethodsPolicy(
registration_enforcement = RegistrationEnforcement(
authentication_methods_registration_campaign = AuthenticationMethodsRegistrationCampaign(
snooze_duration_in_days = 1,
state = AdvancedConfigState.Enabled,
exclude_targets = [
],
include_targets = [
AuthenticationMethodsRegistrationCampaignIncludeTarget(
id = "3ee3a9de-0a86-4e12-a287-9769accf1ba2",
target_type = AuthenticationMethodTargetType.Group,
targeted_authentication_method = "microsoftAuthenticator",
),
],
),
),
)
result = await graph_client.policies.authentication_methods_policy.patch(request_body)