A comprehensive authentication SDK for Python with Pydantic support. Features include user registration, login, 2FA, password management, and secure token handling.
Project description
Arvasit Auth SDK
Authentication SDK for Node.js and Python with comprehensive auth features.
๐ Quick Setup
Node.js
npm install @pratik_25/auth-sdk
import { AuthService, AuthServiceConfig } from '@pratik_25/auth-sdk';
const config: AuthServiceConfig = {
url: 'https://your-auth-service.com',
publicKey: 'your_public_key',
secretKey: 'your_secret_key'
};
const authService = new AuthService(config);
Python
pip install arvasit-auth-sdk
from auth_sdk import AuthService, AuthServiceConfig
config = AuthServiceConfig(
url="https://your-auth-service.com",
public_key="your_public_key",
secret_key="your_secret_key"
)
auth_service = AuthService(config)
โจ Features
- User Authentication: Signup, login, logout
- Two-Factor Authentication: Complete 2FA setup and management
- Password Management: Reset, change, forgot password
- Email & Phone Verification: Account verification
- Session Management: Token management and refresh
- Login Activity: Track and monitor user activities
- Type Safety: Full TypeScript and Python type definitions
- Schema-Driven: Single JSON schema generates both SDKs
๐ Available Methods
Authentication
signup()- Register new userloginWithPassword()/login_with_password()- User loginlogout()- User logoutrefreshAccessToken()/refresh_access_token()- Refresh token
Password Management
forgotPasswordSendOTP()/forgot_password_send_otp()- Send reset OTPupdatePassword()/update_password()- Change passwordenterCredentialForForgotPassword()/enter_credential_for_forgot_password()- Start reset flow
Two-Factor Authentication
generateQRCodeAndSecretFor2FA()/generate_qr_code_and_secret_for_2fa()- Enable 2FAverifyQRCodeAndSecretFor2FA()/verify_qr_code_and_secret_for_2fa()- Verify 2FAgenerateRecoveryCodes()/generate_recovery_codes()- Generate backup codes
User Management
checkCredential()/check_credential()- Check user existssuggestUsername()/suggest_username()- Suggest usernamescheckAvailableUserName()/check_available_username()- Check username availability
Login Activity
loginActivityCounts()/login_activity_counts()- Get activity countsloginActivityDetails()/login_activity_details()- Get activity details
๐ง Configuration
Both SDKs use the same configuration:
// Node.js
const config: AuthServiceConfig = {
url: 'https://your-auth-service.com', // Your auth service URL
publicKey: 'your_public_key', // Public API key
secretKey: 'your_secret_key' // Secret API key
};
# Python
config = AuthServiceConfig(
url="https://your-auth-service.com", # Your auth service URL
public_key="your_public_key", # Public API key
secret_key="your_secret_key" # Secret API key
)
๐ Examples
Complete User Registration Flow
// Node.js
const user = await authService.signup({
firstName: 'John',
lastName: 'Doe',
email: 'john@example.com',
password: 'secure_password123'
});
const loginResult = await authService.loginWithPassword({
credential: 'john@example.com',
password: 'secure_password123'
});
const twofaData = await authService.generateQRCodeAndSecretFor2FA(loginResult.accessToken);
# Python
user = auth_service.signup(SignupRequest(
firstName="John",
lastName="Doe",
email="john@example.com",
password="secure_password123"
))
login_result = auth_service.login_with_password(LoginRequest(
credential="john@example.com",
password="secure_password123"
))
twofa_data = auth_service.generate_qr_code_and_secret_for_2fa(login_result.accessToken)
Forgot Password Flow
// Node.js
await authService.enterCredentialForForgotPassword('john@example.com');
const resetToken = await authService.verifyForgotPasswordOtp({
credential: 'john@example.com',
otp: '123456'
});
# Python
auth_service.enter_credential_for_forgot_password('john@example.com')
reset_token = auth_service.verify_forgot_password_otp('john@example.com', '123456')
๐ ๏ธ Development & SDK Generation
This project uses a schema-driven approach where both SDKs are generated from a single JSON schema.
Prerequisites
- Python 3.8+ (for generation script)
- Node.js 18+ (for TypeScript compilation)
- npm (for package management)
Generate SDKs from Schema
- Update Schema: Edit
schemas/auth-types.json - Generate Types: Run
python3 scripts/generate-types.py - Build TypeScript: Run
cd node && npm run build(optional) - Test Changes: Verify both SDKs work
Adding New API Types
- Add to Schema:
"YourNewRequest": {
"type": "object",
"properties": {
"param1": {"type": "string"},
"param2": {"type": "integer"}
},
"required": ["param1"]
}
-
Regenerate:
python3 scripts/generate-types.py -
Use in Code:
// TypeScript
import { YourNewRequest } from '@pratik_25/auth-sdk';
# Python
from auth_sdk import YourNewRequest
๐ฆ Package Details
Node.js SDK
- Package:
@pratik_25/auth-sdk - Registry: npmjs.org
- Dependencies: axios, luxon
- TypeScript: Full type definitions
Python SDK
- Package:
arvasit-auth-sdk - Registry: PyPI
- Dependencies: requests, pydantic, python-dateutil
- Type Safety: Pydantic models
๐ Schema-Driven Benefits
- โ Single Source of Truth: One JSON schema drives both SDKs
- โ Zero Duplication: No maintaining types in two places
- โ Automatic Consistency: Types always synchronized
- โ Easy Maintenance: Update schema โ Both SDKs updated
- โ Type Safety: Full TypeScript and Python definitions
๐ License
MIT License - see LICENSE file for details.
๐ Support
- Documentation: This README and examples
- Issues: GitHub Issues
- Discussions: GitHub Discussions
Made with โค๏ธ by the Arvasit team
๐ Project Structure
arva-auth-sdk/
โโโ schemas/ # Single source of truth
โ โโโ auth-types.json # JSON schema definitions
โ โโโ README.md # Schema documentation
โโโ scripts/ # Generation scripts
โ โโโ generate-types.py # Auto-generates both SDKs
โโโ node/ # Node.js SDK
โ โโโ src/ # Source code
โ โ โโโ auth-service.ts # Main service class
โ โ โโโ auth-types.ts # Generated TypeScript interfaces
โ โ โโโ index.ts # Generated exports
โ โโโ dist/ # Compiled JavaScript (generated)
โ โโโ package.json # Node.js package configuration
โ โโโ tsconfig.json # TypeScript configuration
โโโ python/ # Python SDK
โ โโโ src/auth_sdk/ # Python package
โ โ โโโ __init__.py # Generated imports
โ โ โโโ auth_service.py # Main service class
โ โ โโโ auth_types.py # Generated Pydantic models
โ โโโ examples/ # Usage examples
โ โ โโโ basic_usage.py # Comprehensive examples
โ โโโ pyproject.toml # Python package configuration
โโโ README.md
โโโ LICENSE
๐ ๏ธ Development & SDK Generation
Prerequisites
Before generating the SDK, ensure you have:
- Python 3.8+ (for the generation script)
- Node.js 18+ (for TypeScript compilation)
- npm (for package management)
Generating the SDK from Schema
This project uses a schema-driven approach where both Node.js and Python SDKs are generated from a single JSON schema file.
Step 1: Update the Schema
Edit the schema file to define your API types:
# Edit the schema file
vim schemas/auth-types.json
The schema follows JSON Schema Draft 7 format:
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Arvasit Authentication Types",
"definitions": {
"YourNewType": {
"type": "object",
"properties": {
"field1": {
"type": "string",
"description": "Description of field1"
},
"field2": {
"type": "integer",
"description": "Description of field2"
}
},
"required": ["field1"]
}
}
}
Step 2: Generate Both SDKs
Run the generation script to create both TypeScript and Python types:
# Generate types for both SDKs
python3 scripts/generate-types.py
This script will:
- โ Validate the JSON schema
- โ
Generate TypeScript interfaces (
node/src/auth-types.ts) - โ
Update TypeScript exports (
node/src/index.ts) - โ
Generate Python Pydantic models (
python/src/auth_sdk/auth_types.py) - โ
Update Python imports (
python/src/auth_sdk/__init__.py) - โ Test Python imports to ensure everything works
Step 3: Build TypeScript SDK (Optional)
If you need the compiled JavaScript:
# Build TypeScript to JavaScript
cd node
npm run build
This creates the dist/ folder with compiled JavaScript and TypeScript declarations.
Step 4: Test Your Changes
Verify everything works:
# Test Python SDK
cd python
python3 -c "from src.auth_sdk import AuthService, YourNewType; print('โ
Python imports work')"
# Test TypeScript compilation
cd node
npm run build
Schema Features Supported
The generation script supports:
- โ
Basic Types:
string,integer,boolean,array,object - โ
Optional Properties: Properties not in
requiredarray - โ Enums: String enums with specific values
- โ Arrays: Arrays with typed items
- โ
References:
$refto other definitions - โ Nested Objects: Complex object structures
- โ
Additional Properties:
additionalProperties: true
Adding New API Types
To add a new API type:
-
Add to Schema:
"YourNewRequest": { "type": "object", "properties": { "param1": {"type": "string"}, "param2": {"type": "integer"} }, "required": ["param1"] }
-
Regenerate SDKs:
python3 scripts/generate-types.py -
Use in Code:
// TypeScript import { YourNewRequest } from '@arvasit/auth-sdk'; const request: YourNewRequest = { param1: "value", param2: 123 };
# Python from auth_sdk import YourNewRequest request = YourNewRequest(param1="value", param2=123)
Troubleshooting Generation
Common Issues:
-
Invalid JSON Schema:
โ Schema validation failed - found 0 definitions
Solution: Check your JSON syntax and ensure
definitionssection exists -
Python Import Errors:
โ Python imports test failed
Solution: Check for syntax errors in generated Python files
-
TypeScript Compilation Errors:
โ TypeScript build failed
Solution: Check for duplicate exports or syntax errors
Debug Tips:
- Use a JSON schema validator to check your schema
- Test Python imports manually:
python3 -c "from src.auth_sdk import YourType" - Check TypeScript compilation:
cd node && npx tsc --noEmit
โก Quick Start
Node.js (TypeScript/JavaScript)
npm install @pratik_25/auth-sdk
import { AuthService, AuthServiceConfig, SignupRequest } from '@pratik_25/auth-sdk';
const config: AuthServiceConfig = {
url: 'https://your-auth-service.com',
publicKey: 'your_public_key',
secretKey: 'your_secret_key'
};
const authService = new AuthService(config);
// Sign up a new user
const user = await authService.signup({
firstName: 'John',
lastName: 'Doe',
email: 'john@example.com',
password: 'secure_password123'
});
console.log(`User created with ID: ${user.authId}`);
Python
pip install arvasit-auth-sdk
from auth_sdk import AuthService, AuthServiceConfig, SignupRequest
config = AuthServiceConfig(
url="https://your-auth-service.com",
public_key="your_public_key",
secret_key="your_secret_key"
)
auth_service = AuthService(config)
# Sign up a new user
signup_data = SignupRequest(
firstName="John",
lastName="Doe",
email="john@example.com",
password="secure_password123"
)
user = auth_service.signup(signup_data)
print(f"User created with ID: {user.authId}")
๐ฆ Node.js SDK
Installation
npm install @pratik_25/auth-sdk
Available APIs
- Authentication:
signup(),loginWithPassword(),loginWithOtp(),logout() - Magic Link Authentication:
verifyMagicLink() - User Management:
suggestUsername(),checkAvailableUserName(),checkCredential() - Password Management:
enterCredentialForForgotPassword(),forgotPasswordSendOTP(),updatePassword() - Two-Factor Authentication:
generateQRCodeAndSecretFor2FA(),verifyQRCodeAndSecretFor2FA() - Recovery Codes:
generateRecoveryCodes(),listOfRecoveryCode() - Token Management:
refreshAccessToken() - Login Activity:
loginActivityCounts(),loginActivityDetails()
๐ Python SDK
Installation
pip install arvasit-auth-sdk
Available APIs
- Authentication:
signup(),login_with_password(),login_with_otp(),logout() - Magic Link Authentication:
verify_magic_link() - User Management:
suggest_username(),check_available_username(),check_credential() - Password Management:
enter_credential_for_forgot_password(),forgot_password_send_otp(),update_password() - Two-Factor Authentication:
generate_qr_code_and_secret_for_2fa(),verify_qr_code_and_secret_for_2fa() - Recovery Codes:
generate_recovery_codes(),list_of_recovery_code() - Token Management:
refresh_access_token() - Login Activity:
login_activity_counts(),login_activity_details()
Common Use Cases
Complete User Registration and 2FA Setup
// Node.js
const user = await authService.signup(signupData);
const loginResult = await authService.loginWithPassword(loginData);
const twofaData = await authService.generateQRCodeAndSecretFor2FA(loginResult.accessToken);
// Python
user = auth_service.signup(signup_data)
login_result = auth_service.login_with_password(login_data)
twofa_data = auth_service.generate_qr_code_and_secret_for_2fa(login_result.accessToken)
Magic Link Authentication
// Node.js
const magicLinkResult = await authService.verifyMagicLink({
token: 'magic-link-token-from-email',
credential: 'john@example.com'
});
// Python
magic_link_result = auth_service.verify_magic_link(
VerifyMagicLinkRequest(
token="magic-link-token-from-email",
credential="john@example.com"
)
)
Forgot Password Flow
// Node.js
const contactInfo = await authService.enterCredentialForForgotPassword('john@example.com');
const resetToken = await authService.verifyForgotPasswordOtp({ credential: 'john@example.com', otp: '123456' });
// Python
contact_info = auth_service.enter_credential_for_forgot_password('john@example.com')
reset_token = auth_service.verify_forgot_password_otp('john@example.com', '123456')
Login Activity Monitoring
// Node.js
const activityCounts = await authService.loginActivityCounts({
accessToken: accessToken,
startDate: '2023-01-01',
endDate: '2023-01-31'
});
// Python
activity_counts = auth_service.login_activity_counts(
access_token=access_token,
start_date='2023-01-01',
end_date='2023-01-31'
)
Configuration
Both SDKs require the same configuration parameters:
// Node.js
const config: AuthServiceConfig = {
url: 'https://your-auth-service.com',
publicKey: 'your_public_key',
secretKey: 'your_secret_key'
};
# Python
config = AuthServiceConfig(
url="https://your-auth-service.com",
public_key="your_public_key",
secret_key="your_secret_key"
)
Dependencies
Node.js SDK
- TypeScript 5.8+
- Node.js 18+
- axios>=1.8.4
- luxon>=3.6.1
Python SDK
- Python 3.8+
- requests>=2.31.0
- pydantic>=2.0.0
- python-dateutil>=2.8.2
Testing
Both SDKs include comprehensive test suites:
# Node.js
cd node
npm test
# Python
cd python
python -m pytest tests/ -v
Examples
- Node.js: Check the
node/src/directory for usage examples - Python: Check the
python/examples/directory for comprehensive examples
API Coverage
Both SDKs provide 100% feature parity with the following categories:
| Feature Category | Node.js SDK | Python SDK |
|---|---|---|
| User Authentication | โ | โ |
| User Management | โ | โ |
| Password Management | โ | โ |
| Two-Factor Authentication | โ | โ |
| Recovery Codes | โ | โ |
| Token Management | โ | โ |
| Login Activity | โ | โ |
| Type Safety | โ | โ |
| Error Handling | โ | โ |
๐ Schema-Driven Development
This project uses a revolutionary schema-driven approach that eliminates duplicate code and ensures perfect consistency between SDKs.
๐ฏ Key Benefits
- โ Single Source of Truth: One JSON schema drives both SDKs
- โ Zero Duplication: No more maintaining types in two places
- โ Automatic Consistency: Types are always perfectly synchronized
- โ Type Safety: Full TypeScript and Python type definitions
- โ Easy Maintenance: Update schema โ Both SDKs updated automatically
- โ Schema Validation: JSON schema provides runtime validation
- โ Better Documentation: Schema includes property descriptions
๐๏ธ How It Works
graph TD
A[schemas/auth-types.json] --> B[scripts/generate-types.py]
B --> C[node/src/auth-types.ts]
B --> D[node/src/index.ts]
B --> E[python/src/auth_sdk/auth_types.py]
B --> F[python/src/auth_sdk/__init__.py]
C --> G[TypeScript SDK]
D --> G
E --> H[Python SDK]
F --> H
๐ Current Schema Stats
- 41 Type Definitions in the schema
- 40 Exported Types (excluding duplicates)
- 100% Feature Parity between Node.js and Python
- Automatic $ref Resolution for complex types
๐ Examples & Documentation
Comprehensive Examples
- Python: Check
python/examples/basic_usage.pyfor complete usage examples - Node.js: All examples are in the Quick Start section above
API Documentation
Both SDKs provide full IntelliSense/autocomplete support:
- TypeScript: Full type definitions with JSDoc comments
- Python: Pydantic models with field validation and documentation
Common Patterns
// Complete authentication flow
const user = await authService.signup(signupData);
const loginResult = await authService.loginWithPassword(loginData);
const twofaData = await authService.generateQRCodeAndSecretFor2FA(loginResult.accessToken);
# Complete authentication flow
user = auth_service.signup(signup_data)
login_result = auth_service.login_with_password(login_data)
twofa_data = auth_service.generate_qr_code_and_secret_for_2fa(login_result.accessToken)
๐ง Development
Contributing
- Fork the repository
- Update the schema (
schemas/auth-types.json) - Regenerate SDKs (
python3 scripts/generate-types.py) - Test your changes (both Node.js and Python)
- Submit a pull request
Local Development
# Clone the repository
git clone https://github.com/arvasit/auth-sdk.git
cd auth-sdk
# Generate SDKs
python3 scripts/generate-types.py
# Test Node.js SDK
cd node && npm install && npm run build
# Test Python SDK
cd ../python && python3 -c "from src.auth_sdk import AuthService; print('โ
Python SDK works')"
๐ License
MIT License - see LICENSE file for details.
๐ Support
- Documentation: Check this README and examples
- Issues: GitHub Issues
- Discussions: GitHub Discussions
๐ฏ Roadmap
- Go SDK - Generate Go client from the same schema
- Java SDK - Generate Java client from the same schema
- OpenAPI Integration - Generate OpenAPI spec from schema
- GraphQL Support - Add GraphQL schema generation
- Enhanced Validation - Runtime schema validation
- Documentation Generation - Auto-generate API docs
Made with โค๏ธ by the Arvasit team
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file arvasit_auth_sdk-0.1.9.tar.gz.
File metadata
- Download URL: arvasit_auth_sdk-0.1.9.tar.gz
- Upload date:
- Size: 12.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4ccb79b8b12e81c23055a53ddf6b853818c8445668a5a7eb5badd6e0c101b4af
|
|
| MD5 |
d30b89da2338cefdebcba85414f5dff1
|
|
| BLAKE2b-256 |
8ecf3e1859dd9e608d6c871f82c13a15ac656d810a519c958229a1f1f9aa75ed
|
File details
Details for the file arvasit_auth_sdk-0.1.9-py3-none-any.whl.
File metadata
- Download URL: arvasit_auth_sdk-0.1.9-py3-none-any.whl
- Upload date:
- Size: 12.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9fceedd1b41945554c09dde80bd3d6b1163e7d3272e18bf27ca40fa929141c88
|
|
| MD5 |
ab4583c0b99764d483385eaa48da5475
|
|
| BLAKE2b-256 |
179cb0905884c6cd1ae9a30e99a10a0b9456d6c41d38b9f8a6f0ca4cac0d9756
|