adpa-enterprise-framework-automation
Version:
Modular, standards-compliant Node.js/TypeScript automation framework for enterprise requirements, project, and data management. Provides CLI and API for BABOK v3, PMBOK 7th Edition, and DMBOK 2.0 (in progress). Production-ready Express.js API with TypeSpe
83 lines • 2.87 kB
JavaScript
import jwt from 'jsonwebtoken';
import { config } from './config.js';
import { logger } from '../utils/logger.js';
export class AdobeAuthenticator {
jwt = null;
expiresAt = 0;
privateKey = null;
constructor() {
this.loadPrivateKey();
}
loadPrivateKey() {
try {
// Use the privateKey directly from config since it's already loaded from environment
if (config.privateKey) {
this.privateKey = config.privateKey;
logger.info('Adobe private key loaded successfully');
}
else {
logger.warn('Adobe private key not found in configuration, using mock authentication');
}
}
catch (error) {
logger.error('Failed to load Adobe private key:', error);
throw new Error('Adobe authentication setup failed');
}
}
async getAccessToken() {
// Check if current token is still valid
if (this.jwt && Date.now() < this.expiresAt) {
return this.jwt;
}
// Generate new JWT token
try {
const payload = {
iss: config.organizationId,
sub: config.accountId,
aud: `https://ims-na1.adobelogin.com/c/${config.clientId}`,
'https://ims-na1.adobelogin.com/s/ent_documentcloud_sdk': true,
iat: Math.floor(Date.now() / 1000),
exp: Math.floor(Date.now() / 1000) + 86400 // 24 hours
};
if (!this.privateKey) {
throw new Error('Private key not loaded');
}
this.jwt = jwt.sign(payload, this.privateKey, { algorithm: 'RS256' });
this.expiresAt = Date.now() + 86400000; // 24 hours
logger.info('Adobe JWT token generated successfully');
return this.jwt;
}
catch (error) {
logger.error('Failed to generate Adobe JWT token:', error);
throw new Error('Adobe authentication failed');
}
}
async authenticate() {
try {
const accessToken = await this.getAccessToken();
return {
accessToken,
expiresAt: this.expiresAt,
success: true
};
}
catch (error) {
logger.error('Adobe authentication failed:', error);
return {
accessToken: '',
expiresAt: 0,
success: false
};
}
}
isTokenValid() {
return this.jwt !== null && Date.now() < this.expiresAt;
}
clearToken() {
this.jwt = null;
this.expiresAt = 0;
logger.info('Adobe authentication token cleared');
}
}
export const adobeAuth = new AdobeAuthenticator();
//# sourceMappingURL=authenticator.js.map