Class AbstractApplicationBuilder<T>
public abstract class AbstractApplicationBuilder<T> : BaseAbstractApplicationBuilder<T> where T : BaseAbstractApplicationBuilder<T>
Type Parameters
T
- Inheritance
-
AbstractApplicationBuilder<T>
- Derived
- Inherited Members
Methods
WithAdfsAuthority(string, bool)
Adds a known Authority corresponding to an ADFS server. See https://aka.ms/msal-net-adfs
public T WithAdfsAuthority(string authorityUri, bool validateAuthority = true)
Parameters
authorityUristringAuthority URL for an ADFS server
validateAuthorityboolWhether the authority should be validated against the server metadata.
Returns
- T
The builder to chain the .With methods
Remarks
MSAL.NET will only support ADFS 2019 or later.
WithAuthority(AadAuthorityAudience, bool)
Adds a known Azure AD authority to the application to sign-in users specifying the sign-in audience (the cloud being the Azure public cloud). See https://aka.ms/msal-net-application-configuration.
public T WithAuthority(AadAuthorityAudience authorityAudience, bool validateAuthority = true)
Parameters
authorityAudienceAadAuthorityAudienceSign-in audience (one AAD organization, any work and school accounts, or any work and school accounts and Microsoft personal accounts
validateAuthorityboolWhether the authority should be validated against the server metadata.
Returns
- T
The builder to chain the .With methods
WithAuthority(AzureCloudInstance, AadAuthorityAudience, bool)
Adds a known Azure AD authority to the application to sign-in users specifying the cloud instance and the sign-in audience. See https://aka.ms/msal-net-application-configuration.
public T WithAuthority(AzureCloudInstance azureCloudInstance, AadAuthorityAudience authorityAudience, bool validateAuthority = true)
Parameters
azureCloudInstanceAzureCloudInstanceInstance of Azure Cloud (for instance Azure worldwide cloud, Azure German Cloud, US government ...)
authorityAudienceAadAuthorityAudienceSign-in audience (one AAD organization, any work and school accounts, or any work and school accounts and Microsoft personal accounts
validateAuthorityboolWhether the authority should be validated against the server metadata.
Returns
- T
The builder to chain the .With methods
WithAuthority(AzureCloudInstance, Guid, bool)
Adds a known Azure AD authority to the application to sign-in users from a single organization (single tenant application) described by its cloud instance and its tenant ID. See https://aka.ms/msal-net-application-configuration.
public T WithAuthority(AzureCloudInstance azureCloudInstance, Guid tenantId, bool validateAuthority = true)
Parameters
azureCloudInstanceAzureCloudInstanceInstance of Azure cloud (for example, Azure public cloud, Azure China, or Azure Government).
tenantIdGuidTenant Id of the tenant from which to sign-in users
validateAuthorityboolWhether the authority should be validated against the server metadata.
Returns
- T
The builder to chain the .With methods
WithAuthority(AzureCloudInstance, string, bool)
Adds a known Azure AD authority to the application to sign-in users from a single organization (single-tenant application) described by its cloud instance and its domain name or tenant ID. See https://aka.ms/msal-net-application-configuration.
public T WithAuthority(AzureCloudInstance azureCloudInstance, string tenant, bool validateAuthority = true)
Parameters
azureCloudInstanceAzureCloudInstanceInstance of Azure cloud (for example, Azure public cloud, Azure China, or Azure Government).
tenantstringDomain name associated with the Azure AD tenant from which to sign-in users. This can also be a GUID.
validateAuthorityboolWhether the authority should be validated against the server metadata.
Returns
- T
The builder to chain the .With methods.
Exceptions
- ArgumentNullException
Thrown if
tenantortenantis null or empty.
WithAuthority(string, bool)
Adds a known Azure AD authority to the application to sign-in users specifying the full authority URI. See Application configuration options.
public T WithAuthority(string authorityUri, bool validateAuthority = true)
Parameters
authorityUristringURI of the authority from which MSAL.NET will acquire the tokens. Authority endpoints for the Azure public Cloud are:
https://login.microsoftonline.com/tenant/wheretenantis the tenant ID of the Azure AD tenant or a domain associated with this Azure AD tenant, in order to sign-in users of a specific organization onlyhttps://login.microsoftonline.com/common/to sign-in users with any work and school accounts or personal Microsoft accountshttps://login.microsoftonline.com/organizations/to sign-in users with any work and school accountshttps://login.microsoftonline.com/consumers/to sign-in users with only personal Microsoft accounts (live)
validateAuthorityboolWhether the authority should be validated against the server metadata.
Returns
- T
The builder to chain the .With methods
Exceptions
- ArgumentNullException
Thrown if
authorityUriis null or empty.- ArgumentException
Thrown if
authorityUriis not well-formatted (for example, has spaces).- MsalClientException
Thrown in general exception scenarios (for example if the application was configured with multiple different authority hosts).
WithAuthority(string, Guid, bool)
Adds a known Azure AD authority to the application to sign-in users from a single organization (single-tenant application) specified by its tenant ID. See Application configuration options.
public T WithAuthority(string cloudInstanceUri, Guid tenantId, bool validateAuthority = true)
Parameters
cloudInstanceUristringAzure cloud instance.
tenantIdGuidGUID of the tenant from which to sign-in users.
validateAuthorityboolWhether the authority should be validated against the server metadata.
Returns
- T
The builder to chain the .With methods.
Exceptions
- ArgumentNullException
Thrown if
cloudInstanceUriis null or empty.- ArgumentException
Thrown if
cloudInstanceUriis not well-formatted (for example, has spaces).- MsalClientException
Thrown in more general exception scenarios (for example if the application was configured with multiple different authority hosts).
WithAuthority(string, string, bool)
Adds a known Azure AD authority to the application to sign-in users from a single organization (single-tenant application) described by its domain name. See https://aka.ms/msal-net-application-configuration.
public T WithAuthority(string cloudInstanceUri, string tenant, bool validateAuthority = true)
Parameters
cloudInstanceUristringUri to the Azure cloud instance (for instance
https://login.microsoftonline.com)tenantstringDomain name associated with the tenant from which to sign-in users
validateAuthorityboolWhether the authority should be validated against the server metadata.
Returns
- T
The builder to chain the .With methods
Remarks
tenant can also contain the string representation of a GUID (tenantId),
or even common, organizations or consumers but in this case
it's recommended to use another override (WithAuthority(AzureCloudInstance, Guid, bool)
and WithAuthority(AzureCloudInstance, AadAuthorityAudience, bool)
Exceptions
- ArgumentNullException
Thrown if
cloudInstanceUriortenantis null or empty.- ArgumentException
Thrown if
cloudInstanceUriortenantis not well-formatted (for example, has spaces).- MsalClientException
Thrown in more general exception scenarios (for example if the application was configured with multiple different authority hosts).
WithAuthority(Uri, bool)
Adds a known authority to the application. See Application configuration options. This constructor is mainly used for scenarios where the authority is not a standard Azure AD authority, nor an ADFS authority, nor an Azure AD B2C authority. For Azure AD, even in sovereign clouds, prefer using other overrides such as WithAuthority(AzureCloudInstance, AadAuthorityAudience, bool)
public T WithAuthority(Uri authorityUri, bool validateAuthority = true)
Parameters
authorityUriUriURI of the authority
validateAuthorityboolWhether the authority should be validated against the server metadata.
Returns
- T
The builder to chain the .With methods
Exceptions
- ArgumentNullException
Thrown if
authorityUriis null.- ArgumentException
Thrown if
authorityUriis not well-formatted (for example, has spaces).- MsalClientException
Thrown in general exception scenarios (for example if the application was configured with multiple different authority hosts).
WithB2CAuthority(string)
Adds a known authority corresponding to an Azure AD B2C policy. See https://aka.ms/msal-net-b2c-specificities
public T WithB2CAuthority(string authorityUri)
Parameters
authorityUristringAzure AD B2C authority, including the B2C policy (for instance
"https://fabrikamb2c.b2clogin.com/tfp/{Tenant}/{policy}
Returns
- T
The builder to chain the .With methods
WithCacheOptions(CacheOptions)
Options for MSAL token caches.
MSAL maintains a token cache internally in memory. By default, this cache object is part of each instance of PublicClientApplication or ConfidentialClientApplication. This method allows customization of the in-memory token cache of MSAL.
MSAL's memory cache is different than token cache serialization. Cache serialization pulls the tokens from a cache (e.g. Redis, Cosmos, or a file on disk), where they are stored in JSON format, into MSAL's internal memory cache. Memory cache operations do not involve JSON operations.
External cache serialization remains the recommended way to handle desktop apps, web site and web APIs, as it provides persistence. These options do not currently control external cache serialization.
Detailed guidance for each application type and platform: https://aka.ms/msal-net-token-cache-serialization
public T WithCacheOptions(CacheOptions options)
Parameters
optionsCacheOptionsOptions for the internal MSAL token caches.
Returns
- T
WithClientCapabilities(IEnumerable<string>)
Microsoft Identity specific OIDC extension that allows resource challenges to be resolved without interaction. Allows configuration of one or more client capabilities, e.g. "llt"
public T WithClientCapabilities(IEnumerable<string> clientCapabilities)
Parameters
clientCapabilitiesIEnumerable<string>
Returns
- T
Remarks
MSAL will transform these into special claims request. See https://openid.net/specs/openid-connect-core-1_0-final.html#ClaimsParameter for details on claim requests. For more details see https://aka.ms/msal-net-claims-request
WithClientId(string)
Sets the Client ID of the application
public T WithClientId(string clientId)
Parameters
clientIdstringClient ID (also known as Application ID) of the application as registered in the application registration portal (https://aka.ms/msal-net-register-app)
Returns
- T
The builder to chain the .With methods
WithExtraQueryParameters(IDictionary<string, string>)
Sets Extra Query Parameters for the query string in the HTTP authentication request
public T WithExtraQueryParameters(IDictionary<string, string> extraQueryParameters)
Parameters
extraQueryParametersIDictionary<string, string>This parameter will be appended as is to the query string in the HTTP authentication request to the authority as a string of segments of the form
key=valueseparated by an ampersand character. The parameter can be null.
Returns
- T
The builder to chain the .With methods
WithExtraQueryParameters(string)
Sets Extra Query Parameters for the query string in the HTTP authentication request
public T WithExtraQueryParameters(string extraQueryParameters)
Parameters
extraQueryParametersstringThis parameter will be appended as is to the query string in the HTTP authentication request to the authority. The string needs to be properly URL-encoded and ready to send as a string of segments of the form
key=valueseparated by an ampersand character.
Returns
- T
WithInstanceDiscovery(bool)
Determines whether or not instance discovery is performed when attempting to authenticate. Setting this to false will completely disable instance discovery and authority validation. This will not affect the behavior of application configured with regional endpoints however.
public T WithInstanceDiscovery(bool enableInstanceDiscovery)
Parameters
enableInstanceDiscoveryboolDetermines if instance discovery/Authority validation is performed
Returns
- T
Remarks
If instance discovery is disabled and no user metadata is provided, MSAL will use the provided authority without any checks.
WithInstanceDiscoveryMetadata(string) takes priority over enableInstanceDiscovery
so instance metadata can be provided regardless of this configuration.
WithInstanceDiscoveryMetadata(string)
Allows developers to configure their own valid authorities. A json string similar to https://aka.ms/aad-instance-discovery should be provided. MSAL uses this information to:
- Call REST APIs on the environment specified in the preferred_network
- Identify an environment under which to save tokens and accounts in the cache
- Use the environment aliases to match tokens issued to other authorities
public T WithInstanceDiscoveryMetadata(string instanceDiscoveryJson)
Parameters
instanceDiscoveryJsonstring
Returns
- T
Remarks
Developers take responsibility for authority validation if they use this method. Should not be used when the authority is not known in advance. Has no effect on ADFS or B2C authorities, only for AAD authorities
WithInstanceDiscoveryMetadata(Uri)
Lets an organization setup their own service to handle instance discovery, which enables better caching for microservice/service environments. A Uri that returns a response similar to https://aka.ms/aad-instance-discovery should be provided. MSAL uses this information to:
- Call REST APIs on the environment specified in the preferred_network
- Identify an environment under which to save tokens and accounts in the cache
- Use the environment aliases to match tokens issued to other authorities
public T WithInstanceDiscoveryMetadata(Uri instanceDiscoveryUri)
Parameters
instanceDiscoveryUriUri
Returns
- T
Remarks
Developers take responsibility for authority validation if they use this method. Should not be used when the authority is not known in advance. Has no effect on ADFS or B2C authorities, only for AAD authorities
WithLegacyCacheCompatibility(bool)
Enables legacy ADAL cache serialization and deserialization.
public T WithLegacyCacheCompatibility(bool enableLegacyCacheCompatibility = true)
Parameters
enableLegacyCacheCompatibilityboolEnable legacy ADAL cache compatibility.
Returns
- T
The builder to chain the .With methods.
Remarks
ADAL is a previous legacy generation of MSAL.NET authentication library.
If you don't use .WithLegacyCacheCompatibility(false), then by default, the ADAL cache is used
(along with MSAL cache). true flag is only needed for specific migration scenarios
from ADAL.NET to MSAL.NET when both library versions are running side-by-side.
To improve performance add .WithLegacyCacheCompatibility(false) unless you care about migration scenarios.
WithOptions(ApplicationOptions)
Sets application options, which can, for instance have been read from configuration files. See https://aka.ms/msal-net-application-configuration.
protected T WithOptions(ApplicationOptions applicationOptions)
Parameters
applicationOptionsApplicationOptionsApplication options
Returns
- T
The builder to chain the .With methods
WithRedirectUri(string)
Sets the redirect URI of the application. The URI must also be registered in the application portal. See https://aka.ms/msal-net-application-configuration
public T WithRedirectUri(string redirectUri)
Parameters
redirectUristringURL where the STS will call back the application with the security token. Public Client Applications - desktop, mobile, console apps - use different browsers (system browser, embedded browses) and brokers and each has its own rules.
Returns
- T
The builder to chain the .With methods
WithTenantId(string)
Sets the tenant ID of the organization from which the application will let
users sign-in. This is classically a GUID or a domain name. See https://aka.ms/msal-net-application-configuration.
Although it is also possible to set tenantId to common,
organizations, and consumers, it's recommended to use one of the
overrides of WithAuthority(AzureCloudInstance, AadAuthorityAudience, bool).
public T WithTenantId(string tenantId)
Parameters
tenantIdstringtenant ID of the Azure AD tenant or a domain associated with this Azure AD tenant, in order to sign-in a user of a specific organization only
Returns
- T
The builder to chain the .With methods