Skip to main content

Rubika: A Python library for interacting with the Rubika Login APi.

Project description

Rubika Login Example

This is a simple example showing how to use the rulog Python library to:

  1. Send a verification code to a phone number.
  2. Login to Rubika using the received code.
  3. Register the device.

Installation

Make sure you have installed the rulog library:

pip install rulog

Example Code

from rulog import Client

# Create a Client instance
Client = Client()

# ===== Send code =====
def send_code(phone):
    try:
        # Try sending via Android platform with send_type=True
        response = Client.sendCode("android", phone, send_type=True)
        return response['data']['phone_code_hash']
    except Exception as e:
        print("❌ Android send failed. Trying Web...")
        try:
            response = Client.sendCode("web", phone)
            return response['data']['phone_code_hash']
        except Exception as e:
            print("❌ Sending code failed:", e)
            return None

# ===== Login =====
def login(phone, hash_code, code):
    try:
        response = Client.signIn("android", phone, hash_code, code)
        print("✅ Login successful.")
        return response
    except Exception as e:
        print("❌ Login failed:", e)
        return None

# ===== Register device =====
def register(auth, key):
    try:
        result = Client.register(platform="android", auths=auth, keys=key)
        if result:
            print("✅ Registration successful.")
            return True
        else:
            print("❌ Registration failed.")
            return False
    except Exception as e:
        print("❌ Registration error:", e)
        return False

# ===== Main execution =====
if __name__ == "__main__":
    phone = input("📱 Enter your phone number (e.g., 9891...): ").strip()

    hash_code = send_code(phone)
    if not hash_code:
        print("🚫 Code sending failed. Exiting.")
        exit()

    code = input("🔢 Enter the received code: ").strip()
    login_response = login(phone, hash_code, code)

    if login_response:
        register(login_response['Auth'], login_response['Key'])

How it works

  1. Send code: Sends a verification code to the phone using Android first, then Web if failed.
  2. Login: Signs in using the phone number, hash code, and received code.
  3. Register: Registers the device using the authentication keys received after login.

Notes

  • Ensure your phone number format is correct.
  • The script handles simple retries for sending codes.
  • The library rulog must be installed.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rulog-1.0.2.tar.gz (11.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rulog-1.0.2-py3-none-any.whl (11.5 kB view details)

Uploaded Python 3

File details

Details for the file rulog-1.0.2.tar.gz.

File metadata

  • Download URL: rulog-1.0.2.tar.gz
  • Upload date:
  • Size: 11.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.4

File hashes

Hashes for rulog-1.0.2.tar.gz
Algorithm Hash digest
SHA256 6fd9ca5364db8d084285fcff36b51562d1adf03c6e795cf24616cec8194ff820
MD5 da595f55350cfc941e825624ebb29db9
BLAKE2b-256 71f89e0a7f382e2c05f343b05ade067dd7ed2e588b4fa87d74c8f2824e2a6adf

See more details on using hashes here.

File details

Details for the file rulog-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: rulog-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 11.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.4

File hashes

Hashes for rulog-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 fd924baff8724ad8ec8c1ff91ccae65dfad20a93dca65c2631dbe59e35e4cb53
MD5 e0fa4db3c425fb036c5a95b6da0b29d8
BLAKE2b-256 4e45595508144ed7b57dfcd77408612682892cff5eca20befc8336a22ee0874e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page