我有以下代碼用于通過 vue-msal 連接到 Azure AD 的基于 Vue JS 的單頁應用程序,當我:第一次打開網絡應用程序將我帶到 AAD 登錄頁面登錄后,將我重定向回我的應用程序然后我可以做一個console.log()并打印出我的訪問令牌等以驗證登錄是否成功并且令牌已成功獲取現在假設我關閉瀏覽器選項卡。我的登錄會話仍然存在(畢竟,我沒有刪除任何 cookie!)但現在我的訪問令牌不見了(大概是因為它被保存為變量而不是 cookie 中)。當我打開一個新選項卡并導航到我的應用程序時,如何重新獲取訪問令牌?# 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')所以我有幾個問題:如果再次加載應用程序,我是否“注定要”重新獲取新令牌?這是傳統做法嗎?如果是這樣,我該怎么做?我嘗試使用:
關閉瀏覽器選項卡并再次打開頁面后,如何使用 vue-msal 從 AAD 重新獲取令牌?
慕斯王
2022-12-18 18:51:22