我有以下代碼用于通過(guò) vue-msal 連接到 Azure AD 的基于 Vue JS 的單頁(yè)應(yīng)用程序,當(dāng)我:第一次打開網(wǎng)絡(luò)應(yīng)用程序?qū)⑽規(guī)У?AAD 登錄頁(yè)面登錄后,將我重定向回我的應(yīng)用程序然后我可以做一個(gè)console.log()并打印出我的訪問(wèn)令牌等以驗(yàn)證登錄是否成功并且令牌已成功獲取現(xiàn)在假設(shè)我關(guān)閉瀏覽器選項(xiàng)卡。我的登錄會(huì)話仍然存在(畢竟,我沒(méi)有刪除任何 cookie?。┑F(xiàn)在我的訪問(wèn)令牌不見了(大概是因?yàn)樗槐4鏋樽兞慷皇?cookie 中)。當(dāng)我打開一個(gè)新選項(xiàng)卡并導(dǎo)航到我的應(yīng)用程序時(shí),如何重新獲取訪問(wèn)令牌?# main.jsimport Vue from 'vue'import App from './App.vue'import router from './router'import msal from 'vue-msal';Vue.config.productionTip = falseVue.use(msal, { auth: { clientId: "CLIENT_ID_OF_MY_SINGLE_PAGE_APPLICATION" authority: "https://login.microsoftonline.com/TENANT_ID/", redirectUri: "http://localhost:8080/", requireAuthOnInitialize: true }, request: { scopes: [ `user.read`, `https://backend-api-hosted-on-functionapp.azurewebsites.net/user_impersonation` ] }, graph: { callAfterInit: true, }, cache: { cacheLocation: "sessionStorage" }});new Vue({ router, render: h => h(App), data: function() { return { dummyVariable: 'dummyValue', } }, created() { console.log("User auth status is: " + this.$msal.isAuthenticated()); console.log("User data object: " + JSON.stringify(this.$msal)) // shows the bearer token the first time, but when I then close the tab and re-open the tab, I see nothing here }}}).$mount('#app')所以我有幾個(gè)問(wèn)題:如果再次加載應(yīng)用程序,我是否“注定要”重新獲取新令牌?這是傳統(tǒng)做法嗎?如果是這樣,我該怎么做?我嘗試使用:
關(guān)閉瀏覽器選項(xiàng)卡并再次打開頁(yè)面后,如何使用 vue-msal 從 AAD 重新獲取令牌?
慕斯王
2022-12-18 18:51:22