Skip to content

Call user_info endpoint for AAD guest scenarios #18

Description

@jennyf19

Why?

TokenAcquistion.cs has hacks to try to guess guest scenarios. In the case of guest scenarios the home tenant ID, home object id is different from the tenantID, object ID which are provided in the IDToken. But we don't have today the home tid/oid information, and therefore we don't know that this is a guest user.
MSAL.NET uses the home tenant information, and therefore in the guest scenarios we don't find find the tokens in the cache today (I believe UniqueObjectIdentifier)

// Special case for guest users as the Guest oid / tenant id are not surfaced.
// B2C should not follow this logic since loginHint is not present
if (!_microsoftIdentityOptions.IsB2C && account == null)
{
if (loginHint == null)
throw new ArgumentNullException(nameof(loginHint));
var accounts = await application.GetAccountsAsync().ConfigureAwait(false);
account = accounts.FirstOrDefault(a => a.Username == loginHint);
}

and

// Workaround for the guest account
if (account == null)
{
var accounts = await app.GetAccountsAsync().ConfigureAwait(false);
account = accounts.FirstOrDefault(a => a.Username == user.GetLoginHint());
}
if (account != null)
{
await app.RemoveAsync(account).ConfigureAwait(false);
_tokenCacheProvider?.ClearAsync().ConfigureAwait(false);
}

The hypothesis is that we'd want to call the User info endpoint not only for B2C, but also AAD, and get the home tenant ID, home iod, instead of the hack.

What ?

  • Like we do w/B2C, call the user_info endpoint for AAD guest scenarios. Today we test for B2C. We probably want to do the same or similar for AAD.

    if (microsoftIdentityOptions.IsB2C)
    {
    context.ProtocolMessage.SetParameter("client_info", "1");
    // When a new Challenge is returned using any B2C user flow different than susi, we must change
    // the ProtocolMessage.IssuerAddress to the desired user flow otherwise the redirect would use the susi user flow
    await b2cOidcHandlers.OnRedirectToIdentityProvider(context).ConfigureAwait(false);
    }

  • probably (to be checked) change the GetMsalId method to use the home tenant information?

public static string GetMsalAccountId(this ClaimsPrincipal claimsPrincipal)

  • if this is successful, remove the hacks?

How to test?

Otherwise we could add an hotmail account in a test tenant. Alternatively the identity lab will have guest accounts.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions