Table of Contents

Class ClaimsPrincipalFactory

Namespace
Microsoft.Identity.Web
Assembly
Microsoft.Identity.Web.dll

Factory class to create ClaimsPrincipal objects.

public static class ClaimsPrincipalFactory
Inheritance
ClaimsPrincipalFactory
Inherited Members

Methods

FromHomeTenantIdAndHomeObjectId(string, string)

Instantiate a ClaimsPrincipal from a home account object ID and home tenant ID. This can be useful when the web app subscribes to another service on behalf of the user and then is called back by a notification where the user is identified by their home tenant ID and home object ID (like in Microsoft Graph Web Hooks).

public static ClaimsPrincipal FromHomeTenantIdAndHomeObjectId(string homeTenantId, string homeObjectId)

Parameters

homeTenantId string

Home tenant ID of the account.

homeObjectId string

Home object ID of the account in this tenant ID.

Returns

ClaimsPrincipal

A ClaimsPrincipal containing these two claims.

Examples

private async Task GetChangedMessagesAsync(IEnumerable<Notification> notifications)
{
 HttpContext.User = ClaimsPrincipalExtension.FromHomeTenantIdAndHomeObjectId(subscription.HomeTenantId,
                                                                     subscription.HomeUserId);
 foreach (var notification in notifications)
 {
  SubscriptionStore subscription =
          subscriptionStore.GetSubscriptionInfo(notification.SubscriptionId);
 string accessToken = await tokenAcquisition.GetAccessTokenForUserAsync(scopes);
 ...}
 }

FromTenantIdAndObjectId(string, string)

Instantiate a ClaimsPrincipal from an account object ID and tenant ID. This can be useful when the web app subscribes to another service on behalf of the user and then is called back by a notification where the user is identified by their tenant ID and object ID (like in Microsoft Graph Web Hooks).

public static ClaimsPrincipal FromTenantIdAndObjectId(string tenantId, string objectId)

Parameters

tenantId string

Tenant ID of the account.

objectId string

Object ID of the account in this tenant ID.

Returns

ClaimsPrincipal

A ClaimsPrincipal containing these two claims.

Examples

private async Task GetChangedMessagesAsync(IEnumerable<Notification> notifications)
{
 HttpContext.User = ClaimsPrincipalExtension.FromTenantIdAndObjectId(subscription.TenantId,
                                                                     subscription.UserId);
 foreach (var notification in notifications)
 {
  SubscriptionStore subscription =
          subscriptionStore.GetSubscriptionInfo(notification.SubscriptionId);
 string accessToken = await tokenAcquisition.GetAccessTokenForUserAsync(scopes);
 ...}
 }