AadHttpClient or MSGraphClient does not work with multiple live accounts
Category
- [ ] Question
- [ ] Typo
- [x] Bug
- [ ] Additional article idea
Expected or Desired Behavior
When multiple accounts found user interaction for choosing correct account should be provided
Observed Behavior
When multiple live account logged in or when current service account does not match any live account you get error.
Steps to Reproduce
When you are logged in SharePoint where SFPX web part exists that connects to Azure services wither using AadHttpClient or MSGraphClient client and check it works fine. Then open in new browser tab Azure portal do sign-out and log in with different account and switch to SharePoint tab and refresh. Or when multiple live accounts found you will get similar issue.
Following errors are not processed. Error in case of multiple live accounts found: AADSTS70002: Error validating credentials. AADSTS16000: Request is ambiguous: multiple user identities are available for the current request Error in case of account mismatch AADSTS50058: A silent sign-in request was sent but none of the currently signed in user(s) match the requested login hint
Proposed solution
Solution @microsoft/sp-http
// AdalAuthContext.js
67: AdalAuthContext.prototype._fetchAccessTokenSilent = function (resourceEndpoint) {`
.
.
73: if (_this._authContext._getItem(_this._authContext.CONSTANTS.STORAGE.ERROR) === 'interaction_required') {
Only one error is processed "interaction_required", but should process also when above mentioned errors are found.
They can also avoid the login prompt by adding the "extraQueryParamter" to config of the "AuthenticationContext" constructor that hints at the current user.
var authContext = new AuthenticationContext({
clientId: clientId,
tenant: aadTenantId,
redirectUri: window.location.origin + '/_forms/spfxsinglesignon.aspx',
extraQueryParameter: '[email protected]'
});
Just ran into the same problem. Logged in with 2 microsoft account.
This is how i did it using ADAL
async getToken(headers: Headers) {
var tp = await this.context.aadTokenProviderFactory.getTokenProvider();
var config = tp["_defaultConfiguration"];
var user = this.context.pageContext.user.loginName;
var aadInstanceUrl = config.aadInstanceUrl[length - 1] === "/" ? config.aadInstanceUrl : config.aadInstanceUrl + "/";
var ctx = new AuthenticationContext({
tenant: config.aadTenantId,
clientId: config.servicePrincipalId,
instance: aadInstanceUrl,
redirectUri: config.redirectUri,
extraQueryParameter: "login_hint=" + encodeURIComponent(user),
loadFrameTimeout: 60000
});
var cu = ctx.getCachedUser();
console.log("USER", cu, user, ctx);
if (cu && cu.userName.toLowerCase() !== user.toLowerCase()) {
ctx.clearCache();
}
var token = await this.acquireToken(ctx, this.resource);
if(headers.has("Authorization")){
headers.set("Authorization", "Bearer " + token)
}else{
headers.append("Authorization", "Bearer " + token);
}
}
private acquireToken(ctx: AuthenticationContext, resource: string){
return new Promise<string>((resolve, reject) => {
ctx.acquireToken(resource, (message, token) =>{
if(!token){
reject(message)
}else{
resolve(token);
}
});
});
}
As this is not really an end-user scenario as they typically have one account, how often you'd really run into this issue unless you are a consultant with multiple accounts... and in this case incognito and profiles would help. Are we missing something on this? Sure - it could be a better implementation, but is this really a common scenario?
My only concern is for a client that might have a shared workstation and the users don't clear the browser cache.
Well, we did have some end users running in this problem allready. Most of them having some kind of admin and a normal account. After some time they did understand what caused it and that a normal user won't bump into this problem, but it's quite hard to explain.
It works for all browsers except IE 11 for us. We are using SPFx 1.6. Below is the error message we are getting. @VesaJuvonen, Problem is we have multiple O365 tenants in our company and users who still use IE11 will face this issue. It works in IE11 inprivate. But we can't ask all the users to use InPrivate mode.
I have noticed that it is not sending login_hint with authorize request.
AADSTS70002: Error validating credentials. AADSTS16000: Request is ambiguous: multiple user identities are available for the current request.
We experienced the same problem with a regular user: in addition to our company tenant, he had added credentials for a school where he's attending some courses. And he experienced an error while using our web part, which is using the aadHttpClient to connect to a back-end API.
@VesaJuvonen It seems to be a problem for some of our end-users ... although it seems to be an edge case and will not affect a majority of our users it still is a blocking issue for some of them. As far as I know we do not have a work-around at the moment (I work in the same team as @lucmoco).
Any update on this? I believe we are seeing a similar issue on our end. Is there any way to force login_hint within SPFx without resorting to ADAL?
@VesaJuvonen end users are having the problem as well. Imagine they used their private account (either Hotmail or Gmail) to log on a consumer service/B2C partner tenant (like I don't know the school board of their district typically) and they are logged in with their corporate account on the corp tenant at the same time.
to follow up the workarounds @araver is suggesting might work for aadhttpclient, but not for graph client as the factory does not expose the getprovider method (at least not in 1.6.0/1.7.1). Setup:
- invite a ms account to a tenant (any tenant) as external user The exact repo case is:
- start with an in private browser
- log on to OneDrive.live.com with the MSA
- go to your SharePoint site with your extension or webpart that calls AAD secured APIs or the Graph, log in with your corp account
- you get the error Also linking that for reference https://github.com/AzureAD/azure-activedirectory-library-for-js/issues/580
Thanks everyone for your input on this. We are aware of this and looking into shipping fix for this as part of the 1.8 release coming in a matter of weeks rather than months... task is currently prioritized as 'must' thing to fix for the release.
@VesaJuvonen : Our clients are facing this issue on a daily basis and we need solution for it as soon as possible. Is there any specific time by when we can expect 1.8 release which will get shipped with this issue as resolved.
@VesaJuvonen : this is also a big issue for our client and as mentioned in an earlier post, it is impossible to explain this issue to a customer. What is the eta on the above mention 1.8 release ? :)
According to:
SharePoint Dev Weekly - Episode 28 - 26th of February 2019 https://youtu.be/oYKBFF7KiKM
ETA 1.8 Release: Soon
Thanks @michel-weber :)
According to SharePoint Developer Monthly Community Call - March 2019 (https://www.youtube.com/watch?v=YntZdZy0NvM), SPFx 1.8 will be shipped SOON (This Month).
Going forward, for new tenants, root site will be a communication site!
SPFX v1.8... Soon - as in, NOW ! 8 hrs ago...
And it's Finally here!!
Announcing the General Availability of SharePoint Framework 1.8
Published March 14, 2019
@2toLeadMike @pkmelee337 @araver @kannansgit @lucmoco @michel-weber @MaheshakaMudli @evobis @baywet