This commit is contained in:
2025-06-17 14:13:11 +09:00
parent abc42330ed
commit be8fd38c59

View File

@@ -41,6 +41,7 @@ class AtprotoOAuthService {
this.oauthClient = await BrowserOAuthClient.load({
clientId: clientId,
handleResolver: 'https://bsky.social', // Default resolver
plcDirectoryUrl: 'https://plc.directory', // Default PLC directory
});
@@ -176,20 +177,43 @@ class AtprotoOAuthService {
return `${origin}/client-metadata.json`;
}
private detectPDSFromHandle(handle: string): string {
// Supported PDS hosts and their corresponding handles
private async detectPDSFromHandle(handle: string): Promise<string> {
// Handle detection for OAuth PDS routing
// Check if handle ends with known PDS domains first
const pdsMapping = {
'syu.is': 'https://syu.is',
'bsky.social': 'https://bsky.social',
};
// Check if handle ends with known PDS domains
for (const [domain, pdsUrl] of Object.entries(pdsMapping)) {
if (handle.endsWith(`.${domain}`)) {
return pdsUrl;
}
}
// For handles that don't match domain patterns, resolve via API
try {
// Try to resolve handle to get the actual PDS
const endpoints = ['https://syu.is', 'https://bsky.social'];
for (const endpoint of endpoints) {
try {
const response = await fetch(`${endpoint}/xrpc/com.atproto.identity.resolveHandle?handle=${encodeURIComponent(handle)}`);
if (response.ok) {
const data = await response.json();
if (data.did) {
return endpoint;
}
}
} catch (e) {
continue;
}
}
} catch (e) {
// Handle resolution failed, using default
}
// Default to bsky.social
return 'https://bsky.social';
}
@@ -217,9 +241,13 @@ class AtprotoOAuthService {
// Re-initialize OAuth client with correct PDS if needed
if (pdsUrl !== 'https://bsky.social') {
// Determine PLC directory for syu.is only
const plcDirectoryUrl = handle.endsWith('.syu.is') || handle.endsWith('.syui.ai') ? 'https://plc.syu.is' : 'https://plc.directory';
this.oauthClient = await BrowserOAuthClient.load({
clientId: this.getClientId(),
handleResolver: pdsUrl,
plcDirectoryUrl: plcDirectoryUrl,
});
}
@@ -591,10 +619,4 @@ class AtprotoOAuthService {
}
export const atprotoOAuthService = new AtprotoOAuthService();
// Debug: Make service available globally for testing
if (typeof window !== 'undefined') {
(window as any).atprotoOAuthService = atprotoOAuthService;
}
export type { AtprotoSession };