{ "version": 3, "sources": ["src/app/classes/MicrosoftGraph.ts"], "sourcesContent": ["import { Router } from \"@angular/router\";\r\nimport { AuthenticationResult, BrowserAuthOptions, InteractionType, PublicClientApplication } from \"@azure/msal-browser\";\r\nimport { Client, GraphRequest } from \"@microsoft/microsoft-graph-client\";\r\nimport { AuthCodeMSALBrowserAuthenticationProvider } from \"@microsoft/microsoft-graph-client/authProviders/authCodeMsalBrowser\";\r\n\r\nexport interface MicrosoftGraphConfig { clientId: string, authority: string, scopes: string[] }\r\n\r\nexport class MicrosoftGraph {\r\n private _clientId: string;\r\n private _authority: string;\r\n private _scopes: string[];\r\n constructor({ clientId, authority, scopes }: MicrosoftGraphConfig) {\r\n this._clientId = clientId;\r\n this._authority = authority;\r\n this._scopes = scopes;\r\n }\r\n\r\n /**\r\n * Represents the client used for making requests to the API.\r\n * Remember to always do a \"null\" check before using the client.\r\n * @example\r\n * Example usage:\r\n * graph.client.api('/me')\r\n * .get()\r\n * .then((response) => {\r\n * console.log(response);\r\n * });\r\n * \r\n *\r\n */\r\n client: Client | null = null;\r\n\r\n\r\n\r\n async initiateClient(): Promise<{ success: boolean, message: string }> {\r\n return new Promise(async (resolve, reject) => {\r\n try {\r\n const authOptions: BrowserAuthOptions = {\r\n clientId: this._clientId,\r\n authority: this._authority,\r\n redirectUri: window.location.href\r\n }\r\n let pca: PublicClientApplication | null = null;\r\n let authResult: AuthenticationResult | null = null;\r\n let authProvider: AuthCodeMSALBrowserAuthenticationProvider | null = null;\r\n\r\n try {\r\n pca = new PublicClientApplication({ auth: authOptions });\r\n } catch (error) {\r\n console.log(error);\r\n throw new Error(String(error));\r\n }\r\n\r\n if (pca === null) throw new Error('Could not create public client');\r\n\r\n try {\r\n await pca.initialize();\r\n } catch (error) {\r\n console.log(error);\r\n throw new Error(String(error));\r\n }\r\n\r\n try {\r\n authResult = await pca.acquireTokenSilent({ scopes: this._scopes });\r\n\r\n } catch (error) {\r\n console.error(error);\r\n \r\n console.log('Failed to get token silently, trying to get token interactively');\r\n \r\n try {\r\n authResult = await pca.acquireTokenPopup({ scopes: this._scopes });\r\n } catch (error) {\r\n console.log(error);\r\n throw new Error(String(error));\r\n }\r\n }\r\n\r\n if (authResult === null || !authResult.account) throw new Error('Could not acquire token');\r\n\r\n pca.setActiveAccount(authResult.account);\r\n\r\n const authCodeOptions = {\r\n account: authResult.account,\r\n interactionType: InteractionType.Popup,\r\n scopes: this._scopes,\r\n }\r\n try {\r\n authProvider = new AuthCodeMSALBrowserAuthenticationProvider(pca, authCodeOptions);\r\n } catch (error) {\r\n console.log(error);\r\n throw new Error(String(error));\r\n }\r\n\r\n if (authProvider === null) throw new Error('Could not create auth provider');\r\n\r\n try {\r\n this.client = Client.initWithMiddleware({ authProvider: authProvider });\r\n resolve({ success: true, message: 'Client initiated successfully' });\r\n } catch (error) {\r\n console.log(error);\r\n throw new Error(String(error));\r\n }\r\n } catch (error) {\r\n reject({ success: false, message: error });\r\n }\r\n\r\n })\r\n }\r\n}\r\n"], "mappings": "2IACAA,IAEA,IAAAC,EAA0D,OAIpD,IAAOC,EAAP,KAAqB,CAIvBC,YAAY,CAAEC,SAAAA,EAAUC,UAAAA,EAAWC,OAAAA,CAAM,EAAwB,CAmBjE,KAAAC,OAAwB,KAlBpB,KAAKC,UAAYJ,EACjB,KAAKK,WAAaJ,EAClB,KAAKK,QAAUJ,CACnB,CAmBMK,gBAAc,QAAAC,EAAA,sBAChB,OAAO,IAAIC,QAAQ,CAAOC,EAASC,IAAUH,EAAA,sBACzC,GAAI,CACA,IAAMI,EAAkC,CACpCZ,SAAU,KAAKI,UACfH,UAAW,KAAKI,WAChBQ,YAAaC,OAAOC,SAASC,MAE7BC,EAAsC,KACtCC,EAA0C,KAC1CC,EAAiE,KAErE,GAAI,CACAF,EAAM,IAAIG,EAAwB,CAAEC,KAAMT,CAAW,CAAE,CAC3D,OAASU,EAAO,CACZC,cAAQC,IAAIF,CAAK,EACX,IAAIG,MAAMC,OAAOJ,CAAK,CAAC,CACjC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CAEJ,EAAC,CACL", "names": ["init_dist", "import_authCodeMsalBrowser", "MicrosoftGraph", "constructor", "clientId", "authority", "scopes", "client", "_clientId", "_authority", "_scopes", "initiateClient", "__async", "Promise", "resolve", "reject", "authOptions", "redirectUri", "window", "location", "href", "pca", "authResult", "authProvider", "PublicClientApplication", "auth", "error", "console", "log", "Error", "String", "initialize", "acquireTokenSilent", "acquireTokenPopup", "account", "setActiveAccount", "authCodeOptions", "interactionType", "InteractionType", "Popup", "AuthCodeMSALBrowserAuthenticationProvider", "Client", "initWithMiddleware", "success", "message"] }