FaceSessionClient.CreateLivenessSession 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
CreateLivenessSession(CreateLivenessSessionContent, CancellationToken) |
Create a new detect liveness session. |
CreateLivenessSession(RequestContent, RequestContext) |
[Protocol Method] Create a new detect liveness session.
|
CreateLivenessSession(CreateLivenessSessionContent, CancellationToken)
- Source:
- FaceSessionClient.cs
Create a new detect liveness session.
public virtual Azure.Response<Azure.AI.Vision.Face.CreateLivenessSessionResult> CreateLivenessSession (Azure.AI.Vision.Face.CreateLivenessSessionContent createLivenessSessionContent, System.Threading.CancellationToken cancellationToken = default);
abstract member CreateLivenessSession : Azure.AI.Vision.Face.CreateLivenessSessionContent * System.Threading.CancellationToken -> Azure.Response<Azure.AI.Vision.Face.CreateLivenessSessionResult>
override this.CreateLivenessSession : Azure.AI.Vision.Face.CreateLivenessSessionContent * System.Threading.CancellationToken -> Azure.Response<Azure.AI.Vision.Face.CreateLivenessSessionResult>
Public Overridable Function CreateLivenessSession (createLivenessSessionContent As CreateLivenessSessionContent, Optional cancellationToken As CancellationToken = Nothing) As 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 CreateLivenessSession.
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 = client.CreateLivenessSession(createLivenessSessionContent);
This sample shows how to call CreateLivenessSession 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 = client.CreateLivenessSession(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
CreateLivenessSession(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 CreateLivenessSession(CreateLivenessSessionContent, CancellationToken) convenience overload with strongly typed models first.
public virtual Azure.Response CreateLivenessSession (Azure.Core.RequestContent content, Azure.RequestContext context = default);
abstract member CreateLivenessSession : Azure.Core.RequestContent * Azure.RequestContext -> Azure.Response
override this.CreateLivenessSession : Azure.Core.RequestContent * Azure.RequestContext -> Azure.Response
Public Overridable Function CreateLivenessSession (content As RequestContent, Optional context As RequestContext = Nothing) As 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 CreateLivenessSession 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 = client.CreateLivenessSession(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 CreateLivenessSession 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 = client.CreateLivenessSession(content);
JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement;
Console.WriteLine(result.GetProperty("sessionId").ToString());
Console.WriteLine(result.GetProperty("authToken").ToString());
Applies to
Azure SDK for .NET