Namespace: microsoft.graph
Wichtig
Die APIs unter der /beta Version in Microsoft Graph können sich ändern. Die Verwendung dieser APIs in Produktionsanwendungen wird nicht unterstützt. Um festzustellen, ob eine API in v1.0 verfügbar ist, verwenden Sie die Version Selektor.
Erstellen Sie ein neues hardwareOathTokenAuthenticationMethodDevice-Objekt . Diese API unterstützt zwei Szenarien:
- Erstellen Sie das neue Hardwaretoken, ohne einem Benutzer zuzuweisen. Sie können dann einem Benutzer zuweisen.
- Erstellen Sie ein Hardwaretoken, und weisen Sie es einem Benutzer in derselben Anforderung zu.
Diese API ist in den folgenden nationalen Cloudbereitstellungen verfügbar.
| Weltweiter Service |
US Government L4 |
US Government L5 (DOD) |
China, betrieben von 21Vianet |
| ✅ |
❌ |
❌ |
❌ |
Berechtigungen
Wählen Sie die Berechtigungen aus, die für diese API als am wenigsten privilegiert markiert sind. Verwenden Sie eine höhere Berechtigung oder Berechtigungen nur, wenn Ihre App dies erfordert. Ausführliche Informationen zu delegierten Berechtigungen und Anwendungsberechtigungen finden Sie unter Berechtigungstypen. Weitere Informationen zu diesen Berechtigungen finden Sie in der Berechtigungsreferenz.
| Berechtigungstyp |
Berechtigungen mit den geringsten Berechtigungen |
Berechtigungen mit höheren Berechtigungen |
| Delegiert (Geschäfts-, Schul- oder Unikonto) |
Policy.ReadWrite.AuthenticationMethod |
Nicht verfügbar. |
| Delegiert (persönliches Microsoft-Konto) |
Nicht unterstützt |
Nicht unterstützt |
| Anwendung |
Policy.ReadWrite.AuthenticationMethod |
Nicht verfügbar. |
Wichtig
Wenn delegierte Berechtigungen mit Geschäfts-, Schul- oder Unikonten verwendet werden, muss der angemeldete Benutzer über eine geeignete Microsoft Entra Rolle oder eine benutzerdefinierte Rolle mit den erforderlichen Berechtigungen verfügen. Die für diesen Vorgang erforderliche integrierte Rolle mit den geringsten Berechtigungen ist der Authentifizierungsrichtlinienadministrator.
Um ein Hardware-OATH-Token zu erstellen und einem Benutzer in einer einzelnen Anforderung zuzuweisen, muss der angemeldete Benutzer auch über Folgendes verfügen:
- Die delegierte Berechtigung UserAuthenticationMethod.ReadWrite.All .
- Entweder Authentifizierungsadministrator (Rolle mit den geringsten Berechtigungen zum Zuweisen von Hardwaretoken zu Nichtadministratorbenutzern) oder Privilegierter Authentifizierungsadministrator (Rolle mit den geringsten Berechtigungen zum Zuweisen von Hardwaretoken zu Administratorbenutzern).
HTTP-Anforderung
POST /directory/authenticationMethodDevices/hardwareOathDevices
Anforderungstext
Geben Sie im Anforderungstext eine JSON-Darstellung des HardwareOathTokenAuthenticationMethodDevice-Objekts an.
Sie können die folgenden Eigenschaften angeben, wenn Sie eine hardwareOathTokenAuthenticationMethodDevice erstellen.
| Eigenschaft |
Typ |
Beschreibung |
| serialNumber |
Zeichenfolge |
Seriennummer des spezifischen Hardwaretokens, die sich häufig auf der Rückseite des Geräts befindet. Erforderlich. |
| Hersteller |
Zeichenfolge |
Herstellername des Hardwaretokens. Erforderlich. |
| model |
Zeichenfolge |
Modellname des Hardwaretokens. Erforderlich. |
| secretKey |
Zeichenfolge |
Geheimer Schlüssel des spezifischen Hardwaretokens, der vom Anbieter bereitgestellt wird. Erforderlich. |
| timeIntervalInSeconds |
Int32 |
Aktualisierungsintervall des sechsstelligen Prüfcodes in Sekunden. Die möglichen Werte sind: 30 oder 60. Erforderlich. |
| hashFunction |
hardwareOathTokenHashFunction |
Hashfunktion des Hardwaretokens. Die möglichen Werte sind: hmacsha1 oder hmacsha256. Der Standardwert ist: hmacsha1. Optional. |
| assignTo |
identity |
Benutzer-ID, wenn Sie das Token einem Benutzer direkt zuweisen möchten. Optional. |
| displayName |
Zeichenfolge |
Name, der für das Hardware-OATH-Token bereitgestellt werden kann. Optional. |
Antwort
Bei erfolgreicher Ausführung gibt die Methode den 201 Created Antwortcode und ein hardwareOathTokenAuthenticationMethodDevice-Objekt im Antworttext zurück.
Beispiele
Beispiel 1: Erstellen eines Tokens ohne Benutzerzuweisung
Anforderung
Das folgende Beispiel zeigt eine Anfrage.
POST https://graph.microsoft.com/beta/directory/authenticationMethodDevices/hardwareOathDevices
Content-Type: application/json
{
"displayName": "Token 1",
"serialNumber": "TOTP123456",
"manufacturer": "Contoso",
"model": "Hardware Token 1000",
"secretKey": "6PJ4UKIW33NNXYZAEHQNFUFTZF7WFTFB",
"timeIntervalInSeconds": 30,
"hashFunction": "hmacsha1"
}
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Beta.Models;
var requestBody = new HardwareOathTokenAuthenticationMethodDevice
{
DisplayName = "Token 1",
SerialNumber = "TOTP123456",
Manufacturer = "Contoso",
Model = "Hardware Token 1000",
SecretKey = "6PJ4UKIW33NNXYZAEHQNFUFTZF7WFTFB",
TimeIntervalInSeconds = 30,
HashFunction = HardwareOathTokenHashFunction.Hmacsha1,
};
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
var result = await graphClient.Directory.AuthenticationMethodDevices.HardwareOathDevices.PostAsync(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.NewHardwareOathTokenAuthenticationMethodDevice()
displayName := "Token 1"
requestBody.SetDisplayName(&displayName)
serialNumber := "TOTP123456"
requestBody.SetSerialNumber(&serialNumber)
manufacturer := "Contoso"
requestBody.SetManufacturer(&manufacturer)
model := "Hardware Token 1000"
requestBody.SetModel(&model)
secretKey := "6PJ4UKIW33NNXYZAEHQNFUFTZF7WFTFB"
requestBody.SetSecretKey(&secretKey)
timeIntervalInSeconds := int32(30)
requestBody.SetTimeIntervalInSeconds(&timeIntervalInSeconds)
hashFunction := graphmodels.HMACSHA1_HARDWAREOATHTOKENHASHFUNCTION
requestBody.SetHashFunction(&hashFunction)
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
hardwareOathDevices, err := graphClient.Directory().AuthenticationMethodDevices().HardwareOathDevices().Post(context.Background(), requestBody, nil)
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
HardwareOathTokenAuthenticationMethodDevice hardwareOathTokenAuthenticationMethodDevice = new HardwareOathTokenAuthenticationMethodDevice();
hardwareOathTokenAuthenticationMethodDevice.setDisplayName("Token 1");
hardwareOathTokenAuthenticationMethodDevice.setSerialNumber("TOTP123456");
hardwareOathTokenAuthenticationMethodDevice.setManufacturer("Contoso");
hardwareOathTokenAuthenticationMethodDevice.setModel("Hardware Token 1000");
hardwareOathTokenAuthenticationMethodDevice.setSecretKey("6PJ4UKIW33NNXYZAEHQNFUFTZF7WFTFB");
hardwareOathTokenAuthenticationMethodDevice.setTimeIntervalInSeconds(30);
hardwareOathTokenAuthenticationMethodDevice.setHashFunction(HardwareOathTokenHashFunction.Hmacsha1);
HardwareOathTokenAuthenticationMethodDevice result = graphClient.directory().authenticationMethodDevices().hardwareOathDevices().post(hardwareOathTokenAuthenticationMethodDevice);
const options = {
authProvider,
};
const client = Client.init(options);
const hardwareOathTokenAuthenticationMethodDevice = {
displayName: 'Token 1',
serialNumber: 'TOTP123456',
manufacturer: 'Contoso',
model: 'Hardware Token 1000',
secretKey: '6PJ4UKIW33NNXYZAEHQNFUFTZF7WFTFB',
timeIntervalInSeconds: 30,
hashFunction: 'hmacsha1'
};
await client.api('/directory/authenticationMethodDevices/hardwareOathDevices')
.version('beta')
.post(hardwareOathTokenAuthenticationMethodDevice);
<?php
use Microsoft\Graph\Beta\GraphServiceClient;
use Microsoft\Graph\Beta\Generated\Models\HardwareOathTokenAuthenticationMethodDevice;
use Microsoft\Graph\Beta\Generated\Models\HardwareOathTokenHashFunction;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new HardwareOathTokenAuthenticationMethodDevice();
$requestBody->setDisplayName('Token 1');
$requestBody->setSerialNumber('TOTP123456');
$requestBody->setManufacturer('Contoso');
$requestBody->setModel('Hardware Token 1000');
$requestBody->setSecretKey('6PJ4UKIW33NNXYZAEHQNFUFTZF7WFTFB');
$requestBody->setTimeIntervalInSeconds(30);
$requestBody->setHashFunction(new HardwareOathTokenHashFunction('hmacsha1'));
$result = $graphServiceClient->directory()->authenticationMethodDevices()->hardwareOathDevices()->post($requestBody)->wait();
Import-Module Microsoft.Graph.Beta.Identity.DirectoryManagement
$params = @{
displayName = "Token 1"
serialNumber = "TOTP123456"
manufacturer = "Contoso"
model = "Hardware Token 1000"
secretKey = "6PJ4UKIW33NNXYZAEHQNFUFTZF7WFTFB"
timeIntervalInSeconds = 30
hashFunction = "hmacsha1"
}
New-MgBetaDirectoryAuthenticationMethodDeviceHardwareOathDevice -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.hardware_oath_token_authentication_method_device import HardwareOathTokenAuthenticationMethodDevice
from msgraph_beta.generated.models.hardware_oath_token_hash_function import HardwareOathTokenHashFunction
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
request_body = HardwareOathTokenAuthenticationMethodDevice(
display_name = "Token 1",
serial_number = "TOTP123456",
manufacturer = "Contoso",
model = "Hardware Token 1000",
secret_key = "6PJ4UKIW33NNXYZAEHQNFUFTZF7WFTFB",
time_interval_in_seconds = 30,
hash_function = HardwareOathTokenHashFunction.Hmacsha1,
)
result = await graph_client.directory.authentication_method_devices.hardware_oath_devices.post(request_body)
Antwort
Das folgende Beispiel zeigt die Antwort.
Hinweis: Das hier gezeigte Antwortobjekt kann zur besseren Lesbarkeit gekürzt werden.
HTTP/1.1 201 Created
Content-Type: application/json
{
"@odata.type": "#microsoft.graph.hardwareOathTokenAuthenticationMethodDevice",
"id": "9b037532-f999-1ed9-13fd-849ffb995e11",
"displayName": "Token 1",
"serialNumber": "TOTP123456",
"manufacturer": "Contoso",
"model": "Hardware Token 1000",
"secretKey": null,
"timeIntervalInSeconds": 30,
"status": "available",
"lastUsedDateTime": null,
"assignedTo": null,
"hashFunction": "hmacsha1"
}
Beispiel 2: Erstellen eines Tokens und Zuweisen eines Tokens zu einem Benutzer
Anforderung
Das folgende Beispiel zeigt eine Anfrage.
POST https://graph.microsoft.com/beta/directory/authenticationMethodDevices/hardwareOathDevices
Content-Type: application/json
{
"displayName": "Token 1",
"serialNumber": "TOTP123456",
"manufacturer": "Contoso",
"model": "Hardware Token 1000",
"secretKey": "6PJ4UKIW33NNXYZAEHQNFUFTZF7WFTFB",
"timeIntervalInSeconds": 30,
"hashFunction": "hmacsha1",
"assignTo": {
"id": "0cadbf92-####-####-####-############"
}
}
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Beta.Models;
var requestBody = new HardwareOathTokenAuthenticationMethodDevice
{
DisplayName = "Token 1",
SerialNumber = "TOTP123456",
Manufacturer = "Contoso",
Model = "Hardware Token 1000",
SecretKey = "6PJ4UKIW33NNXYZAEHQNFUFTZF7WFTFB",
TimeIntervalInSeconds = 30,
HashFunction = HardwareOathTokenHashFunction.Hmacsha1,
AssignTo = new User
{
Id = "0cadbf92-####-####-####-############",
},
};
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
var result = await graphClient.Directory.AuthenticationMethodDevices.HardwareOathDevices.PostAsync(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.NewHardwareOathTokenAuthenticationMethodDevice()
displayName := "Token 1"
requestBody.SetDisplayName(&displayName)
serialNumber := "TOTP123456"
requestBody.SetSerialNumber(&serialNumber)
manufacturer := "Contoso"
requestBody.SetManufacturer(&manufacturer)
model := "Hardware Token 1000"
requestBody.SetModel(&model)
secretKey := "6PJ4UKIW33NNXYZAEHQNFUFTZF7WFTFB"
requestBody.SetSecretKey(&secretKey)
timeIntervalInSeconds := int32(30)
requestBody.SetTimeIntervalInSeconds(&timeIntervalInSeconds)
hashFunction := graphmodels.HMACSHA1_HARDWAREOATHTOKENHASHFUNCTION
requestBody.SetHashFunction(&hashFunction)
assignTo := graphmodels.NewUser()
id := "0cadbf92-####-####-####-############"
assignTo.SetId(&id)
requestBody.SetAssignTo(assignTo)
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
hardwareOathDevices, err := graphClient.Directory().AuthenticationMethodDevices().HardwareOathDevices().Post(context.Background(), requestBody, nil)
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
HardwareOathTokenAuthenticationMethodDevice hardwareOathTokenAuthenticationMethodDevice = new HardwareOathTokenAuthenticationMethodDevice();
hardwareOathTokenAuthenticationMethodDevice.setDisplayName("Token 1");
hardwareOathTokenAuthenticationMethodDevice.setSerialNumber("TOTP123456");
hardwareOathTokenAuthenticationMethodDevice.setManufacturer("Contoso");
hardwareOathTokenAuthenticationMethodDevice.setModel("Hardware Token 1000");
hardwareOathTokenAuthenticationMethodDevice.setSecretKey("6PJ4UKIW33NNXYZAEHQNFUFTZF7WFTFB");
hardwareOathTokenAuthenticationMethodDevice.setTimeIntervalInSeconds(30);
hardwareOathTokenAuthenticationMethodDevice.setHashFunction(HardwareOathTokenHashFunction.Hmacsha1);
User assignTo = new User();
assignTo.setId("0cadbf92-####-####-####-############");
hardwareOathTokenAuthenticationMethodDevice.setAssignTo(assignTo);
HardwareOathTokenAuthenticationMethodDevice result = graphClient.directory().authenticationMethodDevices().hardwareOathDevices().post(hardwareOathTokenAuthenticationMethodDevice);
const options = {
authProvider,
};
const client = Client.init(options);
const hardwareOathTokenAuthenticationMethodDevice = {
displayName: 'Token 1',
serialNumber: 'TOTP123456',
manufacturer: 'Contoso',
model: 'Hardware Token 1000',
secretKey: '6PJ4UKIW33NNXYZAEHQNFUFTZF7WFTFB',
timeIntervalInSeconds: 30,
hashFunction: 'hmacsha1',
assignTo: {
id: '0cadbf92-####-####-####-############'
}
};
await client.api('/directory/authenticationMethodDevices/hardwareOathDevices')
.version('beta')
.post(hardwareOathTokenAuthenticationMethodDevice);
<?php
use Microsoft\Graph\Beta\GraphServiceClient;
use Microsoft\Graph\Beta\Generated\Models\HardwareOathTokenAuthenticationMethodDevice;
use Microsoft\Graph\Beta\Generated\Models\HardwareOathTokenHashFunction;
use Microsoft\Graph\Beta\Generated\Models\User;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new HardwareOathTokenAuthenticationMethodDevice();
$requestBody->setDisplayName('Token 1');
$requestBody->setSerialNumber('TOTP123456');
$requestBody->setManufacturer('Contoso');
$requestBody->setModel('Hardware Token 1000');
$requestBody->setSecretKey('6PJ4UKIW33NNXYZAEHQNFUFTZF7WFTFB');
$requestBody->setTimeIntervalInSeconds(30);
$requestBody->setHashFunction(new HardwareOathTokenHashFunction('hmacsha1'));
$assignTo = new User();
$assignTo->setId('0cadbf92-####-####-####-############');
$requestBody->setAssignTo($assignTo);
$result = $graphServiceClient->directory()->authenticationMethodDevices()->hardwareOathDevices()->post($requestBody)->wait();
Import-Module Microsoft.Graph.Beta.Identity.DirectoryManagement
$params = @{
displayName = "Token 1"
serialNumber = "TOTP123456"
manufacturer = "Contoso"
model = "Hardware Token 1000"
secretKey = "6PJ4UKIW33NNXYZAEHQNFUFTZF7WFTFB"
timeIntervalInSeconds = 30
hashFunction = "hmacsha1"
assignTo = @{
id = "0cadbf92-####-####-####-############"
}
}
New-MgBetaDirectoryAuthenticationMethodDeviceHardwareOathDevice -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.hardware_oath_token_authentication_method_device import HardwareOathTokenAuthenticationMethodDevice
from msgraph_beta.generated.models.hardware_oath_token_hash_function import HardwareOathTokenHashFunction
from msgraph_beta.generated.models.user import User
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
request_body = HardwareOathTokenAuthenticationMethodDevice(
display_name = "Token 1",
serial_number = "TOTP123456",
manufacturer = "Contoso",
model = "Hardware Token 1000",
secret_key = "6PJ4UKIW33NNXYZAEHQNFUFTZF7WFTFB",
time_interval_in_seconds = 30,
hash_function = HardwareOathTokenHashFunction.Hmacsha1,
assign_to = User(
id = "0cadbf92-####-####-####-############",
),
)
result = await graph_client.directory.authentication_method_devices.hardware_oath_devices.post(request_body)
Antwort
Das folgende Beispiel zeigt die Antwort.
Hinweis: Das hier gezeigte Antwortobjekt kann zur besseren Lesbarkeit gekürzt werden.
HTTP/1.1 201 Created
Content-Type: application/json
{
"@odata.type": "#microsoft.graph.hardwareOathTokenAuthenticationMethodDevice",
"id": "9b037532-f999-1ed9-13fd-849ffb995e11",
"displayName": "Token 1",
"serialNumber": "TOTP123456",
"manufacturer": "Contoso",
"model": "Hardware Token 1000",
"secretKey": null,
"timeIntervalInSeconds": 30,
"status": "assigned",
"lastUsedDateTime": null,
"assignedTo": null,
"hashFunction": "hmacsha1",
"assignedTo": {
"id": "0cadbf92-####-####-####-############",
"displayName": "Amy Masters"
}
}