@magic-ext/oauth2 9.2.0 → 9.2.1-canary.274fd4e.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cjs/index.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var p=Object.defineProperty,I=Object.defineProperties,O=Object.getOwnPropertyDescriptor,b=Object.getOwnPropertyDescriptors,w=Object.getOwnPropertyNames,R=Object.getOwnPropertySymbols;var f=Object.prototype.hasOwnProperty,U=Object.prototype.propertyIsEnumerable;var m=(t,r,e)=>r in t?p(t,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[r]=e,v=(t,r)=>{for(var e in r||(r={}))f.call(r,e)&&m(t,e,r[e]);if(R)for(var e of R(r))U.call(r,e)&&m(t,e,r[e]);return t},y=(t,r)=>I(t,b(r));var x=(t,r)=>{for(var e in r)p(t,e,{get:r[e],enumerable:!0})},k=(t,r,e,s)=>{if(r&&typeof r=="object"||typeof r=="function")for(let i of w(r))!f.call(t,i)&&i!==e&&p(t,i,{get:()=>r[i],enumerable:!(s=O(r,i))||s.enumerable});return t};var D=t=>k(p({},"__esModule",{value:!0}),t);var l=(t,r,e)=>new Promise((s,i)=>{var d=o=>{try{n(e.next(o))}catch(u){i(u)}},c=o=>{try{n(e.throw(o))}catch(u){i(u)}},n=o=>o.done?s(o.value):Promise.resolve(o.value).then(d,c);n((e=e.apply(t,r)).next())});var S={};x(S,{OAuthErrorCode:()=>_,OAuthExtension:()=>h,OAuthPayloadMethods:()=>g});module.exports=D(S);var A=require("@magic-sdk/commons");var g=(e=>(e.Start="magic_oauth_login_with_redirect_start",e.Verify="magic_oauth_login_with_redirect_verify",e))(g||{}),_=(a=>(a.InvalidRequest="invalid_request",a.InvalidClient="invalid_client",a.InvalidScope="invalid_scope",a.InvalidGrant="invalid_grant",a.UnauthorizedClient="unauthorized_client",a.UnsupportedResponseType="unsupported_response_type",a.UnsupportedGrantType="unsupported_grant_type",a.UnsupportedTokenType="unsupported_token_type",a.AccessDenied="access_denied",a.ServerError="server_error",a.TemporarilyUnavailable="temporarily_unavailable",a))(_||{});var h=class extends A.Extension.Internal{constructor(){super(...arguments);this.name="oauth2";this.config={};this.compat={"magic-sdk":">=2.4.6","@magic-sdk/react-native":!1,"@magic-sdk/react-native-bare":!1,"@magic-sdk/react-native-expo":!1}}loginWithRedirect(e){return this.utils.createPromiEvent((s,i)=>l(this,null,function*(){var u;let d=this.utils.createJsonRpcRequestPayload("magic_oauth_login_with_redirect_start",[y(v({},e),{apiKey:this.sdk.apiKey,platform:"web"})]),c=yield this.request(d),n=c,o=c;o.error&&i(this.createError(o.error,(u=o.error_description)!=null?u:"An error occurred.",{errorURI:o.error_uri,provider:o.provider})),n!=null&&n.oauthAuthoriationURI&&(window.location.href=n.useMagicServerCallback?new URL(n.oauthAuthoriationURI,this.sdk.endpoint).href:n.oauthAuthoriationURI),s()}))}getRedirectResult(){let e=window.location.search,s=window.location.origin+window.location.pathname;return window.history.replaceState(null,"",s),P.call(this,e)}};function P(t){return this.utils.createPromiEvent((r,e)=>l(this,null,function*(){var n;let s=this.utils.createJsonRpcRequestPayload("magic_oauth_login_with_redirect_verify",[{authorizationResponseParams:t,magicApiKey:this.sdk.apiKey,platform:"web"}]),i=yield this.request(s),d=i,c=i;c.error&&e(this.createError(c.error,(n=c.error_description)!=null?n:"An error occurred.",{errorURI:c.error_uri,provider:c.provider})),r(d)}))}
1
+ "use strict";var p=Object.defineProperty,A=Object.defineProperties,I=Object.getOwnPropertyDescriptor,O=Object.getOwnPropertyDescriptors,w=Object.getOwnPropertyNames,R=Object.getOwnPropertySymbols;var f=Object.prototype.hasOwnProperty,U=Object.prototype.propertyIsEnumerable;var m=(t,r,e)=>r in t?p(t,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[r]=e,v=(t,r)=>{for(var e in r||(r={}))f.call(r,e)&&m(t,e,r[e]);if(R)for(var e of R(r))U.call(r,e)&&m(t,e,r[e]);return t},y=(t,r)=>A(t,O(r));var x=(t,r)=>{for(var e in r)p(t,e,{get:r[e],enumerable:!0})},k=(t,r,e,s)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of w(r))!f.call(t,o)&&o!==e&&p(t,o,{get:()=>r[o],enumerable:!(s=I(r,o))||s.enumerable});return t};var D=t=>k(p({},"__esModule",{value:!0}),t);var l=(t,r,e)=>new Promise((s,o)=>{var c=n=>{try{i(e.next(n))}catch(d){o(d)}},u=n=>{try{i(e.throw(n))}catch(d){o(d)}},i=n=>n.done?s(n.value):Promise.resolve(n.value).then(c,u);i((e=e.apply(t,r)).next())});var S={};x(S,{OAuthErrorCode:()=>_,OAuthExtension:()=>h,OAuthPayloadMethods:()=>g});module.exports=D(S);var b=require("@magic-sdk/commons");var g=(e=>(e.Start="magic_oauth_login_with_redirect_start",e.Verify="magic_oauth_login_with_redirect_verify",e))(g||{}),_=(a=>(a.InvalidRequest="invalid_request",a.InvalidClient="invalid_client",a.InvalidScope="invalid_scope",a.InvalidGrant="invalid_grant",a.UnauthorizedClient="unauthorized_client",a.UnsupportedResponseType="unsupported_response_type",a.UnsupportedGrantType="unsupported_grant_type",a.UnsupportedTokenType="unsupported_token_type",a.AccessDenied="access_denied",a.ServerError="server_error",a.TemporarilyUnavailable="temporarily_unavailable",a))(_||{});var h=class extends b.Extension.Internal{constructor(){super(...arguments);this.name="oauth2";this.config={};this.compat={"magic-sdk":">=2.4.6","@magic-sdk/react-native":!1,"@magic-sdk/react-native-bare":!1,"@magic-sdk/react-native-expo":!1}}loginWithRedirect(e){return this.utils.createPromiEvent((s,o)=>l(this,null,function*(){var d;let c=this.utils.createJsonRpcRequestPayload("magic_oauth_login_with_redirect_start",[y(v({},e),{apiKey:this.sdk.apiKey,platform:"web"})]),u=yield this.request(c),i=u,n=u;n.error&&o(this.createError(n.error,(d=n.error_description)!=null?d:"An error occurred.",{errorURI:n.error_uri,provider:n.provider})),i!=null&&i.oauthAuthoriationURI&&(window.location.href=i.useMagicServerCallback?new URL(i.oauthAuthoriationURI,this.sdk.endpoint).href:i.oauthAuthoriationURI),s()}))}getRedirectResult(e){let s=window.location.search,o=window.location.origin+window.location.pathname;return window.history.replaceState(null,"",o),P.call(this,s,e)}};function P(t,r){return this.utils.createPromiEvent((e,s)=>l(this,null,function*(){var n;let o=this.utils.createJsonRpcRequestPayload("magic_oauth_login_with_redirect_verify",[{authorizationResponseParams:t,magicApiKey:this.sdk.apiKey,platform:"web",lifespan:r}]),c=yield this.request(o),u=c,i=c;i.error&&s(this.createError(i.error,(n=i.error_description)!=null?n:"An error occurred.",{errorURI:i.error_uri,provider:i.provider})),e(u)}))}
2
2
  //# sourceMappingURL=index.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/index.ts", "../../src/types.ts"],
