Skip to content

Instantly share code, notes, and snippets.

@tcpj
Last active July 19, 2021 13:35
Show Gist options
  • Save tcpj/c5ecf89493f2543935feb9231bdd63cf to your computer and use it in GitHub Desktop.
Save tcpj/c5ecf89493f2543935feb9231bdd63cf to your computer and use it in GitHub Desktop.
TTYcka
import qrcode
import requests
import sys
import uuid
DEVICE_NAME = "TTYcka"
BASE_UZIS_URL="https://ocko.uzis.cz/api/v2/"
BASE_NIA_URL="https://ocko.uzis.cz/Account/Prihlaseni"
AUTH_ENDPOINT="auth/login"
PERSON_ENDPOINT="person"
def get_jwt(device_name, installation_id):
url = requests.post(
f"{BASE_UZIS_URL}{AUTH_ENDPOINT}",
json={
"deviceName": device_name,
"installationId": installation_id,
},
)
return url.json()["accessToken"]
def get_login_url(access_token):
return f"{BASE_NIA_URL}?AccessToken={access_token}&Type=AlternativeOnly&ReturnUrl=Home"
def get_persons(access_token):
return requests.get(
f"{BASE_UZIS_URL}{PERSON_ENDPOINT}",
headers={"Authorization": f"Bearer {access_token}"}
).json()
def get_certificates(access_token, person_id):
return requests.get(
f"{BASE_UZIS_URL}{PERSON_ENDPOINT}/{person_id}/dgc",
headers={"Authorization": f"Bearer {access_token}"}
).json()
def new_device():
device_id = str(uuid.uuid4()).upper()
access_token = get_jwt(DEVICE_NAME, device_id)
print(get_login_url(access_token))
print(f"Your installation ID is: {device_id}. Store it somewhere.")
input("Press enter after login.")
return device_id
if __name__ == "__main__":
if len(sys.argv) < 2:
device_id = new_device()
elif len(sys.argv) > 2:
print("Only one argument is allowed. Enter valid device ID.")
else:
uuid_input = sys.argv[1]
device_id = str(uuid.UUID(uuid_input)).upper()
access_token = get_jwt(DEVICE_NAME, device_id)
for person in get_persons(access_token):
person_id = person["id"]
for cert in get_certificates(access_token, person_id):
qr = qrcode.QRCode()
qr.add_data(cert["qrData"])
qr.print_ascii()
@tcpj
Copy link
Author

tcpj commented Jul 6, 2021

Usage:

  • with no arguments a new device ID will be generated and a registration is needed. Follow the link. Your device called "TTYcka" will appear on ocko.uzis.cz
  • first argument is your device ID generated before. It will not create another device in ocko.uzis.cz.
  • the app will list all QR codes for all persons attached to this device ID.

Requirements:

  • requests
  • qrcode

Fucking enjoy

@zajdee
Copy link

zajdee commented Jul 7, 2021

If you wish to use Narodni identita (NIA) instead of birth number/ID card number/SMS, replace AlternativeOnly with NiaOnly.

@borisgrigorov
Copy link

That's really cool! 🚀 🔥

@gjask
Copy link

gjask commented Jul 19, 2021

Nice!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment