feat: Add onPopupWindow callback and update README (#32)
* feat: Add onPopupWindow callback and update README * feat: Pass window reference to onPopupWindow callback --------- Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
This commit is contained in:
parent
c47ea828c3
commit
043efbcf12
1 changed files with 18 additions and 0 deletions
|
|
@ -15,6 +15,7 @@ export class BrowserOAuthClientProvider implements OAuthClientProvider {
|
|||
readonly clientName: string
|
||||
readonly clientUri: string
|
||||
readonly callbackUrl: string
|
||||
readonly onPopupWindow: ((url: string, features: string, window: Window | null) => void) | undefined
|
||||
|
||||
constructor(
|
||||
serverUrl: string,
|
||||
|
|
@ -23,6 +24,7 @@ export class BrowserOAuthClientProvider implements OAuthClientProvider {
|
|||
clientName?: string
|
||||
clientUri?: string
|
||||
callbackUrl?: string
|
||||
onPopupWindow?: (url: string, features: string, window: Window | null) => void
|
||||
} = {},
|
||||
) {
|
||||
this.serverUrl = serverUrl
|
||||
|
|
@ -34,6 +36,7 @@ export class BrowserOAuthClientProvider implements OAuthClientProvider {
|
|||
options.callbackUrl ||
|
||||
(typeof window !== 'undefined' ? new URL('/oauth/callback', window.location.origin).toString() : '/oauth/callback'),
|
||||
)
|
||||
this.onPopupWindow = options.onPopupWindow
|
||||
}
|
||||
|
||||
// --- SDK Interface Methods ---
|
||||
|
|
@ -169,6 +172,11 @@ export class BrowserOAuthClientProvider implements OAuthClientProvider {
|
|||
try {
|
||||
const popup = window.open(sanitizedAuthUrl, `mcp_auth_${this.serverUrlHash}`, popupFeatures)
|
||||
|
||||
// If a callback is provided, invoke it after opening the popup
|
||||
if (this.onPopupWindow) {
|
||||
this.onPopupWindow(sanitizedAuthUrl, popupFeatures, popup)
|
||||
}
|
||||
|
||||
if (!popup || popup.closed || typeof popup.closed === 'undefined') {
|
||||
console.warn(
|
||||
`[${this.storageKeyPrefix}] Popup likely blocked by browser. Manual navigation might be required using the stored URL.`,
|
||||
|
|
|
|||
Loading…
Reference in a new issue