4
- "sourcesContent": ["/* eslint-disable @typescript-eslint/ban-ts-comment */\n\nimport { Extension } from '@magic-sdk/commons';\nimport {\n OAuthErrorData,\n OAuthRedirectError,\n OAuthRedirectResult,\n OAuthRedirectConfiguration,\n OAuthPayloadMethods,\n OAuthRedirectStartResult,\n} from './types';\n\nexport class OAuthExtension extends Extension.Internal<'oauth2'> {\n name = 'oauth2' as const;\n config = {};\n compat = {\n 'magic-sdk': '>=2.4.6',\n '@magic-sdk/react-native': false,\n '@magic-sdk/react-native-bare': false,\n '@magic-sdk/react-native-expo': false,\n };\n\n public loginWithRedirect(configuration: OAuthRedirectConfiguration) {\n return this.utils.createPromiEvent<void>(async (resolve, reject) => {\n const parseRedirectResult = this.utils.createJsonRpcRequestPayload(OAuthPayloadMethods.Start, [\n {\n ...configuration,\n apiKey: this.sdk.apiKey,\n platform: 'web',\n },\n ]);\n\n const result = await this.request<OAuthRedirectStartResult | OAuthRedirectError>(parseRedirectResult);\n const successResult = result as OAuthRedirectStartResult;\n const errorResult = result as OAuthRedirectError;\n\n if (errorResult.error) {\n reject(\n this.createError<OAuthErrorData>(errorResult.error, errorResult.error_description ?? 'An error occurred.', {\n errorURI: errorResult.error_uri,\n provider: errorResult.provider,\n }),\n );\n }\n\n if (successResult?.oauthAuthoriationURI) {\n window.location.href = successResult.useMagicServerCallback\n ? // @ts-ignore - this.sdk.endpoint is marked protected but we need to access it.\n new URL(successResult.oauthAuthoriationURI, this.sdk.endpoint).href\n : successResult.oauthAuthoriationURI;\n }\n\n resolve();\n });\n }\n\n public getRedirectResult() {\n const queryString = window.location.search;\n\n // Remove the query from the redirect callback as a precaution to prevent\n // malicious parties from parsing it before we have a chance to use it.\n const urlWithoutQuery = window.location.origin + window.location.pathname;\n window.history.replaceState(null, '', urlWithoutQuery);\n\n return getResult.call(this, queryString);\n }\n}\n\nfunction getResult(this: OAuthExtension, queryString: string) {\n return this.utils.createPromiEvent<OAuthRedirectResult>(async (resolve, reject) => {\n const parseRedirectResult = this.utils.createJsonRpcRequestPayload(OAuthPayloadMethods.Verify, [\n {\n authorizationResponseParams: queryString,\n magicApiKey: this.sdk.apiKey,\n platform: 'web',\n },\n ]);\n\n // Parse the result, which may contain an OAuth-formatted error.\n const resultOrError = await this.request<OAuthRedirectResult | OAuthRedirectError>(parseRedirectResult);\n const maybeResult = resultOrError as OAuthRedirectResult;\n const maybeError = resultOrError as OAuthRedirectError;\n\n if (maybeError.error) {\n reject(\n this.createError<OAuthErrorData>(maybeError.error, maybeError.error_description ?? 'An error occurred.', {\n errorURI: maybeError.error_uri,\n provider: maybeError.provider,\n }),\n );\n }\n\n resolve(maybeResult);\n });\n}\n\nexport * from './types';\n", "import { MagicUserMetadata } from '@magic-sdk/types';\n\nexport enum OAuthPayloadMethods {\n Start = 'magic_oauth_login_with_redirect_start',\n Verify = 'magic_oauth_login_with_redirect_verify',\n}\n\nexport type OAuthProvider =\n | 'google'\n | 'facebook'\n | 'apple'\n | 'github'\n | 'bitbucket'\n | 'gitlab'\n | 'linkedin'\n | 'twitter'\n | 'discord'\n | 'twitch'\n | 'microsoft';\n\nexport interface OAuthErrorData {\n provider: OAuthProvider;\n errorURI?: string;\n}\n\nexport interface OpenIDConnectProfile {\n name?: string;\n familyName?: string;\n givenName?: string;\n middleName?: string;\n nickname?: string;\n preferredUsername?: string;\n profile?: string;\n picture?: string;\n website?: string;\n gender?: string;\n birthdate?: string;\n zoneinfo?: string;\n locale?: string;\n updatedAt?: number;\n}\n\nexport interface OpenIDConnectEmail {\n email?: string;\n emailVerified?: boolean;\n}\n\nexport interface OpenIDConnectPhone {\n phoneNumber?: string;\n phoneNumberVerified?: boolean;\n}\n\nexport interface OpenIDConnectAddress {\n address?: {\n formatted?: string;\n streetAddress?: string;\n locality?: string;\n region?: string;\n postalCode?: string;\n country?: string;\n };\n}\n\nexport type OpenIDConnectUserInfo = OpenIDConnectProfile &\n OpenIDConnectEmail &\n OpenIDConnectPhone &\n OpenIDConnectAddress & { sub?: string; sources?: Record<string, any> } & Record<string, any>;\n\nexport interface OAuthRedirectStartResult {\n oauthAuthoriationURI?: string;\n useMagicServerCallback?: boolean;\n}\n\nexport interface OAuthRedirectResult {\n oauth: {\n provider: OAuthProvider;\n scope: string[];\n userHandle: string;\n userInfo: OpenIDConnectUserInfo;\n };\n magic: {\n idToken: string;\n userMetadata: MagicUserMetadata;\n };\n}\n\nexport interface OAuthRedirectError {\n provider: OAuthProvider;\n error: string;\n error_description?: string;\n error_uri?: string;\n}\n\nexport interface OAuthRedirectConfiguration {\n provider: OAuthProvider;\n redirectURI: string;\n scope?: string[];\n loginHint?: string;\n}\n\nexport enum OAuthErrorCode {\n InvalidRequest = 'invalid_request',\n InvalidClient = 'invalid_client',\n InvalidScope = 'invalid_scope',\n InvalidGrant = 'invalid_grant',\n UnauthorizedClient = 'unauthorized_client',\n UnsupportedResponseType = 'unsupported_response_type',\n UnsupportedGrantType = 'unsupported_grant_type',\n UnsupportedTokenType = 'unsupported_token_type',\n AccessDenied = 'access_denied',\n ServerError = 'server_error',\n TemporarilyUnavailable = 'temporarily_unavailable',\n}\n"],
5
- "mappings": "i9BAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,oBAAAE,E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,OAAS,OAAO,SAAS,SACjE,cAAO,QAAQ,aAAa,KAAM,GAAIA,CAAe,EAE9CC,EAAU,KAAK,KAAMF,CAAW,CACzC,CACF,EAEA,SAASE,EAAgCF,EAAqB,CAC5D,OAAO,KAAK,MAAM,iBAAsC,CAAOV,EAASC,IAAWC,EAAA,sBArErF,IAAAC,EAsEI,IAAMC,EAAsB,KAAK,MAAM,qEAAwD,CAC7F,CACE,4BAA6BM,EAC7B,YAAa,KAAK,IAAI,OACtB,SAAU,KACZ,CACF,CAAC,EAGKG,EAAgB,MAAM,KAAK,QAAkDT,CAAmB,EAChGU,EAAcD,EACdE,EAAaF,EAEfE,EAAW,OACbd,EACE,KAAK,YAA4Bc,EAAW,OAAOZ,EAAAY,EAAW,oBAAX,KAAAZ,EAAgC,qBAAsB,CACvG,SAAUY,EAAW,UACrB,SAAUA,EAAW,QACvB,CAAC,CACH,EAGFf,EAAQc,CAAW,CACrB,EAAC,CACH",
6
- "names": ["src_exports", "__export", "OAuthErrorCode", "OAuthExtension", "OAuthPayloadMethods", "__toCommonJS", "import_commons", "OAuthPayloadMethods", "OAuthErrorCode", "OAuthExtension", "configuration", "resolve", "reject", "__async", "_a", "parseRedirectResult", "__spreadProps", "__spreadValues", "result", "successResult", "errorResult", "queryString", "urlWithoutQuery", "getResult", "resultOrError", "maybeResult", "maybeError"]
4
+ "sourcesContent": ["/* eslint-disable @typescript-eslint/ban-ts-comment */\n\nimport { Extension } from '@magic-sdk/commons';\nimport {\n OAuthErrorData,\n OAuthRedirectError,\n OAuthRedirectResult,\n OAuthRedirectConfiguration,\n OAuthPayloadMethods,\n OAuthRedirectStartResult,\n} from './types';\n\nexport class OAuthExtension extends Extension.Internal<'oauth2'> {\n name = 'oauth2' as const;\n config = {};\n compat = {\n 'magic-sdk': '>=2.4.6',\n '@magic-sdk/react-native': false,\n '@magic-sdk/react-native-bare': false,\n '@magic-sdk/react-native-expo': false,\n };\n\n public loginWithRedirect(configuration: OAuthRedirectConfiguration) {\n return this.utils.createPromiEvent<void>(async (resolve, reject) => {\n const parseRedirectResult = this.utils.createJsonRpcRequestPayload(OAuthPayloadMethods.Start, [\n {\n ...configuration,\n apiKey: this.sdk.apiKey,\n platform: 'web',\n },\n ]);\n\n const result = await this.request<OAuthRedirectStartResult | OAuthRedirectError>(parseRedirectResult);\n const successResult = result as OAuthRedirectStartResult;\n const errorResult = result as OAuthRedirectError;\n\n if (errorResult.error) {\n reject(\n this.createError<OAuthErrorData>(errorResult.error, errorResult.error_description ?? 'An error occurred.', {\n errorURI: errorResult.error_uri,\n provider: errorResult.provider,\n }),\n );\n }\n\n if (successResult?.oauthAuthoriationURI) {\n window.location.href = successResult.useMagicServerCallback\n ? // @ts-ignore - this.sdk.endpoint is marked protected but we need to access it.\n new URL(successResult.oauthAuthoriationURI, this.sdk.endpoint).href\n : successResult.oauthAuthoriationURI;\n }\n\n resolve();\n });\n }\n\n public getRedirectResult(lifespan?: number) {\n const queryString = window.location.search;\n\n // Remove the query from the redirect callback as a precaution to prevent\n // malicious parties from parsing it before we have a chance to use it.\n const urlWithoutQuery = window.location.origin + window.location.pathname;\n window.history.replaceState(null, '', urlWithoutQuery);\n\n return getResult.call(this, queryString, lifespan);\n }\n}\n\nfunction getResult(this: OAuthExtension, queryString: string, lifespan?: number) {\n return this.utils.createPromiEvent<OAuthRedirectResult>(async (resolve, reject) => {\n const parseRedirectResult = this.utils.createJsonRpcRequestPayload(OAuthPayloadMethods.Verify, [\n {\n authorizationResponseParams: queryString,\n magicApiKey: this.sdk.apiKey,\n platform: 'web',\n lifespan,\n },\n ]);\n\n // Parse the result, which may contain an OAuth-formatted error.\n const resultOrError = await this.request<OAuthRedirectResult | OAuthRedirectError>(parseRedirectResult);\n const maybeResult = resultOrError as OAuthRedirectResult;\n const maybeError = resultOrError as OAuthRedirectError;\n\n if (maybeError.error) {\n reject(\n this.createError<OAuthErrorData>(maybeError.error, maybeError.error_description ?? 'An error occurred.', {\n errorURI: maybeError.error_uri,\n provider: maybeError.provider,\n }),\n );\n }\n\n resolve(maybeResult);\n });\n}\n\nexport * from './types';\n", "import { MagicUserMetadata } from '@magic-sdk/types';\n\nexport enum OAuthPayloadMethods {\n Start = 'magic_oauth_login_with_redirect_start',\n Verify = 'magic_oauth_login_with_redirect_verify',\n}\n\nexport type OAuthProvider =\n | 'google'\n | 'facebook'\n | 'apple'\n | 'github'\n | 'bitbucket'\n | 'gitlab'\n | 'linkedin'\n | 'twitter'\n | 'discord'\n | 'twitch'\n | 'microsoft';\n\nexport interface OAuthErrorData {\n provider: OAuthProvider;\n errorURI?: string;\n}\n\nexport interface OpenIDConnectProfile {\n name?: string;\n familyName?: string;\n givenName?: string;\n middleName?: string;\n nickname?: string;\n preferredUsername?: string;\n profile?: string;\n picture?: string;\n website?: string;\n gender?: string;\n birthdate?: string;\n zoneinfo?: string;\n locale?: string;\n updatedAt?: number;\n}\n\nexport interface OpenIDConnectEmail {\n email?: string;\n emailVerified?: boolean;\n}\n\nexport interface OpenIDConnectPhone {\n phoneNumber?: string;\n phoneNumberVerified?: boolean;\n}\n\nexport interface OpenIDConnectAddress {\n address?: {\n formatted?: string;\n streetAddress?: string;\n locality?: string;\n region?: string;\n postalCode?: string;\n country?: string;\n };\n}\n\nexport type OpenIDConnectUserInfo = OpenIDConnectProfile &\n OpenIDConnectEmail &\n OpenIDConnectPhone &\n OpenIDConnectAddress & { sub?: string; sources?: Record<string, any> } & Record<string, any>;\n\nexport interface OAuthRedirectStartResult {\n oauthAuthoriationURI?: string;\n useMagicServerCallback?: boolean;\n}\n\nexport interface OAuthRedirectResult {\n oauth: {\n provider: OAuthProvider;\n scope: string[];\n userHandle: string;\n userInfo: OpenIDConnectUserInfo;\n };\n magic: {\n idToken: string;\n userMetadata: MagicUserMetadata;\n };\n}\n\nexport interface OAuthRedirectError {\n provider: OAuthProvider;\n error: string;\n error_description?: string;\n error_uri?: string;\n}\n\nexport interface OAuthRedirectConfiguration {\n provider: OAuthProvider;\n redirectURI: string;\n scope?: string[];\n loginHint?: string;\n}\n\nexport enum OAuthErrorCode {\n InvalidRequest = 'invalid_request',\n InvalidClient = 'invalid_client',\n InvalidScope = 'invalid_scope',\n InvalidGrant = 'invalid_grant',\n UnauthorizedClient = 'unauthorized_client',\n UnsupportedResponseType = 'unsupported_response_type',\n UnsupportedGrantType = 'unsupported_grant_type',\n UnsupportedTokenType = 'unsupported_token_type',\n AccessDenied = 'access_denied',\n ServerError = 'server_error',\n TemporarilyUnavailable = 'temporarily_unavailable',\n}\n"],
5
+ "mappings": "i9BAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,oBAAAE,EAAA,mBAAAC,EAAA,wBAAAC,IAAA,eAAAC,EAAAL,GAEA,IAAAM,EAA0B,8BCAnB,IAAKC,OACVA,EAAA,MAAQ,wCACRA,EAAA,OAAS,yCAFCA,OAAA,IAkGAC,OACVA,EAAA,eAAiB,kBACjBA,EAAA,cAAgB,iBAChBA,EAAA,aAAe,gBACfA,EAAA,aAAe,gBACfA,EAAA,mBAAqB,sBACrBA,EAAA,wBAA0B,4BAC1BA,EAAA,qBAAuB,yBACvBA,EAAA,qBAAuB,yBACvBA,EAAA,aAAe,gBACfA,EAAA,YAAc,eACdA,EAAA,uBAAyB,0BAXfA,OAAA,IDxFL,IAAMC,EAAN,cAA6B,YAAU,QAAmB,CAA1D,kCACL,UAAO,SACP,YAAS,CAAC,EACV,YAAS,CACP,YAAa,UACb,0BAA2B,GAC3B,+BAAgC,GAChC,+BAAgC,EAClC,EAEO,kBAAkBC,EAA2C,CAClE,OAAO,KAAK,MAAM,iBAAuB,CAAOC,EAASC,IAAWC,EAAA,sBAvBxE,IAAAC,EAwBM,IAAMC,EAAsB,KAAK,MAAM,oEAAuD,CAC5FC,EAAAC,EAAA,GACKP,GADL,CAEE,OAAQ,KAAK,IAAI,OACjB,SAAU,KACZ,EACF,CAAC,EAEKQ,EAAS,MAAM,KAAK,QAAuDH,CAAmB,EAC9FI,EAAgBD,EAChBE,EAAcF,EAEhBE,EAAY,OACdR,EACE,KAAK,YAA4BQ,EAAY,OAAON,EAAAM,EAAY,oBAAZ,KAAAN,EAAiC,qBAAsB,CACzG,SAAUM,EAAY,UACtB,SAAUA,EAAY,QACxB,CAAC,CACH,EAGED,GAAA,MAAAA,EAAe,uBACjB,OAAO,SAAS,KAAOA,EAAc,uBAEjC,IAAI,IAAIA,EAAc,qBAAsB,KAAK,IAAI,QAAQ,EAAE,KAC/DA,EAAc,sBAGpBR,EAAQ,CACV,EAAC,CACH,CAEO,kBAAkBU,EAAmB,CAC1C,IAAMC,EAAc,OAAO,SAAS,OAI9BC,EAAkB,OAAO,SAAS,OAAS,OAAO,SAAS,SACjE,cAAO,QAAQ,aAAa,KAAM,GAAIA,CAAe,EAE9CC,EAAU,KAAK,KAAMF,EAAaD,CAAQ,CACnD,CACF,EAEA,SAASG,EAAgCF,EAAqBD,EAAmB,CAC/E,OAAO,KAAK,MAAM,iBAAsC,CAAOV,EAASC,IAAWC,EAAA,sBArErF,IAAAC,EAsEI,IAAMC,EAAsB,KAAK,MAAM,qEAAwD,CAC7F,CACE,4BAA6BO,EAC7B,YAAa,KAAK,IAAI,OACtB,SAAU,MACV,SAAAD,CACF,CACF,CAAC,EAGKI,EAAgB,MAAM,KAAK,QAAkDV,CAAmB,EAChGW,EAAcD,EACdE,EAAaF,EAEfE,EAAW,OACbf,EACE,KAAK,YAA4Be,EAAW,OAAOb,EAAAa,EAAW,oBAAX,KAAAb,EAAgC,qBAAsB,CACvG,SAAUa,EAAW,UACrB,SAAUA,EAAW,QACvB,CAAC,CACH,EAGFhB,EAAQe,CAAW,CACrB,EAAC,CACH",
6
+ "names": ["src_exports", "__export", "OAuthErrorCode", "OAuthExtension", "OAuthPayloadMethods", "__toCommonJS", "import_commons", "OAuthPayloadMethods", "OAuthErrorCode", "OAuthExtension", "configuration", "resolve", "reject", "__async", "_a", "parseRedirectResult", "__spreadProps", "__spreadValues", "result", "successResult", "errorResult", "lifespan", "queryString", "urlWithoutQuery", "getResult", "resultOrError", "maybeResult", "maybeError"]
7
7
  }
