Class ClientAssertionCredential
Enables authentication of a Microsoft Entra service principal using a signed client assertion.
public class ClientAssertionCredential : TokenCredential
- Inheritance
-
ClientAssertionCredential
Constructors
ClientAssertionCredential()
Protected constructor for mocking.
protected ClientAssertionCredential()
ClientAssertionCredential(string, string, Func<string>, ClientAssertionCredentialOptions)
Creates an instance of the ClientCertificateCredential with a synchronous callback that provides a signed client assertion to authenticate against Microsoft Entra ID.
public ClientAssertionCredential(string tenantId, string clientId, Func<string> assertionCallback, ClientAssertionCredentialOptions options = null)
Parameters
tenantId
stringThe Microsoft Entra tenant (directory) ID of the service principal.
clientId
stringThe client (application) ID of the service principal
assertionCallback
Func<string>A synchronous callback returning a valid client assertion used to authenticate the service principal.
options
ClientAssertionCredentialOptionsOptions that allow to configure the management of the requests sent to Microsoft Entra ID.
ClientAssertionCredential(string, string, Func<CancellationToken, Task<string>>, ClientAssertionCredentialOptions)
Creates an instance of the ClientCertificateCredential with an asynchronous callback that provides a signed client assertion to authenticate against Microsoft Entra ID.
public ClientAssertionCredential(string tenantId, string clientId, Func<CancellationToken, Task<string>> assertionCallback, ClientAssertionCredentialOptions options = null)
Parameters
tenantId
stringThe Microsoft Entra tenant (directory) ID of the service principal.
clientId
stringThe client (application) ID of the service principal
assertionCallback
Func<CancellationToken, Task<string>>An asynchronous callback returning a valid client assertion used to authenticate the service principal.
options
ClientAssertionCredentialOptionsOptions that allow to configure the management of the requests sent to Microsoft Entra ID.
Methods
GetToken(TokenRequestContext, CancellationToken)
Obtains a token from Microsoft Entra ID, by calling the assertionCallback specified when constructing the credential to obtain a client assertion for authentication.
public override AccessToken GetToken(TokenRequestContext requestContext, CancellationToken cancellationToken = default)
Parameters
requestContext
TokenRequestContextThe details of the authentication request.
cancellationToken
CancellationTokenA CancellationToken controlling the request lifetime.
Returns
- AccessToken
An Azure.Core.AccessToken which can be used to authenticate service client calls.
GetTokenAsync(TokenRequestContext, CancellationToken)
Obtains a token from Microsoft Entra ID, by calling the assertionCallback specified when constructing the credential to obtain a client assertion for authentication.
public override ValueTask<AccessToken> GetTokenAsync(TokenRequestContext requestContext, CancellationToken cancellationToken = default)
Parameters
requestContext
TokenRequestContextThe details of the authentication request.
cancellationToken
CancellationTokenA CancellationToken controlling the request lifetime.
Returns
- ValueTask<AccessToken>
An Azure.Core.AccessToken which can be used to authenticate service client calls.