Share via


ClaimsPrincipalFactory.FromTenantIdAndObjectId(String, String) Method

Definition

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 System.Security.Claims.ClaimsPrincipal FromTenantIdAndObjectId (string tenantId, string objectId);
static member FromTenantIdAndObjectId : string * string -> System.Security.Claims.ClaimsPrincipal
Public Shared Function FromTenantIdAndObjectId (tenantId As String, objectId As String) As ClaimsPrincipal

Parameters

tenantId
String

Tenant ID of the account.

objectId
String

Object ID of the account in this tenant ID.

Returns

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);
 ...}
 }

Applies to