Stopping any window.open if the preventAutoAuth flag is set (#34)
This commit is contained in:
parent
8952e3b47d
commit
8337ff0a68
2 changed files with 8 additions and 0 deletions
|
|
@ -15,6 +15,7 @@ export class BrowserOAuthClientProvider implements OAuthClientProvider {
|
||||||
readonly clientName: string
|
readonly clientName: string
|
||||||
readonly clientUri: string
|
readonly clientUri: string
|
||||||
readonly callbackUrl: string
|
readonly callbackUrl: string
|
||||||
|
private preventAutoAuth?: boolean
|
||||||
readonly onPopupWindow: ((url: string, features: string, window: Window | null) => void) | undefined
|
readonly onPopupWindow: ((url: string, features: string, window: Window | null) => void) | undefined
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
|
|
@ -24,6 +25,7 @@ export class BrowserOAuthClientProvider implements OAuthClientProvider {
|
||||||
clientName?: string
|
clientName?: string
|
||||||
clientUri?: string
|
clientUri?: string
|
||||||
callbackUrl?: string
|
callbackUrl?: string
|
||||||
|
preventAutoAuth?: boolean
|
||||||
onPopupWindow?: (url: string, features: string, window: Window | null) => void
|
onPopupWindow?: (url: string, features: string, window: Window | null) => void
|
||||||
} = {},
|
} = {},
|
||||||
) {
|
) {
|
||||||
|
|
@ -36,6 +38,7 @@ export class BrowserOAuthClientProvider implements OAuthClientProvider {
|
||||||
options.callbackUrl ||
|
options.callbackUrl ||
|
||||||
(typeof window !== 'undefined' ? new URL('/oauth/callback', window.location.origin).toString() : '/oauth/callback'),
|
(typeof window !== 'undefined' ? new URL('/oauth/callback', window.location.origin).toString() : '/oauth/callback'),
|
||||||
)
|
)
|
||||||
|
this.preventAutoAuth = options.preventAutoAuth
|
||||||
this.onPopupWindow = options.onPopupWindow
|
this.onPopupWindow = options.onPopupWindow
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -164,6 +167,9 @@ export class BrowserOAuthClientProvider implements OAuthClientProvider {
|
||||||
* @param authorizationUrl The fully constructed authorization URL from the SDK.
|
* @param authorizationUrl The fully constructed authorization URL from the SDK.
|
||||||
*/
|
*/
|
||||||
async redirectToAuthorization(authorizationUrl: URL): Promise<void> {
|
async redirectToAuthorization(authorizationUrl: URL): Promise<void> {
|
||||||
|
// Ideally we should catch things before we get here, but if we don't, let's not show everyone we are dum
|
||||||
|
if (this.preventAutoAuth) return
|
||||||
|
|
||||||
// Prepare the authorization URL with state
|
// Prepare the authorization URL with state
|
||||||
const sanitizedAuthUrl = await this.prepareAuthorizationUrl(authorizationUrl)
|
const sanitizedAuthUrl = await this.prepareAuthorizationUrl(authorizationUrl)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -177,6 +177,7 @@ export function useMcp(options: UseMcpOptions): UseMcpResult {
|
||||||
clientName,
|
clientName,
|
||||||
clientUri,
|
clientUri,
|
||||||
callbackUrl,
|
callbackUrl,
|
||||||
|
preventAutoAuth,
|
||||||
onPopupWindow,
|
onPopupWindow,
|
||||||
})
|
})
|
||||||
addLog('debug', 'BrowserOAuthClientProvider initialized in connect.')
|
addLog('debug', 'BrowserOAuthClientProvider initialized in connect.')
|
||||||
|
|
@ -781,6 +782,7 @@ export function useMcp(options: UseMcpOptions): UseMcpResult {
|
||||||
clientName,
|
clientName,
|
||||||
clientUri,
|
clientUri,
|
||||||
callbackUrl,
|
callbackUrl,
|
||||||
|
preventAutoAuth,
|
||||||
onPopupWindow,
|
onPopupWindow,
|
||||||
})
|
})
|
||||||
addLog('debug', 'BrowserOAuthClientProvider initialized/updated on mount/option change.')
|
addLog('debug', 'BrowserOAuthClientProvider initialized/updated on mount/option change.')
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue