-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to loop through tenantid's by changing authority url #1289
Comments
@kfear27 Apologies for the delay in responding. @sameerag @pkanher617 can correct me if I'm wrong, but I believe this falls under multi-account scenarios, which isn't currently supported. |
@jasonnutter, thank you for the response. Our Azure AD App is multi tenant capeable, I would have thought this was sufficient to do what is needed ? We do have the permissions to access multiple tenants but each request requires a full refresh. Is there a workaround which can be used to flush sessionStorage/localStorage before each new request so it requests a new token for the new teant id ? |
Thanks @jasonnutter - Do you have an ETA on any updates where this can be run in parallel ? |
@kfear27 Not yet, but we're working on it. I would follow that issues for updates. Closing as a duplicate. |
Just an FYI I found a solution to this. Functions: function getData(tenantid,apiUrl) {
return new Promise(resolve => {
var applicationConfig = {
auth: {
clientId: "AZURE-APP-ID-HERE",
authority: "https://login.microsoftonline.com/" + tenantid,
redirectUri: "https://my.redirect.uri/uri"
},
cache: {
cacheLocation: "localStorage",
storeAuthStateInCookie: false
}
};
var msalInstance = new Msal.UserAgentApplication(applicationConfig);
var scopes = {
forceRefresh: true,
scopes: ["Organization.Read.All"],
loginHint: "user@email.com"
};
msalInstance.acquireTokenSilent(scopes).then(response => {
var xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = function () {
if (this.readyState == 4 && this.status == 200) {
var data = JSON.parse(this.responseText);
$('#o365res').append(JSON.stringify(data, null, 2));
resolve();
}
}
xmlHttp.open("GET", "https://graph.microsoft.com/v1.0/" + apiUrl, true);
xmlHttp.setRequestHeader('Authorization', 'Bearer ' + response.accessToken);
xmlHttp.send();
}).catch(err => { });
});
}
function getDataChain(clients) {
const nextClient = clients.shift();
if (nextClient) {
return getData(nextClient,'organization').then(_ => getDataChain(clients))
} else { return Promise.resolve(); }
} Client ID array & calling the chaining function: var clients = ['XXX-XXX-XXX-XXX-XXX','YYY-YYY-YYY-YYY-YYY'];
getDataChain(clients).then(_ => console.log("all finished")); |
Please follow the issue template below. Failure to do so will result in a delay in answering your question.
Library
msal@1.x.x
or@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:
Example Loop:
Are there any better ways to be doing is where it actually works?
Thanks
The text was updated successfully, but these errors were encountered: