From 5f5d9176af478a6e963e4447035230b76c6d0728 Mon Sep 17 00:00:00 2001 From: Steve Faulkner <471400+southpolesteve@users.noreply.github.com> Date: Mon, 28 Dec 2020 20:55:44 -0600 Subject: [PATCH] WIP --- package-lock.json | 6 ++--- package.json | 1 + src/HostedExplorer.tsx | 41 ++++++++++++++++++++++++++--------- src/hooks/useGraphProfile.tsx | 2 +- webpack.config.js | 4 ++-- 5 files changed, 38 insertions(+), 16 deletions(-) diff --git a/package-lock.json b/package-lock.json index 817617d2e..c0405b064 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15815,9 +15815,9 @@ "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" }, "msal": { - "version": "1.4.3", - "resolved": "https://registry.npmjs.org/msal/-/msal-1.4.3.tgz", - "integrity": "sha512-C90MhgzcBuTSR2BOQ/LQryY1CZVESQLJDdmRDWSsaVde+zwZ2iXD0fWw7zeBd5TzfUCiJEXZVs4lFJ8d/IGbiQ==", + "version": "1.4.4", + "resolved": "https://registry.npmjs.org/msal/-/msal-1.4.4.tgz", + "integrity": "sha512-aOBD/L6jAsizDFzKxxvXxH0FEDjp6Inr3Ufi/Y2o7KCFKN+akoE2sLeszEb/0Y3VxHxK0F0ea7xQ/HHTomKivw==", "requires": { "tslib": "^1.9.3" }, diff --git a/package.json b/package.json index c7ac095bd..50cfdfbe4 100644 --- a/package.json +++ b/package.json @@ -71,6 +71,7 @@ "knockout": "3.5.1", "mkdirp": "1.0.4", "monaco-editor": "0.18.1", + "msal": "1.4.4", "object.entries": "1.1.0", "office-ui-fabric-react": "7.134.1", "p-retry": "4.2.0", diff --git a/src/HostedExplorer.tsx b/src/HostedExplorer.tsx index f8b9dc065..33b946f3a 100644 --- a/src/HostedExplorer.tsx +++ b/src/HostedExplorer.tsx @@ -26,6 +26,9 @@ import { useGraphPhoto } from "./hooks/useGraphPhoto"; import { ConnectScreen } from "./Platform/Hosted/ConnectScreen"; import "./Shared/appInsights"; import { useAADAccount } from "./hooks/useAADAccount"; +import * as Msal from "msal"; +import { fetchMe } from "./hooks/useGraphProfile"; +import { fetchSubscriptions } from "./hooks/useSubscriptions"; initializeIcons(); @@ -53,7 +56,21 @@ const configuration: Configuration = { // } // }; -const application = new PublicClientApplication(configuration); +// const application = new PublicClientApplication(configuration); + +const msal = new Msal.UserAgentApplication({ + auth: { + authority: "https://login.microsoft.com/common", + clientId: "203f1145-856a-4232-83d4-a43568fba23d", + redirectUri: "https://dataexplorer-dev.azurewebsites.net" + } +}); + +// msal.handleRedirectCallback((error, response) => { +// console.log(error, response); +// debugger; +// // handle redirect response or error +// }); const App: React.FunctionComponent = () => { const [isOpen, { setTrue: openPanel, setFalse: dismissPanel }] = useBoolean(false); @@ -209,9 +226,18 @@ const App: React.FunctionComponent = () => { className="mecontrolSigninButton" text="Sign In" onClick={() => { - instance.loginPopup({ - scopes: ["https://graph.microsoft-ppe.com/" + "/.default"], - redirectUri: "https://localhost:1234/hostedExplorer.html" + msal.loginPopup().then(foo => { + msal.acquireTokenSilent({ scopes: ["https://graph.windows.net//.default"] }).then(bar => { + debugger; + // const token = + // "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6IjVPZjlQNUY5Z0NDd0NtRjJCT0hIeEREUS1EayIsImtpZCI6IjVPZjlQNUY5Z0NDd0NtRjJCT0hIeEREUS1EayJ9.eyJhdWQiOiJodHRwczovL21hbmFnZW1lbnQuYXp1cmUuY29tLyIsImlzcyI6Imh0dHBzOi8vc3RzLndpbmRvd3MubmV0LzcyZjk4OGJmLTg2ZjEtNDFhZi05MWFiLTJkN2NkMDExZGI0Ny8iLCJpYXQiOjE2MDkyMDYwNDQsIm5iZiI6MTYwOTIwNjA0NCwiZXhwIjoxNjA5MjA5OTQ0LCJhY3IiOiIxIiwiYWlvIjoiQVpRQWEvOFNBQUFBYzZ3RmNHOWRDYTRDS2tX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BuIjoic3RmYXVsQG1pY3Jvc29mdC5jb20iLCJ1dGkiOiJ2ME0xNVdjSWkwcVpwNTdEd1QwSUFnIiwidmVyIjoiMS4wIiwieG1zX3RjZHQiOjEyODkyNDE1NDd9.WD_NlNg2C9rOeES_zRDEIn9MQaNTElyd1NjmQ89dGg8PxCurhZpnuSNmv6J8KuAaiVtifppu64zP5nPDouAsdq5lWrJ5N6WZE9Aox0RuVMqoQRTYEYSeC0R-2wh_77G77zPHVq2qMTOHKz60_Que6_T5VTOFsNpfPzRQwqXmnIvUZnKqf6cBvxLyJYE2IsXSuOdB7jDNWfnsGv19Ew7IdScS4PoIrsVGX5E7rQ4B_bUoYm74ooiH8W0TmVXah21Z66fVAEzuWYlIX5G6ylmT9ncDefVon5JKKe5ksN5GrNjPpVVm3tyCwJeRO_zmtd7nqOZ6GLrn5hzR4CpKB63Fng"; + fetchMe(bar.accessToken).then(resp => { + debugger; + }); + }); + // msal.acquireTokenSilent({ scopes: ["https://graph.windows.net//.default"] }).then(bar => { + // debugger; + // }); }); }} styles={{ @@ -253,9 +279,4 @@ const App: React.FunctionComponent = () => { ); }; -render( - - - , - document.body -); +render(, document.body); diff --git a/src/hooks/useGraphProfile.tsx b/src/hooks/useGraphProfile.tsx index ac80a057d..36c2c503e 100644 --- a/src/hooks/useGraphProfile.tsx +++ b/src/hooks/useGraphProfile.tsx @@ -12,7 +12,7 @@ export async function fetchMe(accessToken: string): Promise { headers: headers }; - return fetch("https://graph.microsoft.com/v1.0/me", options) + return fetch("https://graph.windows.net/me?api-version=1.6", options) .then(response => response.json()) .catch(error => console.log(error)); } diff --git a/webpack.config.js b/webpack.config.js index 5d68f971d..10f2141fa 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -132,8 +132,8 @@ module.exports = function(env = {}, argv = {}) { }), new HtmlWebpackPlugin({ filename: "index.html", - template: "src/index.html", - chunks: ["index"] + template: "src/hostedExplorer.html", + chunks: ["hostedExplorer"] }), new HtmlWebpackPlugin({ filename: "hostedExplorer.html",