package/dist/es/index.js CHANGED
@@ -1,2 +1,2 @@
1
- var v=Object.defineProperty,y=Object.defineProperties;var _=Object.getOwnPropertyDescriptors;var l=Object.getOwnPropertySymbols;var A=Object.prototype.hasOwnProperty,I=Object.prototype.propertyIsEnumerable;var g=(t,r,e)=>r in t?v(t,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[r]=e,h=(t,r)=>{for(var e in r||(r={}))A.call(r,e)&&g(t,e,r[e]);if(l)for(var e of l(r))I.call(r,e)&&g(t,e,r[e]);return t},R=(t,r)=>y(t,_(r));var p=(t,r,e)=>new Promise((s,c)=>{var d=n=>{try{i(e.next(n))}catch(u){c(u)}},a=n=>{try{i(e.throw(n))}catch(u){c(u)}},i=n=>n.done?s(n.value):Promise.resolve(n.value).then(d,a);i((e=e.apply(t,r)).next())});import{Extension as b}from"@magic-sdk/commons";var m=(e=>(e.Start="magic_oauth_login_with_redirect_start",e.Verify="magic_oauth_login_with_redirect_verify",e))(m||{}),O=(o=>(o.InvalidRequest="invalid_request",o.InvalidClient="invalid_client",o.InvalidScope="invalid_scope",o.InvalidGrant="invalid_grant",o.UnauthorizedClient="unauthorized_client",o.UnsupportedResponseType="unsupported_response_type",o.UnsupportedGrantType="unsupported_grant_type",o.UnsupportedTokenType="unsupported_token_type",o.AccessDenied="access_denied",o.ServerError="server_error",o.TemporarilyUnavailable="temporarily_unavailable",o))(O||{});var f=class extends b.Internal{constructor(){super(...arguments);this.name="oauth2";this.config={};this.compat={"magic-sdk":">=2.4.6","@magic-sdk/react-native":!1,"@magic-sdk/react-native-bare":!1,"@magic-sdk/react-native-expo":!1}}loginWithRedirect(e){return this.utils.createPromiEvent((s,c)=>p(this,null,function*(){var u;let d=this.utils.createJsonRpcRequestPayload("magic_oauth_login_with_redirect_start",[R(h({},e),{apiKey:this.sdk.apiKey,platform:"web"})]),a=yield this.request(d),i=a,n=a;n.error&&c(this.createError(n.error,(u=n.error_description)!=null?u:"An error occurred.",{errorURI:n.error_uri,provider:n.provider})),i!=null&&i.oauthAuthoriationURI&&(window.location.href=i.useMagicServerCallback?new URL(i.oauthAuthoriationURI,this.sdk.endpoint).href:i.oauthAuthoriationURI),s()}))}getRedirectResult(){let e=window.location.search,s=window.location.origin+window.location.pathname;return window.history.replaceState(null,"",s),w.call(this,e)}};function w(t){return this.utils.createPromiEvent((r,e)=>p(this,null,function*(){var i;let s=this.utils.createJsonRpcRequestPayload("magic_oauth_login_with_redirect_verify",[{authorizationResponseParams:t,magicApiKey:this.sdk.apiKey,platform:"web"}]),c=yield this.request(s),d=c,a=c;a.error&&e(this.createError(a.error,(i=a.error_description)!=null?i:"An error occurred.",{errorURI:a.error_uri,provider:a.provider})),r(d)}))}export{O as OAuthErrorCode,f as OAuthExtension,m as OAuthPayloadMethods};
1
+ var v=Object.defineProperty,y=Object.defineProperties;var _=Object.getOwnPropertyDescriptors;var l=Object.getOwnPropertySymbols;var b=Object.prototype.hasOwnProperty,A=Object.prototype.propertyIsEnumerable;var g=(n,r,e)=>r in n?v(n,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[r]=e,h=(n,r)=>{for(var e in r||(r={}))b.call(r,e)&&g(n,e,r[e]);if(l)for(var e of l(r))A.call(r,e)&&g(n,e,r[e]);return n},R=(n,r)=>y(n,_(r));var p=(n,r,e)=>new Promise((s,a)=>{var c=i=>{try{t(e.next(i))}catch(d){a(d)}},u=i=>{try{t(e.throw(i))}catch(d){a(d)}},t=i=>i.done?s(i.value):Promise.resolve(i.value).then(c,u);t((e=e.apply(n,r)).next())});import{Extension as O}from"@magic-sdk/commons";var m=(e=>(e.Start="magic_oauth_login_with_redirect_start",e.Verify="magic_oauth_login_with_redirect_verify",e))(m||{}),I=(o=>(o.InvalidRequest="invalid_request",o.InvalidClient="invalid_client",o.InvalidScope="invalid_scope",o.InvalidGrant="invalid_grant",o.UnauthorizedClient="unauthorized_client",o.UnsupportedResponseType="unsupported_response_type",o.UnsupportedGrantType="unsupported_grant_type",o.UnsupportedTokenType="unsupported_token_type",o.AccessDenied="access_denied",o.ServerError="server_error",o.TemporarilyUnavailable="temporarily_unavailable",o))(I||{});var f=class extends O.Internal{constructor(){super(...arguments);this.name="oauth2";this.config={};this.compat={"magic-sdk":">=2.4.6","@magic-sdk/react-native":!1,"@magic-sdk/react-native-bare":!1,"@magic-sdk/react-native-expo":!1}}loginWithRedirect(e){return this.utils.createPromiEvent((s,a)=>p(this,null,function*(){var d;let c=this.utils.createJsonRpcRequestPayload("magic_oauth_login_with_redirect_start",[R(h({},e),{apiKey:this.sdk.apiKey,platform:"web"})]),u=yield this.request(c),t=u,i=u;i.error&&a(this.createError(i.error,(d=i.error_description)!=null?d:"An error occurred.",{errorURI:i.error_uri,provider:i.provider})),t!=null&&t.oauthAuthoriationURI&&(window.location.href=t.useMagicServerCallback?new URL(t.oauthAuthoriationURI,this.sdk.endpoint).href:t.oauthAuthoriationURI),s()}))}getRedirectResult(e){let s=window.location.search,a=window.location.origin+window.location.pathname;return window.history.replaceState(null,"",a),w.call(this,s,e)}};function w(n,r){return this.utils.createPromiEvent((e,s)=>p(this,null,function*(){var i;let a=this.utils.createJsonRpcRequestPayload("magic_oauth_login_with_redirect_verify",[{authorizationResponseParams:n,magicApiKey:this.sdk.apiKey,platform:"web",lifespan:r}]),c=yield this.request(a),u=c,t=c;t.error&&s(this.createError(t.error,(i=t.error_description)!=null?i:"An error occurred.",{errorURI:t.error_uri,provider:t.provider})),e(u)}))}export{I as OAuthErrorCode,f as OAuthExtension,m as OAuthPayloadMethods};
2
2
  //# sourceMappingURL=index.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/index.ts", "../../src/types.ts"],
4
- "sourcesContent": ["/* eslint-disable @typescript-eslint/ban-ts-comment */\n\nimport { Extension } from '@magic-sdk/commons';\nimport {\n OAuthErrorData,\n OAuthRedirectError,\n OAuthRedirectResult,\n OAuthRedirectConfiguration,\n OAuthPayloadMethods,\n OAuthRedirectStartResult,\n} from './types';\n\nexport class OAuthExtension extends Extension.Internal<'oauth2'> {\n name = 'oauth2' as const;\n config = {};\n compat = {\n 'magic-sdk': '>=2.4.6',\n '@magic-sdk/react-native': false,\n '@magic-sdk/react-native-bare': false,\n '@magic-sdk/react-native-expo': false,\n };\n\n public loginWithRedirect(configuration: OAuthRedirectConfiguration) {\n return this.utils.createPromiEvent<void>(async (resolve, reject) => {\n const parseRedirectResult = this.utils.createJsonRpcRequestPayload(OAuthPayloadMethods.Start, [\n {\n ...configuration,\n apiKey: this.sdk.apiKey,\n platform: 'web',\n },\n ]);\n\n const result = await this.request<OAuthRedirectStartResult | OAuthRedirectError>(parseRedirectResult);\n const successResult = result as OAuthRedirectStartResult;\n const errorResult = result as OAuthRedirectError;\n\n if (errorResult.error) {\n reject(\n this.createError<OAuthErrorData>(errorResult.error, errorResult.error_description ?? 'An error occurred.', {\n errorURI: errorResult.error_uri,\n provider: errorResult.provider,\n }),\n );\n }\n\n if (successResult?.oauthAuthoriationURI) {\n window.location.href = successResult.useMagicServerCallback\n ? // @ts-ignore - this.sdk.endpoint is marked protected but we need to access it.\n new URL(successResult.oauthAuthoriationURI, this.sdk.endpoint).href\n : successResult.oauthAuthoriationURI;\n }\n\n resolve();\n });\n }\n\n public getRedirectResult() {\n const queryString = window.location.search;\n\n // Remove the query from the redirect callback as a precaution to prevent\n // malicious parties from parsing it before we have a chance to use it.\n const urlWithoutQuery = window.location.origin + window.location.pathname;\n window.history.replaceState(null, '', urlWithoutQuery);\n\n return getResult.call(this, queryString);\n }\n}\n\nfunction getResult(this: OAuthExtension, queryString: string) {\n return this.utils.createPromiEvent<OAuthRedirectResult>(async (resolve, reject) => {\n const parseRedirectResult = this.utils.createJsonRpcRequestPayload(OAuthPayloadMethods.Verify, [\n {\n authorizationResponseParams: queryString,\n magicApiKey: this.sdk.apiKey,\n platform: 'web',\n },\n ]);\n\n // Parse the result, which may contain an OAuth-formatted error.\n const resultOrError = await this.request<OAuthRedirectResult | OAuthRedirectError>(parseRedirectResult);\n const maybeResult = resultOrError as OAuthRedirectResult;\n const maybeError = resultOrError as OAuthRedirectError;\n\n if (maybeError.error) {\n reject(\n this.createError<OAuthErrorData>(maybeError.error, maybeError.error_description ?? 'An error occurred.', {\n errorURI: maybeError.error_uri,\n provider: maybeError.provider,\n }),\n );\n }\n\n resolve(maybeResult);\n });\n}\n\nexport * from './types';\n", "import { MagicUserMetadata } from '@magic-sdk/types';\n\nexport enum OAuthPayloadMethods {\n Start = 'magic_oauth_login_with_redirect_start',\n Verify = 'magic_oauth_login_with_redirect_verify',\n}\n\nexport type OAuthProvider =\n | 'google'\n | 'facebook'\n | 'apple'\n | 'github'\n | 'bitbucket'\n | 'gitlab'\n | 'linkedin'\n | 'twitter'\n | 'discord'\n | 'twitch'\n | 'microsoft';\n\nexport interface OAuthErrorData {\n provider: OAuthProvider;\n errorURI?: string;\n}\n\nexport interface OpenIDConnectProfile {\n name?: string;\n familyName?: string;\n givenName?: string;\n middleName?: string;\n nickname?: string;\n preferredUsername?: string;\n profile?: string;\n picture?: string;\n website?: string;\n gender?: string;\n birthdate?: string;\n zoneinfo?: string;\n locale?: string;\n updatedAt?: number;\n}\n\nexport interface OpenIDConnectEmail {\n email?: string;\n emailVerified?: boolean;\n}\n\nexport interface OpenIDConnectPhone {\n phoneNumber?: string;\n phoneNumberVerified?: boolean;\n}\n\nexport interface OpenIDConnectAddress {\n address?: {\n formatted?: string;\n streetAddress?: string;\n locality?: string;\n region?: string;\n postalCode?: string;\n country?: string;\n };\n}\n\nexport type OpenIDConnectUserInfo = OpenIDConnectProfile &\n OpenIDConnectEmail &\n OpenIDConnectPhone &\n OpenIDConnectAddress & { sub?: string; sources?: Record<string, any> } & Record<string, any>;\n\nexport interface OAuthRedirectStartResult {\n oauthAuthoriationURI?: string;\n useMagicServerCallback?: boolean;\n}\n\nexport interface OAuthRedirectResult {\n oauth: {\n provider: OAuthProvider;\n scope: string[];\n userHandle: string;\n userInfo: OpenIDConnectUserInfo;\n };\n magic: {\n idToken: string;\n userMetadata: MagicUserMetadata;\n };\n}\n\nexport interface OAuthRedirectError {\n provider: OAuthProvider;\n error: string;\n error_description?: string;\n error_uri?: string;\n}\n\nexport interface OAuthRedirectConfiguration {\n provider: OAuthProvider;\n redirectURI: string;\n scope?: string[];\n loginHint?: string;\n}\n\nexport enum OAuthErrorCode {\n InvalidRequest = 'invalid_request',\n InvalidClient = 'invalid_client',\n InvalidScope = 'invalid_scope',\n InvalidGrant = 'invalid_grant',\n UnauthorizedClient = 'unauthorized_client',\n UnsupportedResponseType = 'unsupported_response_type',\n UnsupportedGrantType = 'unsupported_grant_type',\n UnsupportedTokenType = 'unsupported_token_type',\n AccessDenied = 'access_denied',\n ServerError = 'server_error',\n TemporarilyUnavailable = 'temporarily_unavailable',\n}\n"],
5
- "mappings": "0nBAEA,OAAS,aAAAA,MAAiB,qBCAnB,IAAKC,OACVA,EAAA,MAAQ,wCACRA,EAAA,OAAS,yCAFCA,OAAA,IAkGAC,OACVA,EAAA,eAAiB,kBACjBA,EAAA,cAAgB,iBAChBA,EAAA,aAAe,gBACfA,EAAA,aAAe,gBACfA,EAAA,mBAAqB,sBACrBA,EAAA,wBAA0B,4BAC1BA,EAAA,qBAAuB,yBACvBA,EAAA,qBAAuB,yBACvBA,EAAA,aAAe,gBACfA,EAAA,YAAc,eACdA,EAAA,uBAAyB,0BAXfA,OAAA,IDxFL,IAAMC,EAAN,cAA6BC,EAAU,QAAmB,CAA1D,kCACL,UAAO,SACP,YAAS,CAAC,EACV,YAAS,CACP,YAAa,UACb,0BAA2B,GAC3B,+BAAgC,GAChC,+BAAgC,EAClC,EAEO,kBAAkBC,EAA2C,CAClE,OAAO,KAAK,MAAM,iBAAuB,CAAOC,EAASC,IAAWC,EAAA,sBAvBxE,IAAAC,EAwBM,IAAMC,EAAsB,KAAK,MAAM,oEAAuD,CAC5FC,EAAAC,EAAA,GACKP,GADL,CAEE,OAAQ,KAAK,IAAI,OACjB,SAAU,KACZ,EACF,CAAC,EAEKQ,EAAS,MAAM,KAAK,QAAuDH,CAAmB,EAC9FI,EAAgBD,EAChBE,EAAcF,EAEhBE,EAAY,OACdR,EACE,KAAK,YAA4BQ,EAAY,OAAON,EAAAM,EAAY,oBAAZ,KAAAN,EAAiC,qBAAsB,CACzG,SAAUM,EAAY,UACtB,SAAUA,EAAY,QACxB,CAAC,CACH,EAGED,GAAA,MAAAA,EAAe,uBACjB,OAAO,SAAS,KAAOA,EAAc,uBAEjC,IAAI,IAAIA,EAAc,qBAAsB,KAAK,IAAI,QAAQ,EAAE,KAC/DA,EAAc,sBAGpBR,EAAQ,CACV,EAAC,CACH,CAEO,mBAAoB,CACzB,IAAMU,EAAc,OAAO,SAAS,OAI9BC,EAAkB,OAAO,SAAS,OAAS,OAAO,SAAS,SACjE,cAAO,QAAQ,aAAa,KAAM,GAAIA,CAAe,EAE9CC,EAAU,KAAK,KAAMF,CAAW,CACzC,CACF,EAEA,SAASE,EAAgCF,EAAqB,CAC5D,OAAO,KAAK,MAAM,iBAAsC,CAAOV,EAASC,IAAWC,EAAA,sBArErF,IAAAC,EAsEI,IAAMC,EAAsB,KAAK,MAAM,qEAAwD,CAC7F,CACE,4BAA6BM,EAC7B,YAAa,KAAK,IAAI,OACtB,SAAU,KACZ,CACF,CAAC,EAGKG,EAAgB,MAAM,KAAK,QAAkDT,CAAmB,EAChGU,EAAcD,EACdE,EAAaF,EAEfE,EAAW,OACbd,EACE,KAAK,YAA4Bc,EAAW,OAAOZ,EAAAY,EAAW,oBAAX,KAAAZ,EAAgC,qBAAsB,CACvG,SAAUY,EAAW,UACrB,SAAUA,EAAW,QACvB,CAAC,CACH,EAGFf,EAAQc,CAAW,CACrB,EAAC,CACH",
6
- "names": ["Extension", "OAuthPayloadMethods", "OAuthErrorCode", "OAuthExtension", "Extension", "configuration", "resolve", "reject", "__async", "_a", "parseRedirectResult", "__spreadProps", "__spreadValues", "result", "successResult", "errorResult", "queryString", "urlWithoutQuery", "getResult", "resultOrError", "maybeResult", "maybeError"]
4
+ "sourcesContent": ["/* eslint-disable @typescript-eslint/ban-ts-comment */\n\nimport { Extension } from '@magic-sdk/commons';\nimport {\n OAuthErrorData,\n OAuthRedirectError,\n OAuthRedirectResult,\n OAuthRedirectConfiguration,\n OAuthPayloadMethods,\n OAuthRedirectStartResult,\n} from './types';\n\nexport class OAuthExtension extends Extension.Internal<'oauth2'> {\n name = 'oauth2' as const;\n config = {};\n compat = {\n 'magic-sdk': '>=2.4.6',\n '@magic-sdk/react-native': false,\n '@magic-sdk/react-native-bare': false,\n '@magic-sdk/react-native-expo': false,\n };\n\n public loginWithRedirect(configuration: OAuthRedirectConfiguration) {\n return this.utils.createPromiEvent<void>(async (resolve, reject) => {\n const parseRedirectResult = this.utils.createJsonRpcRequestPayload(OAuthPayloadMethods.Start, [\n {\n ...configuration,\n apiKey: this.sdk.apiKey,\n platform: 'web',\n },\n ]);\n\n const result = await this.request<OAuthRedirectStartResult | OAuthRedirectError>(parseRedirectResult);\n const successResult = result as OAuthRedirectStartResult;\n const errorResult = result as OAuthRedirectError;\n\n if (errorResult.error) {\n reject(\n this.createError<OAuthErrorData>(errorResult.error, errorResult.error_description ?? 'An error occurred.', {\n errorURI: errorResult.error_uri,\n provider: errorResult.provider,\n }),\n );\n }\n\n if (successResult?.oauthAuthoriationURI) {\n window.location.href = successResult.useMagicServerCallback\n ? // @ts-ignore - this.sdk.endpoint is marked protected but we need to access it.\n new URL(successResult.oauthAuthoriationURI, this.sdk.endpoint).href\n : successResult.oauthAuthoriationURI;\n }\n\n resolve();\n });\n }\n\n public getRedirectResult(lifespan?: number) {\n const queryString = window.location.search;\n\n // Remove the query from the redirect callback as a precaution to prevent\n // malicious parties from parsing it before we have a chance to use it.\n const urlWithoutQuery = window.location.origin + window.location.pathname;\n window.history.replaceState(null, '', urlWithoutQuery);\n\n return getResult.call(this, queryString, lifespan);\n }\n}\n\nfunction getResult(this: OAuthExtension, queryString: string, lifespan?: number) {\n return this.utils.createPromiEvent<OAuthRedirectResult>(async (resolve, reject) => {\n const parseRedirectResult = this.utils.createJsonRpcRequestPayload(OAuthPayloadMethods.Verify, [\n {\n authorizationResponseParams: queryString,\n magicApiKey: this.sdk.apiKey,\n platform: 'web',\n lifespan,\n },\n ]);\n\n // Parse the result, which may contain an OAuth-formatted error.\n const resultOrError = await this.request<OAuthRedirectResult | OAuthRedirectError>(parseRedirectResult);\n const maybeResult = resultOrError as OAuthRedirectResult;\n const maybeError = resultOrError as OAuthRedirectError;\n\n if (maybeError.error) {\n reject(\n this.createError<OAuthErrorData>(maybeError.error, maybeError.error_description ?? 'An error occurred.', {\n errorURI: maybeError.error_uri,\n provider: maybeError.provider,\n }),\n );\n }\n\n resolve(maybeResult);\n });\n}\n\nexport * from './types';\n", "import { MagicUserMetadata } from '@magic-sdk/types';\n\nexport enum OAuthPayloadMethods {\n Start = 'magic_oauth_login_with_redirect_start',\n Verify = 'magic_oauth_login_with_redirect_verify',\n}\n\nexport type OAuthProvider =\n | 'google'\n | 'facebook'\n | 'apple'\n | 'github'\n | 'bitbucket'\n | 'gitlab'\n | 'linkedin'\n | 'twitter'\n | 'discord'\n | 'twitch'\n | 'microsoft';\n\nexport interface OAuthErrorData {\n provider: OAuthProvider;\n errorURI?: string;\n}\n\nexport interface OpenIDConnectProfile {\n name?: string;\n familyName?: string;\n givenName?: string;\n middleName?: string;\n nickname?: string;\n preferredUsername?: string;\n profile?: string;\n picture?: string;\n website?: string;\n gender?: string;\n birthdate?: string;\n zoneinfo?: string;\n locale?: string;\n updatedAt?: number;\n}\n\nexport interface OpenIDConnectEmail {\n email?: string;\n emailVerified?: boolean;\n}\n\nexport interface OpenIDConnectPhone {\n phoneNumber?: string;\n phoneNumberVerified?: boolean;\n}\n\nexport interface OpenIDConnectAddress {\n address?: {\n formatted?: string;\n streetAddress?: string;\n locality?: string;\n region?: string;\n postalCode?: string;\n country?: string;\n };\n}\n\nexport type OpenIDConnectUserInfo = OpenIDConnectProfile &\n OpenIDConnectEmail &\n OpenIDConnectPhone &\n OpenIDConnectAddress & { sub?: string; sources?: Record<string, any> } & Record<string, any>;\n\nexport interface OAuthRedirectStartResult {\n oauthAuthoriationURI?: string;\n useMagicServerCallback?: boolean;\n}\n\nexport interface OAuthRedirectResult {\n oauth: {\n provider: OAuthProvider;\n scope: string[];\n userHandle: string;\n userInfo: OpenIDConnectUserInfo;\n };\n magic: {\n idToken: string;\n userMetadata: MagicUserMetadata;\n };\n}\n\nexport interface OAuthRedirectError {\n provider: OAuthProvider;\n error: string;\n error_description?: string;\n error_uri?: string;\n}\n\nexport interface OAuthRedirectConfiguration {\n provider: OAuthProvider;\n redirectURI: string;\n scope?: string[];\n loginHint?: string;\n}\n\nexport enum OAuthErrorCode {\n InvalidRequest = 'invalid_request',\n InvalidClient = 'invalid_client',\n InvalidScope = 'invalid_scope',\n InvalidGrant = 'invalid_grant',\n UnauthorizedClient = 'unauthorized_client',\n UnsupportedResponseType = 'unsupported_response_type',\n UnsupportedGrantType = 'unsupported_grant_type',\n UnsupportedTokenType = 'unsupported_token_type',\n AccessDenied = 'access_denied',\n ServerError = 'server_error',\n TemporarilyUnavailable = 'temporarily_unavailable',\n}\n"],
5
+ "mappings": "0nBAEA,OAAS,aAAAA,MAAiB,qBCAnB,IAAKC,OACVA,EAAA,MAAQ,wCACRA,EAAA,OAAS,yCAFCA,OAAA,IAkGAC,OACVA,EAAA,eAAiB,kBACjBA,EAAA,cAAgB,iBAChBA,EAAA,aAAe,gBACfA,EAAA,aAAe,gBACfA,EAAA,mBAAqB,sBACrBA,EAAA,wBAA0B,4BAC1BA,EAAA,qBAAuB,yBACvBA,EAAA,qBAAuB,yBACvBA,EAAA,aAAe,gBACfA,EAAA,YAAc,eACdA,EAAA,uBAAyB,0BAXfA,OAAA,IDxFL,IAAMC,EAAN,cAA6BC,EAAU,QAAmB,CAA1D,kCACL,UAAO,SACP,YAAS,CAAC,EACV,YAAS,CACP,YAAa,UACb,0BAA2B,GAC3B,+BAAgC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gC,qBAAsB,CACvG,SAAUa,EAAW,UACrB,SAAUA,EAAW,QACvB,CAAC,CACH,EAGFhB,EAAQe,CAAW,CACrB,EAAC,CACH",
6
+ "names": ["Extension", "OAuthPayloadMethods", "OAuthErrorCode", "OAuthExtension", "Extension", "configuration", "resolve", "reject", "__async", "_a", "parseRedirectResult", "__spreadProps", "__spreadValues", "result", "successResult", "errorResult", "lifespan", "queryString", "urlWithoutQuery", "getResult", "resultOrError", "maybeResult", "maybeError"]
7
7
  }
package/dist/es/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
- var v=Object.defineProperty,y=Object.defineProperties;var _=Object.getOwnPropertyDescriptors;var l=Object.getOwnPropertySymbols;var A=Object.prototype.hasOwnProperty,I=Object.prototype.propertyIsEnumerable;var g=(t,r,e)=>r in t?v(t,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[r]=e,h=(t,r)=>{for(var e in r||(r={}))A.call(r,e)&&g(t,e,r[e]);if(l)for(var e of l(r))I.call(r,e)&&g(t,e,r[e]);return t},R=(t,r)=>y(t,_(r));var p=(t,r,e)=>new Promise((s,c)=>{var d=n=>{try{i(e.next(n))}catch(u){c(u)}},a=n=>{try{i(e.throw(n))}catch(u){c(u)}},i=n=>n.done?s(n.value):Promise.resolve(n.value).then(d,a);i((e=e.apply(t,r)).next())});import{Extension as b}from"@magic-sdk/commons";var m=(e=>(e.Start="magic_oauth_login_with_redirect_start",e.Verify="magic_oauth_login_with_redirect_verify",e))(m||{}),O=(o=>(o.InvalidRequest="invalid_request",o.InvalidClient="invalid_client",o.InvalidScope="invalid_scope",o.InvalidGrant="invalid_grant",o.UnauthorizedClient="unauthorized_client",o.UnsupportedResponseType="unsupported_response_type",o.UnsupportedGrantType="unsupported_grant_type",o.UnsupportedTokenType="unsupported_token_type",o.AccessDenied="access_denied",o.ServerError="server_error",o.TemporarilyUnavailable="temporarily_unavailable",o))(O||{});var f=class extends b.Internal{constructor(){super(...arguments);this.name="oauth2";this.config={};this.compat={"magic-sdk":">=2.4.6","@magic-sdk/react-native":!1,"@magic-sdk/react-native-bare":!1,"@magic-sdk/react-native-expo":!1}}loginWithRedirect(e){return this.utils.createPromiEvent((s,c)=>p(this,null,function*(){var u;let d=this.utils.createJsonRpcRequestPayload("magic_oauth_login_with_redirect_start",[R(h({},e),{apiKey:this.sdk.apiKey,platform:"web"})]),a=yield this.request(d),i=a,n=a;n.error&&c(this.createError(n.error,(u=n.error_description)!=null?u:"An error occurred.",{errorURI:n.error_uri,provider:n.provider})),i!=null&&i.oauthAuthoriationURI&&(window.location.href=i.useMagicServerCallback?new URL(i.oauthAuthoriationURI,this.sdk.endpoint).href:i.oauthAuthoriationURI),s()}))}getRedirectResult(){let e=window.location.search,s=window.location.origin+window.location.pathname;return window.history.replaceState(null,"",s),w.call(this,e)}};function w(t){return this.utils.createPromiEvent((r,e)=>p(this,null,function*(){var i;let s=this.utils.createJsonRpcRequestPayload("magic_oauth_login_with_redirect_verify",[{authorizationResponseParams:t,magicApiKey:this.sdk.apiKey,platform:"web"}]),c=yield this.request(s),d=c,a=c;a.error&&e(this.createError(a.error,(i=a.error_description)!=null?i:"An error occurred.",{errorURI:a.error_uri,provider:a.provider})),r(d)}))}export{O as OAuthErrorCode,f as OAuthExtension,m as OAuthPayloadMethods};
1
+ var v=Object.defineProperty,y=Object.defineProperties;var _=Object.getOwnPropertyDescriptors;var l=Object.getOwnPropertySymbols;var b=Object.prototype.hasOwnProperty,A=Object.prototype.propertyIsEnumerable;var g=(n,r,e)=>r in n?v(n,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[r]=e,h=(n,r)=>{for(var e in r||(r={}))b.call(r,e)&&g(n,e,r[e]);if(l)for(var e of l(r))A.call(r,e)&&g(n,e,r[e]);return n},R=(n,r)=>y(n,_(r));var p=(n,r,e)=>new Promise((s,a)=>{var c=i=>{try{t(e.next(i))}catch(d){a(d)}},u=i=>{try{t(e.throw(i))}catch(d){a(d)}},t=i=>i.done?s(i.value):Promise.resolve(i.value).then(c,u);t((e=e.apply(n,r)).next())});import{Extension as O}from"@magic-sdk/commons";var m=(e=>(e.Start="magic_oauth_login_with_redirect_start",e.Verify="magic_oauth_login_with_redirect_verify",e))(m||{}),I=(o=>(o.InvalidRequest="invalid_request",o.InvalidClient="invalid_client",o.InvalidScope="invalid_scope",o.InvalidGrant="invalid_grant",o.UnauthorizedClient="unauthorized_client",o.UnsupportedResponseType="unsupported_response_type",o.UnsupportedGrantType="unsupported_grant_type",o.UnsupportedTokenType="unsupported_token_type",o.AccessDenied="access_denied",o.ServerError="server_error",o.TemporarilyUnavailable="temporarily_unavailable",o))(I||{});var f=class extends O.Internal{constructor(){super(...arguments);this.name="oauth2";this.config={};this.compat={"magic-sdk":">=2.4.6","@magic-sdk/react-native":!1,"@magic-sdk/react-native-bare":!1,"@magic-sdk/react-native-expo":!1}}loginWithRedirect(e){return this.utils.createPromiEvent((s,a)=>p(this,null,function*(){var d;let c=this.utils.createJsonRpcRequestPayload("magic_oauth_login_with_redirect_start",[R(h({},e),{apiKey:this.sdk.apiKey,platform:"web"})]),u=yield this.request(c),t=u,i=u;i.error&&a(this.createError(i.error,(d=i.error_description)!=null?d:"An error occurred.",{errorURI:i.error_uri,provider:i.provider})),t!=null&&t.oauthAuthoriationURI&&(window.location.href=t.useMagicServerCallback?new URL(t.oauthAuthoriationURI,this.sdk.endpoint).href:t.oauthAuthoriationURI),s()}))}getRedirectResult(e){let s=window.location.search,a=window.location.origin+window.location.pathname;return window.history.replaceState(null,"",a),w.call(this,s,e)}};function w(n,r){return this.utils.createPromiEvent((e,s)=>p(this,null,function*(){var i;let a=this.utils.createJsonRpcRequestPayload("magic_oauth_login_with_redirect_verify",[{authorizationResponseParams:n,magicApiKey:this.sdk.apiKey,platform:"web",lifespan:r}]),c=yield this.request(a),u=c,t=c;t.error&&s(this.createError(t.error,(i=t.error_description)!=null?i:"An error occurred.",{errorURI:t.error_uri,provider:t.provider})),e(u)}))}export{I as OAuthErrorCode,f as OAuthExtension,m as OAuthPayloadMethods};
2
2
  //# sourceMappingURL=index.mjs.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/index.ts", "../../src/types.ts"],
4
- "sourcesContent": ["/* eslint-disable @typescript-eslint/ban-ts-comment */\n\nimport { Extension } from '@magic-sdk/commons';\nimport {\n OAuthErrorData,\n OAuthRedirectError,\n OAuthRedirectResult,\n OAuthRedirectConfiguration,\n OAuthPayloadMethods,\n OAuthRedirectStartResult,\n} from './types';\n\nexport class OAuthExtension extends Extension.Internal<'oauth2'> {\n name = 'oauth2' as const;\n config = {};\n compat = {\n 'magic-sdk': '>=2.4.6',\n '@magic-sdk/react-native': false,\n '@magic-sdk/react-native-bare': false,\n '@magic-sdk/react-native-expo': false,\n };\n\n public loginWithRedirect(configuration: OAuthRedirectConfiguration) {\n return this.utils.createPromiEvent<void>(async (resolve, reject) => {\n const parseRedirectResult = this.utils.createJsonRpcRequestPayload(OAuthPayloadMethods.Start, [\n {\n ...configuration,\n apiKey: this.sdk.apiKey,\n platform: 'web',\n },\n ]);\n\n const result = await this.request<OAuthRedirectStartResult | OAuthRedirectError>(parseRedirectResult);\n const successResult = result as OAuthRedirectStartResult;\n const errorResult = result as OAuthRedirectError;\n\n if (errorResult.error) {\n reject(\n this.createError<OAuthErrorData>(errorResult.error, errorResult.error_description ?? 'An error occurred.', {\n errorURI: errorResult.error_uri,\n provider: errorResult.provider,\n }),\n );\n }\n\n if (successResult?.oauthAuthoriationURI) {\n window.location.href = successResult.useMagicServerCallback\n ? // @ts-ignore - this.sdk.endpoint is marked protected but we need to access it.\n new URL(successResult.oauthAuthoriationURI, this.sdk.endpoint).href\n : successResult.oauthAuthoriationURI;\n }\n\n resolve();\n });\n }\n\n public getRedirectResult() {\n const queryString = window.location.search;\n\n // Remove the query from the redirect callback as a precaution to prevent\n // malicious parties from parsing it before we have a chance to use it.\n const urlWithoutQuery = window.location.origin + window.location.pathname;\n window.history.replaceState(null, '', urlWithoutQuery);\n\n return getResult.call(this, queryString);\n }\n}\n\nfunction getResult(this: OAuthExtension, queryString: string) {\n return this.utils.createPromiEvent<OAuthRedirectResult>(async (resolve, reject) => {\n const parseRedirectResult = this.utils.createJsonRpcRequestPayload(OAuthPayloadMethods.Verify, [\n {\n authorizationResponseParams: queryString,\n magicApiKey: this.sdk.apiKey,\n platform: 'web',\n },\n ]);\n\n // Parse the result, which may contain an OAuth-formatted error.\n const resultOrError = await this.request<OAuthRedirectResult | OAuthRedirectError>(parseRedirectResult);\n const maybeResult = resultOrError as OAuthRedirectResult;\n const maybeError = resultOrError as OAuthRedirectError;\n\n if (maybeError.error) {\n reject(\n this.createError<OAuthErrorData>(maybeError.error, maybeError.error_description ?? 'An error occurred.', {\n errorURI: maybeError.error_uri,\n provider: maybeError.provider,\n }),\n );\n }\n\n resolve(maybeResult);\n });\n}\n\nexport * from './types';\n", "import { MagicUserMetadata } from '@magic-sdk/types';\n\nexport enum OAuthPayloadMethods {\n Start = 'magic_oauth_login_with_redirect_start',\n Verify = 'magic_oauth_login_with_redirect_verify',\n}\n\nexport type OAuthProvider =\n | 'google'\n | 'facebook'\n | 'apple'\n | 'github'\n | 'bitbucket'\n | 'gitlab'\n | 'linkedin'\n | 'twitter'\n | 'discord'\n | 'twitch'\n | 'microsoft';\n\nexport interface OAuthErrorData {\n provider: OAuthProvider;\n errorURI?: string;\n}\n\nexport interface OpenIDConnectProfile {\n name?: string;\n familyName?: string;\n givenName?: string;\n middleName?: string;\n nickname?: string;\n preferredUsername?: string;\n profile?: string;\n picture?: string;\n website?: string;\n gender?: string;\n birthdate?: string;\n zoneinfo?: string;\n locale?: string;\n updatedAt?: number;\n}\n\nexport interface OpenIDConnectEmail {\n email?: string;\n emailVerified?: boolean;\n}\n\nexport interface OpenIDConnectPhone {\n phoneNumber?: string;\n phoneNumberVerified?: boolean;\n}\n\nexport interface OpenIDConnectAddress {\n address?: {\n formatted?: string;\n streetAddress?: string;\n locality?: string;\n region?: string;\n postalCode?: string;\n country?: string;\n };\n}\n\nexport type OpenIDConnectUserInfo = OpenIDConnectProfile &\n OpenIDConnectEmail &\n OpenIDConnectPhone &\n OpenIDConnectAddress & { sub?: string; sources?: Record<string, any> } & Record<string, any>;\n\nexport interface OAuthRedirectStartResult {\n oauthAuthoriationURI?: string;\n useMagicServerCallback?: boolean;\n}\n\nexport interface OAuthRedirectResult {\n oauth: {\n provider: OAuthProvider;\n scope: string[];\n userHandle: string;\n userInfo: OpenIDConnectUserInfo;\n };\n magic: {\n idToken: string;\n userMetadata: MagicUserMetadata;\n };\n}\n\nexport interface OAuthRedirectError {\n provider: OAuthProvider;\n error: string;\n error_description?: string;\n error_uri?: string;\n}\n\nexport interface OAuthRedirectConfiguration {\n provider: OAuthProvider;\n redirectURI: string;\n scope?: string[];\n loginHint?: string;\n}\n\nexport enum OAuthErrorCode {\n InvalidRequest = 'invalid_request',\n InvalidClient = 'invalid_client',\n InvalidScope = 'invalid_scope',\n InvalidGrant = 'invalid_grant',\n UnauthorizedClient = 'unauthorized_client',\n UnsupportedResponseType = 'unsupported_response_type',\n UnsupportedGrantType = 'unsupported_grant_type',\n UnsupportedTokenType = 'unsupported_token_type',\n AccessDenied = 'access_denied',\n ServerError = 'server_error',\n TemporarilyUnavailable = 'temporarily_unavailable',\n}\n"],
5
- "mappings": "0nBAEA,OAAS,aAAAA,MAAiB,qBCAnB,IAAKC,OACVA,EAAA,MAAQ,wCACRA,EAAA,OAAS,yCAFCA,OAAA,IAkGAC,OACVA,EAAA,eAAiB,kBACjBA,EAAA,cAAgB,iBAChBA,EAAA,aAAe,gBACfA,EAAA,aAAe,gBACfA,EAAA,mBAAqB,sBACrBA,EAAA,wBAA0B,4BAC1BA,EAAA,qBAAuB,yBACvBA,EAAA,qBAAuB,yBACvBA,EAAA,aAAe,gBACfA,EAAA,YAAc,eACdA,EAAA,uBAAyB,0BAXfA,OAAA,IDxFL,IAAMC,EAAN,cAA6BC,EAAU,QAAmB,CAA1D,kCACL,UAAO,SACP,YAAS,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W,oBAAX,KAAAZ,EAAgC,qBAAsB,CACvG,SAAUY,EAAW,UACrB,SAAUA,EAAW,QACvB,CAAC,CACH,EAGFf,EAAQc,CAAW,CACrB,EAAC,CACH",
6
- "names": ["Extension", "OAuthPayloadMethods", "OAuthErrorCode", "OAuthExtension", "Extension", "configuration", "resolve", "reject", "__async", "_a", "parseRedirectResult", "__spreadProps", "__spreadValues", "result", "successResult", "errorResult", "queryString", "urlWithoutQuery", "getResult", "resultOrError", "maybeResult", "maybeError"]
4
+ "sourcesContent": ["/* eslint-disable @typescript-eslint/ban-ts-comment */\n\nimport { Extension } from '@magic-sdk/commons';\nimport {\n OAuthErrorData,\n OAuthRedirectError,\n OAuthRedirectResult,\n OAuthRedirectConfiguration,\n OAuthPayloadMethods,\n OAuthRedirectStartResult,\n} from './types';\n\nexport class OAuthExtension extends Extension.Internal<'oauth2'> {\n name = 'oauth2' as const;\n config = {};\n compat = {\n 'magic-sdk': '>=2.4.6',\n '@magic-sdk/react-native': false,\n '@magic-sdk/react-native-bare': false,\n '@magic-sdk/react-native-expo': false,\n };\n\n public loginWithRedirect(configuration: OAuthRedirectConfiguration) {\n return this.utils.createPromiEvent<void>(async (resolve, reject) => {\n const parseRedirectResult = this.utils.createJsonRpcRequestPayload(OAuthPayloadMethods.Start, [\n {\n ...configuration,\n apiKey: this.sdk.apiKey,\n platform: 'web',\n },\n ]);\n\n const result = await this.request<OAuthRedirectStartResult | OAuthRedirectError>(parseRedirectResult);\n const successResult = result as OAuthRedirectStartResult;\n const errorResult = result as OAuthRedirectError;\n\n if (errorResult.error) {\n reject(\n this.createError<OAuthErrorData>(errorResult.error, errorResult.error_description ?? 'An error occurred.', {\n errorURI: errorResult.error_uri,\n provider: errorResult.provider,\n }),\n );\n }\n\n if (successResult?.oauthAuthoriationURI) {\n window.location.href = successResult.useMagicServerCallback\n ? // @ts-ignore - this.sdk.endpoint is marked protected but we need to access it.\n new URL(successResult.oauthAuthoriationURI, this.sdk.endpoint).href\n : successResult.oauthAuthoriationURI;\n }\n\n resolve();\n });\n }\n\n public getRedirectResult(lifespan?: number) {\n const queryString = window.location.search;\n\n // Remove the query from the redirect callback as a precaution to prevent\n // malicious parties from parsing it before we have a chance to use it.\n const urlWithoutQuery = window.location.origin + window.location.pathname;\n window.history.replaceState(null, '', urlWithoutQuery);\n\n return getResult.call(this, queryString, lifespan);\n }\n}\n\nfunction getResult(this: OAuthExtension, queryString: string, lifespan?: number) {\n return this.utils.createPromiEvent<OAuthRedirectResult>(async (resolve, reject) => {\n const parseRedirectResult = this.utils.createJsonRpcRequestPayload(OAuthPayloadMethods.Verify, [\n {\n authorizationResponseParams: queryString,\n magicApiKey: this.sdk.apiKey,\n platform: 'web',\n lifespan,\n },\n ]);\n\n // Parse the result, which may contain an OAuth-formatted error.\n const resultOrError = await this.request<OAuthRedirectResult | OAuthRedirectError>(parseRedirectResult);\n const maybeResult = resultOrError as OAuthRedirectResult;\n const maybeError = resultOrError as OAuthRedirectError;\n\n if (maybeError.error) {\n reject(\n this.createError<OAuthErrorData>(maybeError.error, maybeError.error_description ?? 'An error occurred.', {\n errorURI: maybeError.error_uri,\n provider: maybeError.provider,\n }),\n );\n }\n\n resolve(maybeResult);\n });\n}\n\nexport * from './types';\n", "import { MagicUserMetadata } from '@magic-sdk/types';\n\nexport enum OAuthPayloadMethods {\n Start = 'magic_oauth_login_with_redirect_start',\n Verify = 'magic_oauth_login_with_redirect_verify',\n}\n\nexport type OAuthProvider =\n | 'google'\n | 'facebook'\n | 'apple'\n | 'github'\n | 'bitbucket'\n | 'gitlab'\n | 'linkedin'\n | 'twitter'\n | 'discord'\n | 'twitch'\n | 'microsoft';\n\nexport interface OAuthErrorData {\n provider: OAuthProvider;\n errorURI?: string;\n}\n\nexport interface OpenIDConnectProfile {\n name?: string;\n familyName?: string;\n givenName?: string;\n middleName?: string;\n nickname?: string;\n preferredUsername?: string;\n profile?: string;\n picture?: string;\n website?: string;\n gender?: string;\n birthdate?: string;\n zoneinfo?: string;\n locale?: string;\n updatedAt?: number;\n}\n\nexport interface OpenIDConnectEmail {\n email?: string;\n emailVerified?: boolean;\n}\n\nexport interface OpenIDConnectPhone {\n phoneNumber?: string;\n phoneNumberVerified?: boolean;\n}\n\nexport interface OpenIDConnectAddress {\n address?: {\n formatted?: string;\n streetAddress?: string;\n locality?: string;\n region?: string;\n postalCode?: string;\n country?: string;\n };\n}\n\nexport type OpenIDConnectUserInfo = OpenIDConnectProfile &\n OpenIDConnectEmail &\n OpenIDConnectPhone &\n OpenIDConnectAddress & { sub?: string; sources?: Record<string, any> } & Record<string, any>;\n\nexport interface OAuthRedirectStartResult {\n oauthAuthoriationURI?: string;\n useMagicServerCallback?: boolean;\n}\n\nexport interface OAuthRedirectResult {\n oauth: {\n provider: OAuthProvider;\n scope: string[];\n userHandle: string;\n userInfo: OpenIDConnectUserInfo;\n };\n magic: {\n idToken: string;\n userMetadata: MagicUserMetadata;\n };\n}\n\nexport interface OAuthRedirectError {\n provider: OAuthProvider;\n error: string;\n error_description?: string;\n error_uri?: string;\n}\n\nexport interface OAuthRedirectConfiguration {\n provider: OAuthProvider;\n redirectURI: string;\n scope?: string[];\n loginHint?: string;\n}\n\nexport enum OAuthErrorCode {\n InvalidRequest = 'invalid_request',\n InvalidClient = 'invalid_client',\n InvalidScope = 'invalid_scope',\n InvalidGrant = 'invalid_grant',\n UnauthorizedClient = 'unauthorized_client',\n UnsupportedResponseType = 'unsupported_response_type',\n UnsupportedGrantType = 'unsupported_grant_type',\n UnsupportedTokenType = 'unsupported_token_type',\n AccessDenied = 'access_denied',\n ServerError = 'server_error',\n TemporarilyUnavailable = 'temporarily_unavailable',\n}\n"],
5
+ "mappings": "0nBAEA,OAAS,aAAAA,MAAiB,qBCAnB,IAAKC,OACVA,EAAA,MAAQ,wCACRA,EAAA,OAAS,yCAFCA,OAAA,IAkGAC,OACVA,EAAA,eAAiB,kBACjBA,EAAA,cAAgB,iBAChBA,EAAA,aAAe,gBACfA,EAAA,aAAe,gBACfA,EA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C,EAsEI,IAAMC,EAAsB,KAAK,MAAM,qEAAwD,CAC7F,CACE,4BAA6BO,EAC7B,YAAa,KAAK,IAAI,OACtB,SAAU,MACV,SAAAD,CACF,CACF,CAAC,EAGKI,EAAgB,MAAM,KAAK,QAAkDV,CAAmB,EAChGW,EAAcD,EACdE,EAAaF,EAEfE,EAAW,OACbf,EACE,KAAK,YAA4Be,EAAW,OAAOb,EAAAa,EAAW,oBAAX,KAAAb,EAAgC,qBAAsB,CACvG,SAAUa,EAAW,UACrB,SAAUA,EAAW,QACvB,CAAC,CACH,EAGFhB,EAAQe,CAAW,CACrB,EAAC,CACH",
6
+ "names": ["Extension", "OAuthPayloadMethods", "OAuthErrorCode", "OAuthExtension", "Extension", "configuration", "resolve", "reject", "__async", "_a", "parseRedirectResult", "__spreadProps", "__spreadValues", "result", "successResult", "errorResult", "lifespan", "queryString", "urlWithoutQuery", "getResult", "resultOrError", "maybeResult", "maybeError"]
7
7
  }
package/dist/extension.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var MagicOAuth2Extension=(()=>{var U=Object.create;var d=Object.defineProperty,k=Object.defineProperties,D=Object.getOwnPropertyDescriptor,P=Object.getOwnPropertyDescriptors,S=Object.getOwnPropertyNames,f=Object.getOwnPropertySymbols,E=Object.getPrototypeOf,y=Object.prototype.hasOwnProperty,q=Object.prototype.propertyIsEnumerable;var v=(t,e,r)=>e in t?d(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,g=(t,e)=>{for(var r in e||(e={}))y.call(e,r)&&v(t,r,e[r]);if(f)for(var r of f(e))q.call(e,r)&&v(t,r,e[r]);return t},_=(t,e)=>k(t,P(e));var C=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),A=(t,e)=>{for(var r in e)d(t,r,{get:e[r],enumerable:!0})},O=(t,e,r,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of S(e))!y.call(t,i)&&i!==r&&d(t,i,{get:()=>e[i],enumerable:!(s=D(e,i))||s.enumerable});return t};var M=(t,e,r)=>(r=t!=null?U(E(t)):{},O(e||!t||!t.__esModule?d(r,"default",{value:t,enumerable:!0}):r,t)),T=t=>O(d({},"__esModule",{value:!0}),t);var h=(t,e,r)=>new Promise((s,i)=>{var p=o=>{try{n(r.next(o))}catch(u){i(u)}},c=o=>{try{n(r.throw(o))}catch(u){i(u)}},n=o=>o.done?s(o.value):Promise.resolve(o.value).then(p,c);n((r=r.apply(t,e)).next())});var I=C((G,b)=>{b.exports=Magic});var K={};A(K,{default:()=>z});var w=M(I());var m={};A(m,{OAuthErrorCode:()=>x,OAuthPayloadMethods:()=>R});var R=(r=>(r.Start="magic_oauth_login_with_redirect_start",r.Verify="magic_oauth_login_with_redirect_verify",r))(R||{}),x=(a=>(a.InvalidRequest="invalid_request",a.InvalidClient="invalid_client",a.InvalidScope="invalid_scope",a.InvalidGrant="invalid_grant",a.UnauthorizedClient="unauthorized_client",a.UnsupportedResponseType="unsupported_response_type",a.UnsupportedGrantType="unsupported_grant_type",a.UnsupportedTokenType="unsupported_token_type",a.AccessDenied="access_denied",a.ServerError="server_error",a.TemporarilyUnavailable="temporarily_unavailable",a))(x||{});var l=class extends w.Extension.Internal{constructor(){super(...arguments);this.name="oauth2";this.config={};this.compat={"magic-sdk":">=2.4.6","@magic-sdk/react-native":!1,"@magic-sdk/react-native-bare":!1,"@magic-sdk/react-native-expo":!1}}loginWithRedirect(r){return this.utils.createPromiEvent((s,i)=>h(this,null,function*(){var u;let p=this.utils.createJsonRpcRequestPayload("magic_oauth_login_with_redirect_start",[_(g({},r),{apiKey:this.sdk.apiKey,platform:"web"})]),c=yield this.request(p),n=c,o=c;o.error&&i(this.createError(o.error,(u=o.error_description)!=null?u:"An error occurred.",{errorURI:o.error_uri,provider:o.provider})),n!=null&&n.oauthAuthoriationURI&&(window.location.href=n.useMagicServerCallback?new URL(n.oauthAuthoriationURI,this.sdk.endpoint).href:n.oauthAuthoriationURI),s()}))}getRedirectResult(){let r=window.location.search,s=window.location.origin+window.location.pathname;return window.history.replaceState(null,"",s),N.call(this,r)}};function N(t){return this.utils.createPromiEvent((e,r)=>h(this,null,function*(){var n;let s=this.utils.createJsonRpcRequestPayload("magic_oauth_login_with_redirect_verify",[{authorizationResponseParams:t,magicApiKey:this.sdk.apiKey,platform:"web"}]),i=yield this.request(s),p=i,c=i;c.error&&r(this.createError(c.error,(n=c.error_description)!=null?n:"An error occurred.",{errorURI:c.error_uri,provider:c.provider})),e(p)}))}Object.assign(l,g({},m));var z=l;return T(K);})();
1
+ "use strict";var MagicOAuth2Extension=(()=>{var U=Object.create;var d=Object.defineProperty,k=Object.defineProperties,D=Object.getOwnPropertyDescriptor,P=Object.getOwnPropertyDescriptors,S=Object.getOwnPropertyNames,f=Object.getOwnPropertySymbols,E=Object.getPrototypeOf,y=Object.prototype.hasOwnProperty,q=Object.prototype.propertyIsEnumerable;var v=(t,e,r)=>e in t?d(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,g=(t,e)=>{for(var r in e||(e={}))y.call(e,r)&&v(t,r,e[r]);if(f)for(var r of f(e))q.call(e,r)&&v(t,r,e[r]);return t},_=(t,e)=>k(t,P(e));var C=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),b=(t,e)=>{for(var r in e)d(t,r,{get:e[r],enumerable:!0})},A=(t,e,r,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of S(e))!y.call(t,o)&&o!==r&&d(t,o,{get:()=>e[o],enumerable:!(s=D(e,o))||s.enumerable});return t};var M=(t,e,r)=>(r=t!=null?U(E(t)):{},A(e||!t||!t.__esModule?d(r,"default",{value:t,enumerable:!0}):r,t)),T=t=>A(d({},"__esModule",{value:!0}),t);var h=(t,e,r)=>new Promise((s,o)=>{var c=n=>{try{i(r.next(n))}catch(p){o(p)}},u=n=>{try{i(r.throw(n))}catch(p){o(p)}},i=n=>n.done?s(n.value):Promise.resolve(n.value).then(c,u);i((r=r.apply(t,e)).next())});var I=C((G,O)=>{O.exports=Magic});var K={};b(K,{default:()=>z});var w=M(I());var m={};b(m,{OAuthErrorCode:()=>x,OAuthPayloadMethods:()=>R});var R=(r=>(r.Start="magic_oauth_login_with_redirect_start",r.Verify="magic_oauth_login_with_redirect_verify",r))(R||{}),x=(a=>(a.InvalidRequest="invalid_request",a.InvalidClient="invalid_client",a.InvalidScope="invalid_scope",a.InvalidGrant="invalid_grant",a.UnauthorizedClient="unauthorized_client",a.UnsupportedResponseType="unsupported_response_type",a.UnsupportedGrantType="unsupported_grant_type",a.UnsupportedTokenType="unsupported_token_type",a.AccessDenied="access_denied",a.ServerError="server_error",a.TemporarilyUnavailable="temporarily_unavailable",a))(x||{});var l=class extends w.Extension.Internal{constructor(){super(...arguments);this.name="oauth2";this.config={};this.compat={"magic-sdk":">=2.4.6","@magic-sdk/react-native":!1,"@magic-sdk/react-native-bare":!1,"@magic-sdk/react-native-expo":!1}}loginWithRedirect(r){return this.utils.createPromiEvent((s,o)=>h(this,null,function*(){var p;let c=this.utils.createJsonRpcRequestPayload("magic_oauth_login_with_redirect_start",[_(g({},r),{apiKey:this.sdk.apiKey,platform:"web"})]),u=yield this.request(c),i=u,n=u;n.error&&o(this.createError(n.error,(p=n.error_description)!=null?p:"An error occurred.",{errorURI:n.error_uri,provider:n.provider})),i!=null&&i.oauthAuthoriationURI&&(window.location.href=i.useMagicServerCallback?new URL(i.oauthAuthoriationURI,this.sdk.endpoint).href:i.oauthAuthoriationURI),s()}))}getRedirectResult(r){let s=window.location.search,o=window.location.origin+window.location.pathname;return window.history.replaceState(null,"",o),N.call(this,s,r)}};function N(t,e){return this.utils.createPromiEvent((r,s)=>h(this,null,function*(){var n;let o=this.utils.createJsonRpcRequestPayload("magic_oauth_login_with_redirect_verify",[{authorizationResponseParams:t,magicApiKey:this.sdk.apiKey,platform:"web",lifespan:e}]),c=yield this.request(o),u=c,i=c;i.error&&s(this.createError(i.error,(n=i.error_description)!=null?n:"An error occurred.",{errorURI:i.error_uri,provider:i.provider})),r(u)}))}Object.assign(l,g({},m));var z=l;return T(K);})();
2
2
  if (MagicOAuth2Extension && MagicOAuth2Extension.default != null) { MagicOAuth2Extension = Object.assign(MagicOAuth2Extension.default, MagicOAuth2Extension); delete MagicOAuth2Extension.default; }
