Partager via


ITokenAcquirer.GetTokenForUserAsync Method

Definition

Typically used from an ASP.NET Core web app or web API controller. This method gets an access token for a downstream API on behalf of the user account for which the claims are provided in the current user.

public System.Threading.Tasks.Task<Microsoft.Identity.Abstractions.AcquireTokenResult> GetTokenForUserAsync (System.Collections.Generic.IEnumerable<string> scopes, Microsoft.Identity.Abstractions.AcquireTokenOptions? tokenAcquisitionOptions = default, System.Security.Claims.ClaimsPrincipal? user = default, System.Threading.CancellationToken cancellationToken = default);
abstract member GetTokenForUserAsync : seq<string> * Microsoft.Identity.Abstractions.AcquireTokenOptions * System.Security.Claims.ClaimsPrincipal * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Microsoft.Identity.Abstractions.AcquireTokenResult>
Public Function GetTokenForUserAsync (scopes As IEnumerable(Of String), Optional tokenAcquisitionOptions As AcquireTokenOptions = Nothing, Optional user As ClaimsPrincipal = Nothing, Optional cancellationToken As CancellationToken = Nothing) As Task(Of AcquireTokenResult)

Parameters

scopes
IEnumerable<String>

Scopes to request for the downstream API to call.

tokenAcquisitionOptions
AcquireTokenOptions

Options passed-in to create the token acquisition object which calls into MSAL .NET.

user
ClaimsPrincipal

Optional claims principal representing the user. If not provided, will use the signed-in user (in a web app), or the user for which the token was received (in a web API) cases where a given account is a guest in other tenants, and you want to acquire tokens for a specific tenant, like where the user is a guest in.

cancellationToken
CancellationToken

Cancellation token

Returns

An AcquireTokenResult to call on behalf of the user, the downstream API characterized by its scopes.

Applies to