PageSourceSearch

https://ta-tum.com/js/libs/microsoft.authz.js

js ta-tum.com collected 2026-09-24 11:31:37 UTC 3,847 bytes, 125 lines download raw bytes

1var msalConfig = {
2    auth: {
3        clientId: config.microsoftClientId, //This is your client ID
4        authority: "https://login.microsoftonline.com/common" //This is your tenant info
5    }
6    /*,
7    cache: {
8        cacheLocation: "localStorage",
9        storeAuthStateInCookie: true
10    }
11    */
12};
13
14var graphConfig = {
15    graphMeEndpoint: "https://graph.microsoft.com/v1.0/me"
16};
17
18var requestObj = {
19    scopes: ["User.Read"]
20};
21
22var myMSALObj = new Msal.UserAgentApplication(msalConfig);
23
24
25myMSALObj.handleRedirectCallback(authRedirectCallBack);
26
27function signInMicrosoft() {
28    myMSALObj.loginPopup(requestObj).then(function (loginResponse) {
29        acquireTokenSilent();
30    }).catch(function (error) {
31        //Please check the console for errors
32        console.log(error)
33        if (error.toString().indexOf('cancelled') >= 0) {
34            document.body.dispatchEvent(new CustomEvent("cancelMicrosoft"));
35            return false;
36        } else {
37            acquireTokenSilent();
38        }
39
40    });
41}
42
43function signOutMicrosoft() {
44    myMSALObj.logout();
45}
46
47function acquireTokenSilent() {
48    //Always start with acquireTokenSilent to obtain a token in the signed in user from cache
49    myMSALObj.acquireTokenSilent(requestObj).then(function (tokenResponse) {
50        document.body.dispatchEvent(new CustomEvent("MicrosoftLogin", {
51            detail: {
52                token: tokenResponse.accessToken,
53                name: tokenResponse.account.name,
54                email: tokenResponse.account.userName
55            }
56        }));
57    }).catch(function (error) {
58        document.body.dispatchEvent(new CustomEvent("cancelMicrosoft"));
59        //console.log(error)
60    });
61}
62
63
64function acquireTokenRedirectAndCallMSGraph() {
65    myMSALObj.acquireTokenSilent(requestObj).then(function (tokenResponse) {
66    }).catch(function (error) {
67        console.log(error);
68        if (requiresInteraction(error.errorCode)) {
69            myMSALObj.acquireTokenRedirect(requestObj);
70        } else {
71            document.body.dispatchEvent(new CustomEvent("cancelMicrosoft"));
72        }
73    });
74}
75
76function authRedirectCallBack(error, response) {
77    if (error) {
78        console.log(error);
79        document.body.dispatchEvent(new CustomEvent("cancelMicrosoft"));
80    } else {
81        if (response.tokenType === "access_token") {
82            document.body.dispatchEvent(new CustomEvent("MicrosoftLogin", {
83                detail: {
84                    token: response.accessToken,
85                    name: response.account.name,
86                    email: response.account.userName
87                }
88            }));
89        }
90    }
91}
92
93function requiresInteraction(errorCode) {
94    if (!errorCode || !errorCode.length) {
95        return false;
96    }
97    return errorCode === "consent_required" ||
98        errorCode === "interaction_required" ||
99        errorCode === "login_required";
100}
101
102// Browser check variables
103var ua = window.navigator.userAgent;
104var msie = ua.indexOf('MSIE ');
105var msie11 = ua.indexOf('Trident/');
106var msedge = ua.indexOf('Edge/');
107var isIE = msie > 0 || msie11 > 0;
108var isEdge = msedge > 0;
109
110// can change this to default an experience outside browser use
111var loginType = isIE ? "REDIRECT" : "POPUP";
112
113// runs on page load, change config to try different login types to see what is best for your application
114if (loginType === 'POPUP') {
115    if (myMSALObj.getAccount()) {// avoid duplicate code execution on page load in case of iframe and popup window.
116        acquireTokenSilent();
117    }
118}
119else if (loginType === 'REDIRECT') {
120    if (myMSALObj.getAccount() && !myMSALObj.isCallback(window.location.hash)) {// avoid duplicate code execution on page load in case of iframe and popup window.
121        acquireTokenRedirectAndCallMSGraph();
122    }
123} else {
124    console.error('Please set a valid login type');
125}

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.