{"version":3,"sources":["webpack:///./src/components/auth/SsoDialog.ts","webpack:///./src/components/auth/open-id-connect.ts"],"names":["SsoDialog","authorizeEndpoint","_classCallCheck","title","width","height","interval","onClose","onSuccess","onFailure","this","key","get","screen","value","_this","dialog","window","open","concat","position","ping","closed","_unused","location","href","startsWith","CognitoConfiguration","OpenIdConnectAuthorizeEndpoint","slice","e","isComplete","url","URL","params","URLSearchParams","search","includes","getError","getErrorDescription","getAuthorizationCode","onclose","close","setTimeout","generateAuthorizeUrl","action","context","options","redirectUrl","toString","getThumbprint","returnUrl","encodeURIComponent","_i","_Object$entries","Object","entries","length","_Object$entries$_i","_slicedToArray"],"mappings":"y7BAEO,IAAMA,EAAS,WAiBrB,SAAAA,EAAYC,I,4FAA2BC,CAAA,KAAAF,GAhBvC,KACQC,uBAAiB,EAEzB,KACQE,WAAK,OACLC,MAAgB,IAAG,KACnBC,OAAiB,IAEzB,KACQC,SAAmB,IAE3B,KACQC,aAAO,OACPC,eAAS,OACTC,eAAS,EAGhBC,KAAKT,kBAAoBA,E,UAkEzB,O,EAjEAD,G,EAAA,EAAAW,IAAA,WAAAC,IAED,WAIC,MAAO,CAHMC,OAAOR,OAAS,EAAMK,KAAKL,OAAS,EACnCQ,OAAOT,MAAQ,EAAMM,KAAKN,MAAQ,KAGhD,CAAAO,IAAA,OAAAG,MAED,WAAO,IAAAC,EAAA,KACAC,EAASC,OAAOC,KACrBR,KAAKT,kBACLS,KAAKP,MAAK,SAAAgB,OACDT,KAAKN,MAAK,YAAAe,OAAWT,KAAKL,OAAM,SAAAc,OAAQT,KAAKU,SAAS,GAAE,UAAAD,OAAST,KAAKU,SAAS,GAAE,iBAa9E,SAAPC,IACL,IAAIC,GAAS,EAEb,IACCA,EAASN,EAAOM,OAEjB,MAAAC,IAEA,GAAID,EACHP,EAAKR,eACD,GAnBa,WAClB,IACC,OAAOS,EAAOQ,SAASC,KAAKC,WAAWC,uBAAqBC,+BAA+BC,MAAM,GAAI,IAEtG,MAAOC,GACN,OAAO,GAcEC,GAEL,CACJ,IAAMC,EAAM,IAAIC,IAAIjB,EAAOQ,SAASC,MAC9BS,EAAS,IAAIC,gBAAgBH,EAAII,QAxBlBpB,EAAOQ,SAASC,KAAKY,SAAS,SA0BlDtB,EAAKN,UAAUM,EAAKuB,SAASJ,GAASnB,EAAKwB,oBAAoBL,IAE/DnB,EAAKP,UAAUO,EAAKyB,qBAAqBN,IAE1ClB,EAAOyB,QAAU,KACjB1B,EAAKR,UACLS,EAAO0B,aAXPC,WAAWtB,EAAMN,EAAKT,UAexBe,KACA,CAAAV,IAAA,uBAAAG,MAED,SAAqBoB,GACpB,OAAOA,EAAOtB,IAAI,UAClB,CAAAD,IAAA,WAAAG,MAED,SAASoB,GACR,OAAOA,EAAOtB,IAAI,WAClB,CAAAD,IAAA,sBAAAG,MAED,SAAoBoB,GACnB,OAAOA,EAAOtB,IAAI,0B,8EAClBZ,EApFoB,I,0rCCCP,SAAS4C,EACvBC,EACAC,EACAC,GAEA,IAAIC,EAAcrB,uBAAqBC,+BAA8B,GAAAT,OACjE0B,EAAOI,YAAY,YAAA9B,OACV2B,EAAQG,YAAY,eAAA9B,OACjB+B,2BAEhB,GAAIH,EAAS,CACRA,EAAQI,YACXJ,EAAQI,UAAYC,mBAAmBL,EAAQI,YAEhD,IAAK,IAALE,EAAA,EAAAC,EAA2BC,OAAOC,QAAQT,GAAQM,EAAAC,EAAAG,OAAAJ,IAAE,CAA/C,IAAAK,EAAAC,EAAAL,EAAAD,GAAA,GAAO1C,EAAG+C,EAAA,GAAE5C,EAAK4C,EAAA,GACjB5C,IACHkC,GAA4B,IAAH7B,OAAOR,EAAG,KAAAQ,OAAIL,KAI1C,OAAOkC","file":"66.03e17389da4d5487105f.js","sourcesContent":["import { CognitoConfiguration } from '@cognitoforms/utils/clientside-configuration';\r\n\r\nexport class SsoDialog {\r\n\t// Auth settings\r\n\tprivate authorizeEndpoint: string;\r\n\r\n\t// Dialog settings\r\n\tprivate title: string;\r\n\tprivate width: number = 800;\r\n\tprivate height: number = 800;\r\n\r\n\t// How often to check status of redirecting\r\n\tprivate interval: number = 500;\r\n\r\n\t// Event handlers\r\n\tprivate onClose: () => void;\r\n\tprivate onSuccess: (code: string) => void;\r\n\tprivate onFailure: (error: string, description: string) => void;\r\n\r\n\tconstructor(authorizeEndpoint: string) {\r\n\t\tthis.authorizeEndpoint = authorizeEndpoint;\r\n\t}\r\n\r\n\tget position() : [height: number, width: number] {\r\n\t\tconst top = (screen.height / 2) - (this.height / 2);\r\n\t\tconst left = (screen.width / 2) - (this.width / 2);\r\n\r\n\t\treturn [top, left];\r\n\t}\r\n\r\n\topen() {\r\n\t\tconst dialog = window.open(\r\n\t\t\tthis.authorizeEndpoint,\r\n\t\t\tthis.title,\r\n\t\t\t`width=${this.width},height=${this.height},top=${this.position[0]},left=${this.position[1]},popup=true`\r\n\t\t) as Window;\r\n\r\n\t\tconst hasError = () => dialog.location.href.includes('error');\r\n\t\tconst isComplete = () => {\r\n\t\t\ttry {\r\n\t\t\t\treturn dialog.location.href.startsWith(CognitoConfiguration.OpenIdConnectAuthorizeEndpoint.slice(0, -1));\r\n\t\t\t}\r\n\t\t\tcatch (e) {\r\n\t\t\t\treturn false;\r\n\t\t\t}\r\n\t\t};\r\n\r\n\t\tconst ping = () => {\r\n\t\t\tlet closed = false;\r\n\r\n\t\t\ttry {\r\n\t\t\t\tclosed = dialog.closed;\r\n\t\t\t}\r\n\t\t\tcatch { }\r\n\r\n\t\t\tif (closed)\r\n\t\t\t\tthis.onClose();\r\n\t\t\telse if (!isComplete())\r\n\t\t\t\tsetTimeout(ping, this.interval);\r\n\t\t\telse {\r\n\t\t\t\tconst url = new URL(dialog.location.href);\r\n\t\t\t\tconst params = new URLSearchParams(url.search);\r\n\t\t\t\tif (hasError())\r\n\t\t\t\t\tthis.onFailure(this.getError(params), this.getErrorDescription(params));\r\n\t\t\t\telse\r\n\t\t\t\t\tthis.onSuccess(this.getAuthorizationCode(params));\r\n\r\n\t\t\t\tdialog.onclose = null;\r\n\t\t\t\tthis.onClose();\r\n\t\t\t\tdialog.close();\r\n\t\t\t}\r\n\t\t};\r\n\r\n\t\tping();\r\n\t}\r\n\r\n\tgetAuthorizationCode(params: URLSearchParams): string {\r\n\t\treturn params.get('code');\r\n\t}\r\n\r\n\tgetError(params: URLSearchParams): string {\r\n\t\treturn params.get('error');\r\n\t}\r\n\r\n\tgetErrorDescription(params: URLSearchParams): string {\r\n\t\treturn params.get('error_description');\r\n\t}\r\n}","import { CognitoConfiguration } from '@cognitoforms/utils/clientside-configuration';\r\nimport { getThumbprint } from '@cognitoforms/api/services/authentication';\r\n\r\nexport default function generateAuthorizeUrl(\r\n\taction: AuthenticationAction,\r\n\tcontext: AuthenticationContext,\r\n\toptions?: LoginOptions | SignupOptions | ValidateOptions | InviteOptions\r\n) {\r\n\tlet redirectUrl = CognitoConfiguration.OpenIdConnectAuthorizeEndpoint +\r\n\t\t`${action.toString()}` +\r\n\t\t`?context=${context.toString()}` +\r\n\t\t`&thumbprint=${getThumbprint()}`;\r\n\r\n\tif (options) {\r\n\t\tif (options.returnUrl)\r\n\t\t\toptions.returnUrl = encodeURIComponent(options.returnUrl);\r\n\r\n\t\tfor (const [key, value] of Object.entries(options)) {\r\n\t\t\tif (value)\r\n\t\t\t\tredirectUrl = redirectUrl + `&${key}=${value}`;\r\n\t\t}\r\n\t}\r\n\r\n\treturn redirectUrl;\r\n}\r\n\r\nexport type AuthenticationProvider = 'Google' | 'Facebook' | 'Microsoft';\r\n\r\nexport type AuthenticationAction = 'login' | 'signup' | 'validate';\r\n\r\nexport type AuthenticationContext = 'redirect' | 'popup';\r\n\r\nexport type AuthenticationMethodType = 'Unknown' | 'Email' | 'Google' | 'Facebook' | 'Microsoft' | 'Support' | 'Custom';\r\n\r\ntype LoginOptions = {\r\n\treturnUrl: string;\r\n\tinviteCode: string;\r\n\tauthMethodType: AuthenticationMethodType;\r\n\trequiredOrg: string;\r\n\trequiredOrgName: string;\r\n\tdestinationOrgName: string;\r\n\trequiredUser: string;\r\n\tlogoutReason: string;\r\n}\r\n\r\ntype SignupOptions = {\r\n\treturnUrl: string;\r\n\tinviteCode: string;\r\n\tauthMethodType: AuthenticationMethodType;\r\n\torganizationName: string;\r\n\ttimezone: string;\r\n}\r\n\r\ntype ValidateOptions = {\r\n\tAuthenticationType: AuthenticationMethodType;\r\n\tAuthenticationProvider: AuthenticationProvider;\r\n\tTenantId: string;\r\n\tClientId: string;\r\n\tClientSecret: string;\r\n}\r\n\r\ntype InviteOptions = {\r\n\tencryptedUserInfo: string;\r\n\tencryptedState: string;\r\n}"],"sourceRoot":""}