scientific-skills/labarchive-integration/references/authentication_guide.md
API access requires an Enterprise LabArchives license. Contact your LabArchives administrator or [email protected] to:
You need two sets of credentials:
The external applications password is different from your regular LabArchives login password. It provides API access without exposing your primary credentials.
Steps to create external applications password:
Security note: Treat this password like an API token. If compromised, regenerate it immediately from account settings.
Create a config.yaml file to store your credentials securely:
# Regional API endpoint
api_url: https://api.labarchives.com/api
# Institutional credentials (from administrator)
access_key_id: YOUR_ACCESS_KEY_ID_HERE
access_password: YOUR_ACCESS_PASSWORD_HERE
# User credentials (for user-specific operations)
user_email: [email protected]
user_external_password: YOUR_EXTERNAL_APP_PASSWORD_HERE
Alternative: Environment variables
For enhanced security, use environment variables instead of config file:
export LABARCHIVES_API_URL="https://api.labarchives.com/api"
export LABARCHIVES_ACCESS_KEY_ID="your_key_id"
export LABARCHIVES_ACCESS_PASSWORD="your_access_password"
export LABARCHIVES_USER_EMAIL="[email protected]"
export LABARCHIVES_USER_PASSWORD="your_external_app_password"
Select the correct regional API endpoint for your institution:
| Region | Endpoint | Use if your LabArchives URL is |
|---|---|---|
| US/International | https://api.labarchives.com/api | mynotebook.labarchives.com |
| Australia | https://auapi.labarchives.com/api | aunotebook.labarchives.com |
| UK | https://ukapi.labarchives.com/api | uknotebook.labarchives.com |
Using the wrong regional endpoint will result in authentication failures even with correct credentials.
from labarchivespy.client import Client
import yaml
# Load configuration
with open('config.yaml', 'r') as f:
config = yaml.safe_load(f)
# Initialize client with institutional credentials
client = Client(
config['api_url'],
config['access_key_id'],
config['access_password']
)
# Authenticate as specific user to get UID
login_params = {
'login_or_email': config['user_email'],
'password': config['user_external_password']
}
response = client.make_call('users', 'user_access_info', params=login_params)
# Parse response to extract UID
import xml.etree.ElementTree as ET
uid = ET.fromstring(response.content)[0].text
print(f"Authenticated as user ID: {uid}")
import requests
import yaml
# Load configuration
with open('config.yaml', 'r') as f:
config = yaml.safe_load(f)
# Construct API call
url = f"{config['api_url']}/users/user_access_info"
params = {
'access_key_id': config['access_key_id'],
'access_password': config['access_password'],
'login_or_email': config['user_email'],
'password': config['user_external_password']
}
# Make authenticated request
response = requests.get(url, params=params)
if response.status_code == 200:
print("Authentication successful!")
print(response.content.decode('utf-8'))
else:
print(f"Authentication failed: {response.status_code}")
print(response.content.decode('utf-8'))
library(httr)
library(xml2)
# Configuration
api_url <- "https://api.labarchives.com/api"
access_key_id <- "YOUR_ACCESS_KEY_ID"
access_password <- "YOUR_ACCESS_PASSWORD"
user_email <- "[email protected]"
user_external_password <- "YOUR_EXTERNAL_APP_PASSWORD"
# Make authenticated request
response <- GET(
paste0(api_url, "/users/user_access_info"),
query = list(
access_key_id = access_key_id,
access_password = access_password,
login_or_email = user_email,
password = user_external_password
)
)
# Parse response
if (status_code(response) == 200) {
content <- content(response, as = "text", encoding = "UTF-8")
xml_data <- read_xml(content)
uid <- xml_text(xml_find_first(xml_data, "//uid"))
print(paste("Authenticated as user ID:", uid))
} else {
print(paste("Authentication failed:", status_code(response)))
}
LabArchives now uses OAuth 2.0 for new third-party integrations. Legacy API key authentication (described above) continues to work for direct API access.
OAuth flow (for app developers):
Contact LabArchives developer support for OAuth integration documentation.
Possible causes and solutions:
Incorrect access_key_id or access_password
Wrong external applications password
API access not enabled
Wrong regional endpoint
Possible causes and solutions:
Insufficient permissions
Account suspended or expired
Firewall/proxy configuration:
If your institution uses a firewall or proxy:
import requests
# Configure proxy
proxies = {
'http': 'http://proxy.university.edu:8080',
'https': 'http://proxy.university.edu:8080'
}
# Make request with proxy
response = requests.get(url, params=params, proxies=proxies)
SSL certificate verification:
For self-signed certificates (not recommended for production):
# Disable SSL verification (use only for testing)
response = requests.get(url, params=params, verify=False)
Never commit credentials to version control
config.yaml to .gitignoreRotate credentials regularly
Use least privilege principle
Monitor API usage
Secure storage
Use this script to verify your authentication setup:
#!/usr/bin/env python3
"""Test LabArchives API authentication"""
from labarchivespy.client import Client
import yaml
import sys
def test_authentication():
try:
# Load config
with open('config.yaml', 'r') as f:
config = yaml.safe_load(f)
print("Configuration loaded successfully")
print(f"API URL: {config['api_url']}")
# Initialize client
client = Client(
config['api_url'],
config['access_key_id'],
config['access_password']
)
print("Client initialized")
# Test authentication
login_params = {
'login_or_email': config['user_email'],
'password': config['user_external_password']
}
response = client.make_call('users', 'user_access_info', params=login_params)
if response.status_code == 200:
print("✅ Authentication successful!")
# Extract UID
import xml.etree.ElementTree as ET
uid = ET.fromstring(response.content)[0].text
print(f"User ID: {uid}")
# Get user info
user_response = client.make_call('users', 'user_info_via_id', params={'uid': uid})
print("✅ User information retrieved successfully")
return True
else:
print(f"❌ Authentication failed: {response.status_code}")
print(response.content.decode('utf-8'))
return False
except Exception as e:
print(f"❌ Error: {str(e)}")
import traceback
traceback.print_exc()
return False
if __name__ == '__main__':
success = test_authentication()
sys.exit(0 if success else 1)
Run this script to confirm everything is configured correctly:
python3 test_auth.py
If authentication continues to fail after troubleshooting: