PageSourceSearch

https://mypublicinbox.com/authHeader.js

js mypublicinbox.com collected 2026-10-03 22:01:54 UTC 5,269 bytes, 106 lines download raw bytes

1// Configuración de MSAL
2const msalConfig = {
3    auth: {
4        clientId: "e9b54e11-55d3-4508-9dbd-4069ed85cf88", // This is the ONLY mandatory field that you need to supply.
5        authority:
6            "https://mypublicinbox.b2clogin.com/mypublicinbox.onmicrosoft.com/B2C_1_SignInSignUp", // Choose SUSI as your default authority.
7        knownAuthorities: ["mypublicinbox.b2clogin.com"], // Mark your B2C tenant's domain as trusted.
8        redirectUri: `${window.location.origin}/signin-callback`, // You must register this URI on Azure Portal/App Registration. Defaults to window.location.origin
9        postLogoutRedirectUri: "/", // Indicates the page to navigate after logout.
10        navigateToLoginRequestUrl: false, // If "true", will navigate back to the original request location before processing the auth code response.
11    },
12    cache: {
13        cacheLocation: "localStorage", // Configures cache location. "sessionStorage" is more secure, but "localStorage" gives you SSO between tabs.
14        storeAuthStateInCookie: true, // Set this to "true" if you are having issues on IE11 or Edge
15    },
16};
17
18// Crear una instancia de MSAL
19const msalInstance = new msal.PublicClientApplication(msalConfig);
20
21const LoginStatus = Object.freeze({
22  Ok: 0,
23  RegisterPending: 1
24});
25
26// Función para comprobar si el usuario está logueado y tiene un token válido
27async function checkLogin() {
28    const accounts = msalInstance.getAllAccounts();
29    if (accounts.length > 0) {
30        try {
31            const silentRequest = {
32                account: msalInstance.getActiveAccount() || accounts[0],
33                scopes: [
34                    "https://mypublicinbox.onmicrosoft.com/525ee109-95e6-4114-97a3-26e0636f4c7f/user_impersonation",
35                ],
36            };
37            const tokenResponse = await msalInstance.acquireTokenSilent(silentRequest);
38            if (tokenResponse.accessToken) {
39                // Usuario logueado y token válido
40                const response = await fetch("/api/Users/currentMiniProfile", {
41                    headers: {
42                        "Content-Type": "application/json",
43                        Authorization: `Bearer ${tokenResponse.accessToken}`,
44                    },
45                });
46
47                if (response.ok) {
48                    const data = await response.json();
49
50                    if (data.status == LoginStatus.Ok) {
51
52                        document.getElementById("loggedOut").style.display = "none";
53                        document.getElementById("loggedIn").style.display = "block";
54
55                        document.querySelectorAll(".mpi-user-name>a").forEach((element) => {
56                            element.innerHTML = element.innerHTML
57                                .replace("NombreUsuario", data.nickName)
58                                .replace("UserName", data.nickName);
59                        });
60
61                        document.querySelector(".mpi-user-credits div span").innerText =
62                            data.currentBalance;
63
64                        if (data.isExpert) {
65                            document.querySelector(".mpi-user-be-public-profile").style.display =
66                                "none";
67                            document.querySelector(".mpi-user-win-tempos").style.display = "none";
68                            document
69                                .querySelectorAll(".mpi-user-see-public-profile>a")
70                                .forEach((element) => {
71                                    element.href = `/${data.nickName}`;
72                                });
73                        } else {
74                            document.querySelector(".mpi-user-see-public-profile").style.display =
75                                "none";
76                        }
77
78                        if (data.avatarUrl && data.avatarUrl != "") {
79                            document.querySelector(".mpi-user-avatar div img").src = data.avatarUrl;
80                            document.querySelector(".mpi-user-avatar div img").srcset = data.avatarUrl;
81                        } else {
82                            const avatarText =
83                                data.name?.length > 0 && data.surname?.length
84                                    ? `${data.name[0]}${data.surname[0]}`
85                                    : "";
86                            document.querySelector(
87                                ".mpi-user-avatar div"
88                            ).innerHTML = `<div style='width: 40px;height: 40px; background-color: #bdbdbd; color: #fafafa; display:flex; align-items: center; border-radius: 50%;font-size: 1.25rem;justify-content: center;'>${avatarText}</div>`;
89                        }
90                    } else if (data.status == LoginStatus.RegisterPending) {
91                        window.location.assign("/register");
92                    }
93                }
94            }
95        } catch (error) {
96            // Error al obtener el token, redirigir al login
97            //msalInstance.loginRedirect();
98        }
99    } else {
100        // Usuario no logueado
101        //msalInstance.loginRedirect();
102    }
103}
104
105// Llamar a la función para comprobar el login al cargar la página
106window.onload = checkLogin;

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.