fix
This commit is contained in:
@@ -41,6 +41,7 @@ class AtprotoOAuthService {
|
|||||||
this.oauthClient = await BrowserOAuthClient.load({
|
this.oauthClient = await BrowserOAuthClient.load({
|
||||||
clientId: clientId,
|
clientId: clientId,
|
||||||
handleResolver: 'https://bsky.social', // Default resolver
|
handleResolver: 'https://bsky.social', // Default resolver
|
||||||
|
plcDirectoryUrl: 'https://plc.directory', // Default PLC directory
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
@@ -176,20 +177,43 @@ class AtprotoOAuthService {
|
|||||||
return `${origin}/client-metadata.json`;
|
return `${origin}/client-metadata.json`;
|
||||||
}
|
}
|
||||||
|
|
||||||
private detectPDSFromHandle(handle: string): string {
|
private async detectPDSFromHandle(handle: string): Promise<string> {
|
||||||
// Supported PDS hosts and their corresponding handles
|
// Handle detection for OAuth PDS routing
|
||||||
|
|
||||||
|
// Check if handle ends with known PDS domains first
|
||||||
const pdsMapping = {
|
const pdsMapping = {
|
||||||
'syu.is': 'https://syu.is',
|
'syu.is': 'https://syu.is',
|
||||||
'bsky.social': 'https://bsky.social',
|
'bsky.social': 'https://bsky.social',
|
||||||
};
|
};
|
||||||
|
|
||||||
// Check if handle ends with known PDS domains
|
|
||||||
for (const [domain, pdsUrl] of Object.entries(pdsMapping)) {
|
for (const [domain, pdsUrl] of Object.entries(pdsMapping)) {
|
||||||
if (handle.endsWith(`.${domain}`)) {
|
if (handle.endsWith(`.${domain}`)) {
|
||||||
return pdsUrl;
|
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
|
// Default to bsky.social
|
||||||
return 'https://bsky.social';
|
return 'https://bsky.social';
|
||||||
}
|
}
|
||||||
@@ -217,9 +241,13 @@ class AtprotoOAuthService {
|
|||||||
|
|
||||||
// Re-initialize OAuth client with correct PDS if needed
|
// Re-initialize OAuth client with correct PDS if needed
|
||||||
if (pdsUrl !== 'https://bsky.social') {
|
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({
|
this.oauthClient = await BrowserOAuthClient.load({
|
||||||
clientId: this.getClientId(),
|
clientId: this.getClientId(),
|
||||||
handleResolver: pdsUrl,
|
handleResolver: pdsUrl,
|
||||||
|
plcDirectoryUrl: plcDirectoryUrl,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -591,10 +619,4 @@ class AtprotoOAuthService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const atprotoOAuthService = new 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 };
|
export type { AtprotoSession };
|
||||||
|
Reference in New Issue
Block a user