using 2fa with api

This commit is contained in:
Maxim Devaev 2023-01-23 17:28:21 +02:00
parent 59c5aa6a58
commit 361c5a3dd8
1 changed files with 22 additions and 2 deletions

View File

@ -9,8 +9,28 @@ This document describes the PiKVM API. Since the system consists of microservice
All APIs are restricted to authentication. To make requests, you either need to auth each request individually, All APIs are restricted to authentication. To make requests, you either need to auth each request individually,
or get a token and pass it as a cookie with each request. or get a token and pass it as a cookie with each request.
!!! note With enabled [2FA](auth.md#two-factor-authentication), you will need to add the one-time code to the password without spaces.
With enabled [2FA](auth.md#two-factor-authentication), you will need to add the one-time code to the password without spaces. That is, if the password is `foobar` and the code is `123456`, then you need to use `foobar123456` as the password. That is, if the password is `foobar` and the code is `123456`, then you need to use `foobar123456` as the password.
The code can be generated using any TOTP library, for example in Python:
```python
import requests
import pyotp
user = "admin"
passwd = "admin"
secret = "3OBBOGSJRYRBZH35PGXURM4CMWTH3WSU" # Can be found in /etc/kvmd/totp.secret
print(requests.get(
url="https://pikvm/api/info",
verify=False, # For self-signed SSL certificate
headers={
"X-KVMD-User": user,
"X-KVMD-Passwd": passwd + pyotp.TOTP(secret).now(),
},
).text)
```
### Single request auth ### Single request auth