How to loop through tenantid's by changing authority url
See original GitHub issuePlease follow the issue template below. Failure to do so will result in a delay in answering your question.
Library
-
msal@1.x.xor@azure/msal@1.x.x
Description
I’ve created a multi tenant App in Azure AD and can use MSAL+Graph API successfully, however I am not attempting to loop through our tenants to collect information, however am unsure of how to do so.
When creating a loop using forEach it doesn’t change authority so the returned data from the first connection is returned each time.
See code:
function config_app(tenantid, callback, apiUrl) {
var applicationConfig = {
auth: {
clientId: "XXXX-XXXX-XXXX-XXXX",
authority: "https://login.microsoftonline.com/" + tenantid,
redirectUri: "https://my.redirecturi.com/fake"
},
cache: {
cacheLocation: "sessionStorage",
storeAuthStateInCookie: false
}
};
var msalInstance = new Msal.UserAgentApplication(applicationConfig);
callback(tenantid, applicationConfig, msalInstance, callMSGraph, apiUrl);
}
function sign_in(tenantid, applicationConfig, msalInstance, callback, apiUrl) {
var scopes = {
scopes: ["Organization.Read.All"],
loginHint: "my@email.com"
};
msalInstance.acquireTokenSilent(scopes).then(response => {
callback(response.accessToken, graphAPICallback, apiUrl);
}).catch(err => {
});
}
function callMSGraph(accessToken, callback, apiUrl) {
console.log("calling ms graph");
var xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = function () {
if (this.readyState == 4 && this.status == 200)
callback(JSON.parse(this.responseText));
}
xmlHttp.open("GET", "https://graph.microsoft.com/v1.0/" + apiUrl, true);
xmlHttp.setRequestHeader('Authorization', 'Bearer ' + accessToken);
xmlHttp.send();
}
function graphAPICallback(data) {
$('#o365res').append(JSON.stringify(data, null, 2));
}
config_app('XXX-XXX-XXX-XXX-XXX', sign_in, 'organization');
Example Loop:
var clients = ['XXX-XXX-XXX-XXX-XXX','YYYY-YYYY-YYYY-YYYY'];
clients.forEach(function(e) {
config_app(e, sign_in, 'organization');
});
Are there any better ways to be doing is where it actually works?
Thanks
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Looping through tenants using MSAL.js - Stack Overflow
I have attempted to simply change the config of the MSAL connection however this fails and will use the existing authority value every...
Read more >SharePoint Online: PowerShell to Iterate through All Site ...
This PnP PowerShell script loops through all sites in your SharePoint Online environment and gets you the site URL. #Parameter $AdminSiteURL = " ......
Read more >URL Not Generating Properly · Issue #641 · tenancy/multi-tenant
When running an artisan job that loops through all web sites - the URL within the results (an email) is set to localhost....
Read more >Redirect Users - Auth0
Describes how to redirect users to URLs that have not been added to the AllowList.
Read more >Set up inventory components - Power Platform | Microsoft Learn
Edit the Command Center App > Get M365 Service Messages flow. Update the List serviceAnnouncements from Graph action and change the Authority ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Just an FYI I found a solution to this.
Functions:
Client ID array & calling the chaining function:
@kfear27 Not yet, but we’re working on it. I would follow that issues for updates.
Closing as a duplicate.