#!/usr/bin/env python3
"""
ActiveCollab API Token Generator (Self-Hosted)
Run this script once to generate your API token.
After getting the token, add it to config.json and delete this script.
"""
import json
import urllib.request
import urllib.error
import getpass
from pathlib import Path
SCRIPT_DIR = Path(__file__).parent
def post_json(url: str, data: dict) -> dict:
req = urllib.request.Request(
url,
data=json.dumps(data).encode('utf-8'),
headers={
'Content-Type': 'application/json',
'User-Agent': 'ActiveCollab-MCP-TokenGenerator/1.0'
}
)
try:
with urllib.request.urlopen(req) as response:
return json.loads(response.read().decode('utf-8'))
except urllib.error.HTTPError as e:
error_body = e.read().decode('utf-8')
print(f"HTTP Error {e.code}: {error_body}")
raise
def main():
print("=== ActiveCollab API Token Generator (Self-Hosted) ===\n")
base_url = input("ActiveCollab URL (e.g., https://collab.inchoo.net): ").rstrip('/')
email = input("Email: ")
password = getpass.getpass("Password: ")
print("\nGenerating token...")
token_url = f"{base_url}/api/v1/issue-token"
try:
response = post_json(token_url, {
"username": email,
"password": password,
"client_name": "Claude MCP Server",
"client_vendor": "Inchoo"
})
if response.get("is_ok") and response.get("token"):
token = response["token"]
print("\n" + "=" * 50)
print("SUCCESS! Here are your credentials:\n")
print(f"API URL: {base_url}/api/v1")
print(f"API Token: {token}")
print("=" * 50)
config = {
"activecollab": {
"api_url": f"{base_url}/api/v1",
"api_token": token
},
"cache": {
"enabled": True,
"ttl_seconds": 300
}
}
print("\nconfig.json content:")
print(json.dumps(config, indent=2))
save = input("\nSave to config.json now? (y/n): ")
if save.lower() == 'y':
config_path = SCRIPT_DIR / "config.json"
with open(config_path, "w") as f:
json.dump(config, f, indent=2)
print(f"Saved to {config_path}!")
print("\nIMPORTANT: Delete this script and never commit config.json to git!")
else:
print(f"Failed: {response}")
except urllib.error.HTTPError as e:
if e.code == 500:
print("\nError: Invalid credentials or user doesn't exist")
else:
print(f"\nFailed with error {e.code}")
if __name__ == "__main__":
main()