adobe-ps-scripts-loreal/ARCHIVE/test_auth.py
DJP 4a192a8c97 Initial commit: Adobe Photoshop API text management scripts
Local and cloud-based workflows for extracting and updating
text layers in PSD files via ExtendScript and Adobe PS API.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-02 13:46:52 -05:00

172 lines
No EOL
7.6 KiB
Python

#!/usr/bin/env python3
"""
Simple script to test Adobe API authentication with additional debugging
"""
import requests
import time
import json
# The token from your update
API_KEY = "f34becb759244899bd73b86220f6fb92"
ACCESS_TOKEN = "eyJhbGciOiJSUzI1NiIsIng1dSI6Imltc19uYTEta2V5LWF0LTEuY2VyIiwia2lkIjoiaW1zX25hMS1rZXktYXQtMSIsIml0dCI6ImF0In0.eyJpZCI6IjE3NDQ4NzYzNDM5MzdfNTE1YjU0NTgtZDU3NC00N2RlLThmNzgtYjQ5MGMwYjZiOWYyX3VlMSIsIm9yZyI6IkZBRDYxRTI3NjY4NkRCM0QwQTQ5NUVDNEBBZG9iZU9yZyIsInR5cGUiOiJhY2Nlc3NfdG9rZW4iLCJjbGllbnRfaWQiOiJmMzRiZWNiNzU5MjQ0ODk5YmQ3M2I4NjIyMGY2ZmI5MiIsInVzZXJfaWQiOiJEQTM3MUY1NzY3RUJEMDdEMEE0OTVGOTRAdGVjaGFjY3QuYWRvYmUuY29tIiwiYXMiOiJpbXMtbmExIiwiYWFfaWQiOiJEQTM3MUY1NzY3RUJEMDdEMEE0OTVGOTRAdGVjaGFjY3QuYWRvYmUuY29tIiwiY3RwIjozLCJtb2kiOiIzMDA1NWZlNyIsImV4cGlyZXNfaW4iOiI4NjQwMDAwMCIsImNyZWF0ZWRfYXQiOiIxNzQ0ODc2MzQzOTM3Iiwic2NvcGUiOiJvcGVuaWQsQWRvYmVJRCxyZWFkX29yZ2FuaXphdGlvbnMifQ.P0J4J7Qy-zflhrq6u2JX1rXucimiwuR__bkXJnZ4ZSiNY9G6fMPL1ym0isrFTAadVisgJLlHsh0QQZpLY5l-Uv3XZZRWnbK7fo2uDy4j-o7Y4aO7vBQ-VyCS8C7D_msgnHHnFcxwYXGAmv10-AFUfBsw3Y1xRVjDMIJH1Ux8NdbZ8j1zJXN1FPuuBi8fH1hmKda85nuXJsKc7TqaYBzX4AGzWBPV6hyoKedzrNtPCNRx3muhHnCS_q6wmk6Jx6kVAxrYPeeoA-W-ZKJrP-5BhQf0KUVOBtaCBKlrDL-ftML0LZlWswB14kKTMkt9R7z6xwLyPWfD1ldFh3bEMaa0YA"
def test_auth(access_token, api_key=None):
"""Test authentication with Adobe API"""
print(f"Testing authentication with token: {access_token[:20]}...{access_token[-20:]}")
try:
# Test with userinfo endpoint (requires auth token only)
headers = {"Authorization": f"Bearer {access_token}"}
response = requests.get(
"https://ims-na1.adobelogin.com/ims/userinfo",
headers=headers,
timeout=20
)
print(f"IMS User Info response status: {response.status_code}")
try:
headers_dict = dict(response.headers)
print(f"Response headers: {json.dumps(headers_dict, indent=2)}")
except:
print("Could not display response headers")
if response.text:
print(f"Response body: {response.text}")
# If API key is provided, also test an API that requires both
if api_key:
api_headers = {
"Authorization": f"Bearer {access_token}",
"x-api-key": api_key,
"Content-Type": "application/json"
}
print("\nTesting with API key and token together...")
# Try Adobe Developer API
dev_response = requests.get(
"https://developer.adobe.com/apis",
headers=api_headers,
timeout=20
)
print(f"Developer API response status: {dev_response.status_code}")
# Try Stock API
stock_params = {"search_parameters[limit]": 1}
stock_response = requests.get(
"https://stock.adobe.io/Rest/Media/1/Search/Files",
headers=api_headers,
params=stock_params,
timeout=20
)
print(f"Stock API response status: {stock_response.status_code}")
if stock_response.text and len(stock_response.text) < 500:
print(f"Stock API response: {stock_response.text}")
# Test Photoshop API endpoints that we need
ps_endpoints = [
"https://image.adobe.io/pie/psdService/text",
"https://image.adobe.io/pie/psdService/presignedUrl",
"https://firefly-api.adobe.io/v2/photoshop/editText",
"https://firefly-api.adobe.io/v2/storage/presignedUrl"
]
print("\nTesting Photoshop API endpoints:")
for endpoint in ps_endpoints:
try:
ps_response = requests.get(
endpoint,
headers=api_headers,
timeout=15
)
print(f" {endpoint}: Status {ps_response.status_code}")
# If we get a response that's not too long, show it
if ps_response.text and len(ps_response.text) < 300:
print(f" Response: {ps_response.text}")
except Exception as e:
print(f" {endpoint}: Error - {str(e)}")
# Analyze token regardless of auth success
try:
import base64
# Get payload part (second part of the JWT token)
payload = access_token.split('.')[1]
# Add padding if needed
padding = len(payload) % 4
if padding:
payload += '=' * (4 - padding)
# Decode the payload
decoded = base64.b64decode(payload)
token_data = json.loads(decoded)
# Extract token data
print("\nToken data (full JWT payload):")
print(json.dumps(token_data, indent=2))
# Check created_at and expires_in
# Note: Adobe timestamps are in milliseconds since epoch
created_at_ms = int(token_data.get('created_at', 0))
created_at = created_at_ms / 1000 # Convert to seconds
expires_in_sec = int(token_data.get('expires_in', 0))
current_time = time.time()
print("\nToken details (corrected timestamps):")
print(f" Created at: {time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(created_at))}")
print(f" Expires in: {expires_in_sec} seconds ({expires_in_sec/86400:.1f} days)")
print(f" Current time: {time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(current_time))}")
# Check if token is expired
expiration_time = created_at + expires_in_sec
if current_time > expiration_time:
print(f" ✗ Token EXPIRED on {time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(expiration_time))}")
else:
print(f" ✓ Token valid until {time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(expiration_time))}")
print(f" ({(expiration_time - current_time)/86400:.1f} days remaining)")
# Calculate actual age of token
token_age_days = (current_time - created_at) / 86400
print(f" Token age: {token_age_days:.1f} days")
# Print scopes
scopes = token_data.get('scope', '').split(',')
print("\nToken scopes:")
for scope in scopes:
print(f" - {scope}")
except Exception as e:
print(f"Error analyzing token: {str(e)}")
if response.status_code == 200:
print("\n✓ Authentication successful!")
return True
else:
print(f"\n✗ Authentication failed: {response.status_code}")
return False
except Exception as e:
print(f"✗ Error testing authentication: {str(e)}")
return False
if __name__ == "__main__":
print("Enhanced Adobe API Authentication Test")
print("-" * 40)
print("Testing token and API key...")
# Try a few times in case of network issues
max_attempts = 2
for attempt in range(1, max_attempts + 1):
print(f"\nAttempt {attempt} of {max_attempts}")
result = test_auth(ACCESS_TOKEN, API_KEY)
if result:
break
elif attempt < max_attempts:
print(f"Retrying in 5 seconds...")
time.sleep(5)
print("\nTest complete.")