Class ClientSecretCredential
Enables authentication to Microsoft Entra ID using a client secret that was generated for an App Registration. More information on how to configure a client secret can be found at https://learn.microsoft.com/entra/identity-platform/quickstart-configure-app-access-web-apis#add-credentials-to-your-web-application.
public class ClientSecretCredential : TokenCredential
- Inheritance
-
ClientSecretCredential
Constructors
ClientSecretCredential()
Protected constructor for mocking.
protected ClientSecretCredential()
ClientSecretCredential(string, string, string)
Creates an instance of the ClientSecretCredential with the details needed to authenticate against Microsoft Entra ID with a client secret.
public ClientSecretCredential(string tenantId, string clientId, string clientSecret)
Parameters
tenantId
stringThe Microsoft Entra tenant (directory) ID of the service principal.
clientId
stringThe client (application) ID of the service principal
clientSecret
stringA client secret that was generated for the App Registration used to authenticate the client.
ClientSecretCredential(string, string, string, ClientSecretCredentialOptions)
Creates an instance of the ClientSecretCredential with the details needed to authenticate against Microsoft Entra ID with a client secret.
public ClientSecretCredential(string tenantId, string clientId, string clientSecret, ClientSecretCredentialOptions options)
Parameters
tenantId
stringThe Microsoft Entra tenant (directory) ID of the service principal.
clientId
stringThe client (application) ID of the service principal
clientSecret
stringA client secret that was generated for the App Registration used to authenticate the client.
options
ClientSecretCredentialOptionsOptions that allow to configure the management of the requests sent to the Microsoft Entra ID.
ClientSecretCredential(string, string, string, TokenCredentialOptions)
Creates an instance of the ClientSecretCredential with the details needed to authenticate against Microsoft Entra ID with a client secret.
public ClientSecretCredential(string tenantId, string clientId, string clientSecret, TokenCredentialOptions options)
Parameters
tenantId
stringThe Microsoft Entra tenant (directory) ID of the service principal.
clientId
stringThe client (application) ID of the service principal
clientSecret
stringA client secret that was generated for the App Registration used to authenticate the client.
options
TokenCredentialOptionsOptions 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, using the specified client secret to authenticate. Acquired tokens are cached by the credential instance. Token lifetime and refreshing is handled automatically. Where possible, reuse credential instances to optimize cache effectiveness.
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, using the specified client secret to authenticate. Acquired tokens are cached by the credential instance. Token lifetime and refreshing is handled automatically. Where possible, reuse credential instances to optimize cache effectiveness.
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.