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.3.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.3-py3-none-any.whl (11.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: rulog-1.0.3.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.3.tar.gz
Algorithm Hash digest
SHA256 bb5befd394a3573c069f83c674c4b302ad012e81759b043c8857c80254710f42
MD5 a8ac9253117a3bda22769a9fc441336f
BLAKE2b-256 dcfb0ff4c724aafeb51464cea7d71d933a9f5341232433ae3a1adc7bacc5beb7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: rulog-1.0.3-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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 d078512ea4ca33c173c925803dfebae453f7418023427848c5253a206220c07c
MD5 afc5340b74e5ff4fc7ac83b187856553
BLAKE2b-256 958eb3559862d6e40e3dbdc754114b90b81061377d1a18593f29f9a852a6ba32

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