你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn。
FaceSessionClient.CreateLivenessSessionAsync Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Overloads
CreateLivenessSessionAsync(CreateLivenessSessionContent, CancellationToken) |
Create a new detect liveness session. |
CreateLivenessSessionAsync(RequestContent, RequestContext) |
[Protocol Method] Create a new detect liveness session.
|
CreateLivenessSessionAsync(CreateLivenessSessionContent, CancellationToken)
- Source:
- FaceSessionClient.cs
Create a new detect liveness session.
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.AI.Vision.Face.CreateLivenessSessionResult>> CreateLivenessSessionAsync (Azure.AI.Vision.Face.CreateLivenessSessionContent createLivenessSessionContent, System.Threading.CancellationToken cancellationToken = default);
abstract member CreateLivenessSessionAsync : Azure.AI.Vision.Face.CreateLivenessSessionContent * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Azure.Response<Azure.AI.Vision.Face.CreateLivenessSessionResult>>
override this.CreateLivenessSessionAsync : Azure.AI.Vision.Face.CreateLivenessSessionContent * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Azure.Response<Azure.AI.Vision.Face.CreateLivenessSessionResult>>
Public Overridable Function CreateLivenessSessionAsync (createLivenessSessionContent As CreateLivenessSessionContent, Optional cancellationToken As CancellationToken = Nothing) As Task(Of Response(Of CreateLivenessSessionResult))
Parameters
- createLivenessSessionContent
- CreateLivenessSessionContent
Request for creating liveness session.
- cancellationToken
- CancellationToken
The cancellation token to use.
Returns
Exceptions
createLivenessSessionContent
is null.
Examples
This sample shows how to call CreateLivenessSessionAsync.
Uri endpoint = new Uri("<https://my-service.azure.com>");
AzureKeyCredential credential = new AzureKeyCredential("<key>");
FaceSessionClient client = new FaceSessionClient(endpoint, credential);
CreateLivenessSessionContent createLivenessSessionContent = new CreateLivenessSessionContent(LivenessOperationMode.Passive);
Response<CreateLivenessSessionResult> response = await client.CreateLivenessSessionAsync(createLivenessSessionContent);
This sample shows how to call CreateLivenessSessionAsync with all parameters.
Uri endpoint = new Uri("<https://my-service.azure.com>");
AzureKeyCredential credential = new AzureKeyCredential("<key>");
FaceSessionClient client = new FaceSessionClient(endpoint, credential);
CreateLivenessSessionContent createLivenessSessionContent = new CreateLivenessSessionContent(LivenessOperationMode.Passive)
{
SendResultsToClient = true,
DeviceCorrelationIdSetInClient = true,
DeviceCorrelationId = "<deviceCorrelationId>",
AuthTokenTimeToLiveInSeconds = 1234,
};
Response<CreateLivenessSessionResult> response = await client.CreateLivenessSessionAsync(createLivenessSessionContent);
Remarks
A session is best for client device scenarios where developers want to authorize a client device to perform only a liveness detection without granting full access to their resource. Created sessions have a limited life span and only authorize clients to perform the desired action before access is expired.
Permissions includes... > * * Ability to call /detectLiveness/singleModal for up to 3 retries. * A token lifetime of 10 minutes.
> [!NOTE] > Client access can be revoked by deleting the session using the Delete Liveness Session operation. To retrieve a result, use the Get Liveness Session. To audit the individual requests that a client has made to your resource, use the List Liveness Session Audit Entries.
Applies to
CreateLivenessSessionAsync(RequestContent, RequestContext)
- Source:
- FaceSessionClient.cs
[Protocol Method] Create a new detect liveness session.
- This protocol method allows explicit creation of the request and processing of the response for advanced scenarios.
- Please try the simpler CreateLivenessSessionAsync(CreateLivenessSessionContent, CancellationToken) convenience overload with strongly typed models first.
public virtual System.Threading.Tasks.Task<Azure.Response> CreateLivenessSessionAsync (Azure.Core.RequestContent content, Azure.RequestContext context = default);
abstract member CreateLivenessSessionAsync : Azure.Core.RequestContent * Azure.RequestContext -> System.Threading.Tasks.Task<Azure.Response>
override this.CreateLivenessSessionAsync : Azure.Core.RequestContent * Azure.RequestContext -> System.Threading.Tasks.Task<Azure.Response>
Public Overridable Function CreateLivenessSessionAsync (content As RequestContent, Optional context As RequestContext = Nothing) As Task(Of Response)
Parameters
- content
- RequestContent
The content to send as the body of the request.
- context
- RequestContext
The request context, which can override default behaviors of the client pipeline on a per-call basis.
Returns
The response returned from the service.
Exceptions
content
is null.
Service returned a non-success status code.
Examples
This sample shows how to call CreateLivenessSessionAsync and parse the result.
Uri endpoint = new Uri("<https://my-service.azure.com>");
AzureKeyCredential credential = new AzureKeyCredential("<key>");
FaceSessionClient client = new FaceSessionClient(endpoint, credential);
using RequestContent content = RequestContent.Create(new
{
livenessOperationMode = "Passive",
});
Response response = await client.CreateLivenessSessionAsync(content);
JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement;
Console.WriteLine(result.GetProperty("sessionId").ToString());
Console.WriteLine(result.GetProperty("authToken").ToString());
This sample shows how to call CreateLivenessSessionAsync with all request content and parse the result.
Uri endpoint = new Uri("<https://my-service.azure.com>");
AzureKeyCredential credential = new AzureKeyCredential("<key>");
FaceSessionClient client = new FaceSessionClient(endpoint, credential);
using RequestContent content = RequestContent.Create(new
{
livenessOperationMode = "Passive",
sendResultsToClient = true,
deviceCorrelationIdSetInClient = true,
deviceCorrelationId = "<deviceCorrelationId>",
authTokenTimeToLiveInSeconds = 1234,
});
Response response = await client.CreateLivenessSessionAsync(content);
JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement;
Console.WriteLine(result.GetProperty("sessionId").ToString());
Console.WriteLine(result.GetProperty("authToken").ToString());