Skip to content

Commit 61b1b0d

Browse files
author
Jinyu Li
committed
add sample code
1 parent efbe1af commit 61b1b0d

File tree

1 file changed

+90
-1
lines changed

1 file changed

+90
-1
lines changed

articles/ai-services/computer-vision/concept-face-liveness-quick-link.md

Lines changed: 90 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,96 @@ You can utilize the liveness quick link website liveness.face.azure.com to turn
3232
:::image type="content" source="media/liveness/liveness-quick-link-diagram.png" alt-text="A diagram illustrates liveness quick link work flow":::
3333

3434
1. Start a session server side. Your backend asks Face API for a new liveness session and receives a short lived authorization token that represents that session.
35-
2. Swap the token for a link. Your backend sends the token to the Quick Link service, which creates a one time URL tied to the session.
35+
2. Swap the token for a link. Your backend sends the token to the Quick Link service, which creates a one time URL tied to the session. here are examples to post request:
36+
37+
#### [C#](#tab/csharp)
38+
```csharp
39+
var client = new HttpClient();
40+
var request = new HttpRequestMessage
41+
{
42+
Method = HttpMethod.Post,
43+
RequestUri = new Uri("https://liveness.face.azure.com/api/s"),
44+
Headers =
45+
{
46+
{ "authorization", "Bearer <session-authorization-token>" },
47+
},
48+
};
49+
using (var response = await client.SendAsync(request))
50+
{
51+
response.EnsureSuccessStatusCode();
52+
var body = await response.Content.ReadAsStringAsync();
53+
Console.WriteLine(body);
54+
}
55+
```
56+
57+
#### [Java](#tab/java)
58+
```java
59+
HttpRequest request = HttpRequest.newBuilder()
60+
.uri(URI.create("https://liveness.face.azure.com/api/s"))
61+
.header("authorization", "Bearer <session-authorization-token>")
62+
.method("POST", HttpRequest.BodyPublishers.noBody())
63+
.build();
64+
HttpResponse<String> response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());
65+
System.out.println(response.body());
66+
```
67+
68+
#### [Python](#tab/python)
69+
```python
70+
import http.client
71+
72+
conn = http.client.HTTPSConnection("liveness.face.azure.com")
73+
74+
headers = {
75+
'authorization': "Bearer <session-authorization-token>"
76+
}
77+
78+
conn.request("POST", "/api/s", headers=headers)
79+
80+
res = conn.getresponse()
81+
data = res.read()
82+
83+
print(data.decode("utf-8"))
84+
85+
```
86+
87+
#### [JavaScript](#tab/javascript)
88+
```javascript
89+
fetch("https://liveness.face.azure.com/api/s", {
90+
"method": "POST",
91+
"headers": {
92+
"authorization": "Bearer <session-authorization-token>"
93+
}
94+
})
95+
.then(response => {
96+
console.log(response);
97+
})
98+
.catch(err => {
99+
console.error(err);
100+
});
101+
```
102+
103+
#### [REST(Windows)](#tab/cmd)
104+
```console
105+
curl --request POST ^
106+
--url https://liveness.face.azure.com/api/s ^
107+
--header 'authorization: Bearer <session-authorization-token>'
108+
```
109+
110+
#### [REST(Linux)](#tab/bash)
111+
```bash
112+
curl --request POST \
113+
--url https://liveness.face.azure.com/api/s \
114+
--header 'authorization: Bearer <session-authorization-token>'
115+
```
116+
117+
An example response:
118+
```json
119+
{
120+
"url": "/?s=60c3980c-d9f6-4b16-a7f5-f1f4ad2b506f"
121+
}
122+
```
123+
Simply compose the returned url after liveness quick link web site https:////liveness.face.azure.com/?s=60c3980c-d9f6-4b16-a7f5-f1f4ad2b506f
124+
36125
3. Send the link to the user. You can redirect the browser, show a button, or display a QR code—anything that gets the user to open the link on a camera enabled device.
37126
4. Azure hosts the capture. When the link opens, the Azure operated page guides the user through the liveness check sequence using the latest Liveness Web Client.
38127
5. Get the outcome callback. As soon as the check finishes—or if the user abandons or times out—Quick Link notify to your callback endpoint so your application can decide what happens next.

0 commit comments

Comments
 (0)