@@ -14,7 +14,7 @@ export declare class OAuthExtension extends Extension.Internal<'oauth2'> {
14
14
  error: (reason: any) => void;
15
15
  settled: () => void;
16
16
  }>;
17
- getRedirectResult(): import("@magic-sdk/commons").PromiEvent<OAuthRedirectResult, {
17
+ getRedirectResult(lifespan?: number): import("@magic-sdk/commons").PromiEvent<OAuthRedirectResult, {
18
18
  done: (result: OAuthRedirectResult) => void;
19
19
  error: (reason: any) => void;
20
20
  settled: () => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@magic-ext/oauth2",
3
- "version": "9.2.0",
3
+ "version": "9.2.1-canary.274fd4e.0",
4
4
  "description": "Magic SDK OAuth Extension for Web environments.",
5
5
  "author": "Magic <team@magic.link> (https://magic.link/)",
6
6
  "license": "MIT",
@@ -32,8 +32,8 @@
32
32
  "crypto-js": "^3.3.0"
33
33
  },
34
34
  "devDependencies": {
35
- "@magic-sdk/commons": "^24.2.0",
35
+ "@magic-sdk/commons": "24.2.1-canary.274fd4e.0",
36
36
  "@types/crypto-js": "~3.1.47"
37
37
  },
38
- "gitHead": "7ae3e9df5e3a71ad7238c4d25fd09f960f30ce6e"
38
+ "gitHead": "274fd4eb6cfef3697696946bf498af360f111211"
39
39
  }