mirror of
https://github.com/ViaVersion/VIAaaS.git
synced 2025-01-24 22:01:49 +01:00
use localStorage for msa, fix loginRequest
This commit is contained in:
parent
1244c7b7a0
commit
007ff302b9
@ -481,7 +481,7 @@ class MicrosoftAccount extends McAccount {
|
|||||||
|
|
||||||
refresh() {
|
refresh() {
|
||||||
super.refresh();
|
super.refresh();
|
||||||
return getTokenPopup(this.msUser, loginRequest)
|
return getTokenPopup(this.msUser, getLoginRequest())
|
||||||
.then(response => fetch("https://user.auth.xboxlive.com/user/authenticate", {
|
.then(response => fetch("https://user.auth.xboxlive.com/user/authenticate", {
|
||||||
method: "post",
|
method: "post",
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
@ -586,7 +586,9 @@ function loginMc(user, pass) {
|
|||||||
$("#form_add_mc input").val("");
|
$("#form_add_mc input").val("");
|
||||||
}
|
}
|
||||||
|
|
||||||
const loginRequest = {scopes: ["XboxLive.signin"], prompt: "select_account"};
|
function getLoginRequest() {
|
||||||
|
return {scopes: ["XboxLive.signin"]};
|
||||||
|
}
|
||||||
let redirectUrl = "https://viaversion.github.io/VIAaaS/src/main/resources/web/";
|
let redirectUrl = "https://viaversion.github.io/VIAaaS/src/main/resources/web/";
|
||||||
if (location.hostname === "localhost" || whitelistedOrigin.includes(location.origin)) {
|
if (location.hostname === "localhost" || whitelistedOrigin.includes(location.origin)) {
|
||||||
redirectUrl = location.origin + location.pathname;
|
redirectUrl = location.origin + location.pathname;
|
||||||
@ -599,7 +601,7 @@ const msalConfig = {
|
|||||||
redirectUri: redirectUrl,
|
redirectUri: redirectUrl,
|
||||||
},
|
},
|
||||||
cache: {
|
cache: {
|
||||||
cacheLocation: "sessionStorage",
|
cacheLocation: "localStorage",
|
||||||
storeAuthStateInCookie: false,
|
storeAuthStateInCookie: false,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -607,7 +609,9 @@ const msalConfig = {
|
|||||||
const myMSALObj = new msal.PublicClientApplication(msalConfig);
|
const myMSALObj = new msal.PublicClientApplication(msalConfig);
|
||||||
|
|
||||||
function loginMs() {
|
function loginMs() {
|
||||||
myMSALObj.loginRedirect(loginRequest);
|
let req = getLoginRequest();
|
||||||
|
req.prompt = "select_account";
|
||||||
|
myMSALObj.loginRedirect(req);
|
||||||
}
|
}
|
||||||
|
|
||||||
$(() => myMSALObj.handleRedirectPromise().then((resp) => {
|
$(() => myMSALObj.handleRedirectPromise().then((resp) => {
|
||||||
@ -627,6 +631,7 @@ $(() => myMSALObj.handleRedirectPromise().then((resp) => {
|
|||||||
|
|
||||||
function getTokenPopup(username, request) {
|
function getTokenPopup(username, request) {
|
||||||
request.account = myMSALObj.getAccountByUsername(username);
|
request.account = myMSALObj.getAccountByUsername(username);
|
||||||
|
request.loginHint = username;
|
||||||
return myMSALObj.acquireTokenSilent(request).catch(error => {
|
return myMSALObj.acquireTokenSilent(request).catch(error => {
|
||||||
console.warn("silent token acquisition fails.");
|
console.warn("silent token acquisition fails.");
|
||||||
if (error instanceof msal.InteractionRequiredAuthError) {
|
if (error instanceof msal.InteractionRequiredAuthError) {
|
||||||
|
Loading…
Reference in New Issue
Block a user