Skip to main content

Arvasit Authentication SDK for Python - Complete authentication solution with 2FA, password management, and user management

Project description

Arvasit Auth SDK - Python

PyPI version Python 3.8+ License: MIT

The official Arvasit Authentication SDK for Python provides a comprehensive authentication solution with user management, two-factor authentication, password management, and login activity monitoring.

🚀 Features

  • Complete Authentication System - Signup, login, logout with multiple methods
  • Two-Factor Authentication (2FA) - QR code generation, TOTP verification, device management
  • Password Management - Forgot password, reset, update with security
  • User Management - Profile management, username suggestions, credential validation
  • Recovery Codes - Generate and manage backup recovery codes
  • Login Activity - Track and monitor user login activities
  • Type Safety - Full Pydantic model validation
  • Magic Link Authentication - Passwordless login via email links

📦 Installation

pip install arvasit-auth-sdk

🔧 Quick Start

from auth_sdk import AuthService, AuthServiceConfig, SignupRequest, LoginRequest

# Configure the SDK
config = AuthServiceConfig(
    url="https://your-auth-service.com",
    public_key="your_public_key",
    secret_key="your_secret_key"
)

# Initialize the service
auth_service = AuthService(config)

# Sign up a new user
signup_data = SignupRequest(
    firstName="John",
    lastName="Doe",
    email="john.doe@example.com",
    username="johndoe",
    password="SecurePassword123!",
    phoneNumber="+1234567890"
)

user = auth_service.signup(signup_data)
print(f"User created with ID: {user.authId}")

# Login with password
login_data = LoginRequest(
    credential="john.doe@example.com",
    password="SecurePassword123!"
)

login_result = auth_service.login_with_password(login_data)
print(f"Access token: {login_result.accessToken}")

📚 API Reference

Authentication Methods

Password Login

from auth_sdk import LoginRequest

login_data = LoginRequest(
    credential="user@example.com",  # Email, phone, or username
    password="user_password"
)

result = auth_service.login_with_password(login_data)

OTP Login

from auth_sdk import OtpLoginRequest

otp_data = OtpLoginRequest(
    credential="user@example.com",
    otp="123456"
)

result = auth_service.login_with_otp(otp_data)

Two-Factor Authentication Login

from auth_sdk import TwoFALoginRequest

twofa_data = TwoFALoginRequest(
    credential="user@example.com",
    totp="123456"  # TOTP code from authenticator app
)

result = auth_service.verify_two_factor_authentication(twofa_data)

Recovery Code Login

from auth_sdk import RecoveryCodeLoginRequest

recovery_data = RecoveryCodeLoginRequest(
    credential="user@example.com",
    recoveryCode="RECOVERY123"
)

result = auth_service.login_with_recovery_code(recovery_data)

Two-Factor Authentication

Generate 2FA Setup

# Generate QR code and secret for 2FA setup
twofa_data = auth_service.generate_qr_code_and_secret_for_2fa(access_token)
print(f"Secret: {twofa_data.secret}")
print(f"QR Code: {twofa_data.qrCode}")

Verify 2FA Setup

from auth_sdk import VerifyQRCodeAndSecretFor2FARequest

verify_data = VerifyQRCodeAndSecretFor2FARequest(
    accessToken=access_token,
    totp="123456",
    secretKey="JBSWY3DPEHPK3PXP"
)

result = auth_service.verify_qr_code_and_secret_for_2fa(verify_data)

Manage 2FA Devices

# List 2FA devices
devices = auth_service.list_of_two_fa_secrets(access_token)

# Remove a 2FA device
auth_service.remove_two_fa_device(access_token, "device_key")

# Disable 2FA
auth_service.disable_two_fa(access_token)

Password Management

Forgot Password Flow

# Step 1: Enter credential to get contact info
contact_info = auth_service.enter_credential_for_forgot_password("user@example.com")

# Step 2: Send OTP
auth_service.forgot_password_send_otp("user@example.com", "email")

# Step 3: Verify OTP
reset_token = auth_service.verify_forgot_password_otp("user@example.com", "123456")

# Step 4: Reset password
auth_service.verify_token_setup_password(reset_token, "new_password")

Update Password

auth_service.update_password(
    credential="user@example.com",
    old_password="old_password",
    new_password="new_password"
)

User Management

Username Management

# Suggest usernames
suggestions = auth_service.suggest_username("John", "Doe")

# Check username availability
is_available = auth_service.check_available_username("johndoe")

Credential Validation

credential_info = auth_service.check_credential("user@example.com")
print(f"Type: {credential_info.type}")
print(f"Valid: {credential_info.isValid}")

Token Management

Refresh Access Token

from auth_sdk import RefreshAccessTokenRequest

refresh_data = RefreshAccessTokenRequest(token=refresh_token)
new_tokens = auth_service.refresh_access_token(refresh_data)

Logout

from auth_sdk import LogoutRequest

logout_data = LogoutRequest(token=access_token)
auth_service.logout(logout_data)

Login Activity Monitoring

Get Activity Counts

activity_counts = auth_service.login_activity_counts(
    access_token=access_token,
    start_date="2024-01-01",
    end_date="2024-01-31",
    page=1,
    limit=10
)

Get Activity Details

activity_details = auth_service.login_activity_details(
    access_token=access_token,
    start_date="2024-01-01",
    end_date="2024-01-31",
    page=1,
    limit=10
)

🔒 Security Features

  • HMAC Authentication - Secure API communication with timestamp-based signatures
  • Type Validation - Pydantic models ensure data integrity
  • Error Handling - Comprehensive error handling with detailed messages
  • Token Management - Secure access and refresh token handling

🧪 Testing

# Test imports
from auth_sdk import AuthService, AuthServiceConfig, LoginRequest

# Test service creation
config = AuthServiceConfig(
    url="https://test.com",
    public_key="test_key",
    secret_key="test_secret"
)
service = AuthService(config)
print("✅ SDK initialized successfully")

📋 Requirements

  • Python 3.8+
  • requests>=2.31.0
  • pydantic>=2.0.0
  • python-dateutil>=2.8.2

🔗 Related Projects

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🆘 Support

🤝 Contributing

Contributions are welcome! Please read our Contributing Guide for details.


Made with ❤️ by the Arvasit Team

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

arvasit_auth_sdk-0.1.8.tar.gz (8.9 kB view details)

Uploaded Source

Built Distribution

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

arvasit_auth_sdk-0.1.8-py3-none-any.whl (9.1 kB view details)

Uploaded Python 3

File details

Details for the file arvasit_auth_sdk-0.1.8.tar.gz.

File metadata

  • Download URL: arvasit_auth_sdk-0.1.8.tar.gz
  • Upload date:
  • Size: 8.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for arvasit_auth_sdk-0.1.8.tar.gz
Algorithm Hash digest
SHA256 4037b4ff27e7205219e91ce7c242e0bf60c9e44e49dc8b5b09b682da4d0dac28
MD5 e688dc83b723e4bfdd74ef7c3e30f6b3
BLAKE2b-256 de609093d7e3dcc27af29d8715464d42c8b81bc5a2a705d5b9d6ce5b97d4aa05

See more details on using hashes here.

File details

Details for the file arvasit_auth_sdk-0.1.8-py3-none-any.whl.

File metadata

File hashes

Hashes for arvasit_auth_sdk-0.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 13b7372dde7ea5c6e04dad1054fed125eb91af5d14b847b81ef2b3faa87f84c9
MD5 57898af2880aff817ff2d07065c8f21c
BLAKE2b-256 6eae7ffec9ea55539de0f36936eff3a0906953a10e9ba2a1aa9bb0bd024b564c

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