|
|
|
@@ -38,11 +38,13 @@ class AtprotoOAuthService {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Support multiple PDS hosts for OAuth
|
|
|
|
|
console.log('[OAuth Debug] Initializing OAuth client with default settings');
|
|
|
|
|
this.oauthClient = await BrowserOAuthClient.load({
|
|
|
|
|
clientId: clientId,
|
|
|
|
|
handleResolver: 'https://bsky.social', // Default resolver
|
|
|
|
|
plcDirectoryUrl: 'https://plc.directory', // Default PLC directory
|
|
|
|
|
});
|
|
|
|
|
console.log('[OAuth Debug] OAuth client initialized with defaults');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -116,23 +118,24 @@ class AtprotoOAuthService {
|
|
|
|
|
// Create Agent directly with session (per official docs)
|
|
|
|
|
try {
|
|
|
|
|
this.agent = new Agent(session);
|
|
|
|
|
|
|
|
|
|
console.log('[OAuth Debug] Agent created successfully with session');
|
|
|
|
|
|
|
|
|
|
// Check if agent has session info after creation
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (this.agent.session) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
console.log('[OAuth Debug] Agent has session:', this.agent.session);
|
|
|
|
|
}
|
|
|
|
|
} catch (err) {
|
|
|
|
|
|
|
|
|
|
console.log('[OAuth Debug] Failed to create agent with session:', err);
|
|
|
|
|
// Fallback to dpopFetch method
|
|
|
|
|
try {
|
|
|
|
|
this.agent = new Agent({
|
|
|
|
|
service: session.server?.serviceEndpoint || 'https://bsky.social',
|
|
|
|
|
fetch: session.dpopFetch
|
|
|
|
|
});
|
|
|
|
|
console.log('[OAuth Debug] Agent created with dpopFetch fallback');
|
|
|
|
|
} catch (fallbackErr) {
|
|
|
|
|
console.error('[OAuth Debug] Failed to create agent with fallback:', fallbackErr);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Store basic session info
|
|
|
|
@@ -274,22 +277,30 @@ class AtprotoOAuthService {
|
|
|
|
|
|
|
|
|
|
// Detect PDS based on handle
|
|
|
|
|
const pdsUrl = await this.detectPDSFromHandle(handle);
|
|
|
|
|
// Starting OAuth flow
|
|
|
|
|
|
|
|
|
|
console.log('[OAuth Debug] Detected PDS for handle', handle, ':', pdsUrl);
|
|
|
|
|
|
|
|
|
|
// Always re-initialize OAuth client with detected PDS
|
|
|
|
|
// Re-initializing OAuth client
|
|
|
|
|
console.log('[OAuth Debug] Re-initializing OAuth client');
|
|
|
|
|
|
|
|
|
|
// Clear existing client to force fresh initialization
|
|
|
|
|
this.oauthClient = null;
|
|
|
|
|
this.initializePromise = null;
|
|
|
|
|
|
|
|
|
|
// Determine PLC directory based on input handle, not environment PDS
|
|
|
|
|
let plcDirectoryUrl = 'https://plc.directory'; // Default to Bluesky PLC
|
|
|
|
|
if (handle.endsWith('.syu.is') || handle.endsWith('.syui.ai')) {
|
|
|
|
|
plcDirectoryUrl = 'https://plc.syu.is';
|
|
|
|
|
}
|
|
|
|
|
console.log('[OAuth Debug] Using PLC directory:', plcDirectoryUrl);
|
|
|
|
|
|
|
|
|
|
this.oauthClient = await BrowserOAuthClient.load({
|
|
|
|
|
clientId: this.getClientId(),
|
|
|
|
|
handleResolver: pdsUrl,
|
|
|
|
|
plcDirectoryUrl: pdsUrl === 'https://syu.is' ? 'https://plc.syu.is' : 'https://plc.directory',
|
|
|
|
|
plcDirectoryUrl: plcDirectoryUrl,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
console.log('[OAuth Debug] OAuth client re-initialized successfully');
|
|
|
|
|
|
|
|
|
|
// OAuth client initialized
|
|
|
|
|
|
|
|
|
|
// Start OAuth authorization flow
|
|
|
|
|