Table of Contents

Class PublicClientApplicationBuilder

Namespace
Microsoft.Identity.Client
Assembly
Microsoft.Identity.Client.dll
public sealed class PublicClientApplicationBuilder : AbstractApplicationBuilder<PublicClientApplicationBuilder>
Inheritance
PublicClientApplicationBuilder
Inherited Members

Methods

Build()

Builds an instance of IPublicClientApplication from the parameters set in the PublicClientApplicationBuilder.

public IPublicClientApplication Build()

Returns

IPublicClientApplication

An instance of IPublicClientApplication

Exceptions

MsalClientException

Thrown when errors occur locally in the library itself (for example, because of incorrect configuration).

Create(string)

Creates a PublicClientApplicationBuilder from a clientID. See https://aka.ms/msal-net-application-configuration

public static PublicClientApplicationBuilder Create(string clientId)

Parameters

clientId string

Client ID (also known as App ID) of the application as registered in the application registration portal (https://aka.ms/msal-net-register-app)/.

Returns

PublicClientApplicationBuilder

A PublicClientApplicationBuilder from which to set more parameters, and to create a public client application instance

CreateWithApplicationOptions(PublicClientApplicationOptions)

Creates a PublicClientApplicationBuilder from public client application configuration options. See https://aka.ms/msal-net-application-configuration

public static PublicClientApplicationBuilder CreateWithApplicationOptions(PublicClientApplicationOptions options)

Parameters

options PublicClientApplicationOptions

Public client applications configuration options

Returns

PublicClientApplicationBuilder

A PublicClientApplicationBuilder from which to set more parameters, and to create a public client application instance

IsBrokerAvailable()

Returns true if a broker can be used. This method is only needed to be used in mobile scenarios which support Mobile Application Management. In other supported scenarios, use WithBroker by itself, which will fall back to use a browser if broker is unavailable.

public bool IsBrokerAvailable()

Returns

bool

Remarks

  • On Windows, the broker (WAM) can be used on Windows 10 and is always installed. See https://aka.ms/msal-net-wam
  • On Mac, Linux, and older versions of Windows a broker is not available.
  • In .NET classic or .NET, install Microsoft.Identity.Client.Desktop first and call WithDesktopFeatures().
  • In mobile apps, the device must be Intune joined and Authenticator or Company Portal must be installed. See https://aka.ms/msal-brokers

WithDefaultRedirectUri()

Configures the public client application to use the recommended reply URI for the platform. See https://aka.ms/msal-net-default-reply-uri.

Platform
.NET desktop
For system browser on .NET Core
NOTE:There will be an update to the default redirect URI in the future to accommodate for system browsers on the .NET desktop and .NET Core platforms.
public PublicClientApplicationBuilder WithDefaultRedirectUri()

Returns

PublicClientApplicationBuilder

A PublicClientApplicationBuilder from which to set more parameters, and to create a public client application instance

WithKerberosTicketClaim(string, KerberosTicketContainer)

Sets the parameters required to get a Kerberos Ticket from Azure AD service.

public PublicClientApplicationBuilder WithKerberosTicketClaim(string servicePrincipalName, KerberosTicketContainer ticketContainer)

Parameters

servicePrincipalName string

Service principal name to get Kerberos Service Ticket.

ticketContainer KerberosTicketContainer

Specify where the Kerberos ticket will be returned - as a claim in the ID token or as a claim in the access token. If the ticket is for the client application, use the ID token. If the ticket is for the downstream API, use the access token.

Returns

PublicClientApplicationBuilder

Remarks

The expiry of the Kerberos ticket is tied to the expiry of the token that contains it. MSAL provides several helper APIs to read and write Kerberos tickets from the Windows Ticket Cache - see KerberosSupplementalTicketManager.

WithOidcAuthority(string)

Adds a known authority corresponding to a generic OpenIdConnect Identity Provider. MSAL will append ".well-known/openid-configuration" to the authority and retrieve the OIDC metadata from there, to figure out the endpoints. See https://openid.net/specs/openid-connect-core-1_0.html#Terminology

public PublicClientApplicationBuilder WithOidcAuthority(string authorityUri)

Parameters

authorityUri string

Returns

PublicClientApplicationBuilder

Remarks

Experimental on public clients. Do not use this method with Entra ID authorities (e.g. https://login.microsfoftonline.com/common). Use WithAuthority(string) instead.

WithParentActivityOrWindow(Func<nint>)

Sets a reference to the IntPtr to a window that triggers the browser to be shown. Used to center the browser that pop-up onto this window.

[CLSCompliant(false)]
public PublicClientApplicationBuilder WithParentActivityOrWindow(Func<nint> windowFunc)

Parameters

windowFunc Func<nint>

A function to return the current window

Returns

PublicClientApplicationBuilder

The builder to chain the .With methods

WithWindowsBrokerOptions(WindowsBrokerOptions)

Allows customization of the Windows 10 Broker experience.

[Obsolete("This API has been replaced with WithBroker(BrokerOptions), which can be found in Microsoft.Identity.Client.Broker package. See https://aka.ms/msal-net-wam for details.", false)]
public PublicClientApplicationBuilder WithWindowsBrokerOptions(WindowsBrokerOptions options)

Parameters

options WindowsBrokerOptions

Returns

PublicClientApplicationBuilder