diff --git a/packages/@magic-ext/oauth2/src/index.ts b/packages/@magic-ext/oauth2/src/index.ts index 5b9912750..1c6c20d0c 100644 --- a/packages/@magic-ext/oauth2/src/index.ts +++ b/packages/@magic-ext/oauth2/src/index.ts @@ -8,6 +8,7 @@ import { OAuthRedirectConfiguration, OAuthPayloadMethods, OAuthRedirectStartResult, + OAuthPopupConfiguration, } from './types'; export class OAuthExtension extends Extension.Internal<'oauth2'> { @@ -64,6 +65,18 @@ export class OAuthExtension extends Extension.Internal<'oauth2'> { return getResult.call(this, queryString, lifespan); } + + public loginWithPopup(configuration: OAuthPopupConfiguration) { + const requestPayload = this.utils.createJsonRpcRequestPayload(OAuthPayloadMethods.Popup, [ + { + ...configuration, + apiKey: this.sdk.apiKey, + platform: 'web', + }, + ]); + + return this.request(requestPayload); + } } function getResult(this: OAuthExtension, queryString: string, lifespan?: number) { diff --git a/packages/@magic-ext/oauth2/src/types.ts b/packages/@magic-ext/oauth2/src/types.ts index 28295d979..310fffb41 100644 --- a/packages/@magic-ext/oauth2/src/types.ts +++ b/packages/@magic-ext/oauth2/src/types.ts @@ -3,6 +3,7 @@ import { MagicUserMetadata } from '@magic-sdk/types'; export enum OAuthPayloadMethods { Start = 'magic_oauth_login_with_redirect_start', Verify = 'magic_oauth_login_with_redirect_verify', + Popup = 'magic_oauth_login_with_popup', } export type OAuthProvider = @@ -99,6 +100,12 @@ export interface OAuthRedirectConfiguration { loginHint?: string; } +export interface OAuthPopupConfiguration { + provider: OAuthProvider; + scope?: string[]; + loginHint?: string; +} + export enum OAuthErrorCode { InvalidRequest = 'invalid_request', InvalidClient = 'invalid_client', diff --git a/packages/@magic-sdk/types/src/core/message-types.ts b/packages/@magic-sdk/types/src/core/message-types.ts index d6b441f02..d1cee37d4 100644 --- a/packages/@magic-sdk/types/src/core/message-types.ts +++ b/packages/@magic-sdk/types/src/core/message-types.ts @@ -9,6 +9,8 @@ export enum MagicIncomingWindowMessage { MAGIC_MG_BOX_SEND_RECEIPT = 'MAGIC_MG_BOX_SEND_RECEIPT', MAGIC_SEND_PRODUCT_ANNOUNCEMENT = 'MAGIC_SEND_PRODUCT_ANNOUNCEMENT', MAGIC_PONG = 'MAGIC_PONG', + MAGIC_POPUP_RESPONSE = 'MAGIC_POPUP_RESPONSE', + MAGIC_POPUP_OAUTH_VERIFY_RESPONSE = 'MAGIC_POPUP_OAUTH_VERIFY_RESPONSE', } export enum MagicOutgoingWindowMessage {