-
Notifications
You must be signed in to change notification settings - Fork 377
Tenant profiles
pmaytak edited this page Aug 26, 2021
·
3 revisions
Here is a code sample that acquires tokens for the same account, but in different tenant, and then displays the tenants and the claims of the ID token in each tenant
using Microsoft.Identity.Client;
using System;
using System.Threading.Tasks;
class Program
{
static async Task Main(string[] args)
{
IPublicClientApplication app = PublicClientApplicationBuilder.Create("4a1aa1d5-c567-49d0-ad0b-cd957a47f842")
.WithDefaultRedirectUri()
.Build();
// Authenticate in my home tenant (Authority is 'common')
AuthenticationResult result = await app.AcquireTokenInteractive(new[] { "user.read" })
.ExecuteAsync();
// Get a new token for myself, but in another tenant.
result = await app.AcquireTokenSilent(new[] { "user.read" }, result.Account)
.WithAuthority(app.Authority.Replace("common", "msidentitysamplestesting.onmicrosoft.com"))
.ExecuteAsync();
// Display tenants, and claims
foreach (var tenantProfile in result.Account.GetTenantProfiles())
{
Console.WriteLine($"Tenant= {tenantProfile.TenantId}");
foreach(var claim in tenantProfile.ClaimsPrincipal.Claims)
{
Console.WriteLine($" {claim.Type}={claim.Value}");
}
}
}
}
- Home
- Why use MSAL.NET
- Is MSAL.NET right for me
- Scenarios
- Register your app with AAD
- Client applications
- Acquiring tokens
- MSAL samples
- Known Issues
- Acquiring a token for the app
- Acquiring a token on behalf of a user in Web APIs
- Acquiring a token by authorization code in Web Apps
- AcquireTokenInteractive
- WAM - the Windows broker
- .NET Core
- Maui Docs
- Custom Browser
- Applying an AAD B2C policy
- Integrated Windows Authentication for domain or AAD joined machines
- Username / Password
- Device Code Flow for devices without a Web browser
- ADFS support
- High Availability
- Regional
- Token cache serialization
- Logging
- Exceptions in MSAL
- Provide your own Httpclient and proxy
- Extensibility Points
- Clearing the cache
- Client Credentials Multi-Tenant guidance
- Performance perspectives
- Differences between ADAL.NET and MSAL.NET Apps
- PowerShell support
- Testing apps that use MSAL
- Experimental Features
- Proof of Possession (PoP) tokens
- Using in Azure functions
- Extract info from WWW-Authenticate headers
- SPA Authorization Code