Skip to main content

Microsoft authentication

Not yet available (2.4.x)

The Microsoft provider is not enabled yet. Only Google is live right now — calling auth.signIn() with this provider throws AuthErrorCode.PROVIDER_NOT_ENABLED. The page below documents its intended shape for when it is re-enabled. See the provider overview and the Google provider.

The Microsoft provider signs users in with the Microsoft Authentication Library (MSAL) for browsers (@azure/msal-browser, read from window.msal). It drives MSAL's popup / redirect sign-in and silent token acquisition.

When you need a backend

No backend is required for the browser sign-in itself. MSAL handles the OAuth/OIDC flow against Microsoft Entra ID. Use a backend only if you exchange tokens or call protected downstream APIs server-side.

Configuration

import { auth } from 'capacitor-auth-manager';

auth.configure({
providers: {
microsoft: {
clientId: 'YOUR_APPLICATION_CLIENT_ID',
redirectUri: 'https://your-app.com/auth/callback',
tenantId: 'common',
scopes: ['openid', 'profile', 'email'],
},
},
});

Options

From the MicrosoftAuthOptions interface in src/definitions.ts:

OptionTypeRequiredPurpose
clientIdstringYesEntra ID application (client) ID.
redirectUristringYesRedirect URI registered with the app.
clientSecretstringNoServer-side flows only — do not embed in the browser.
tenantIdstringNoTenant ID (e.g. common, organizations, or a specific tenant).
scopesstring[]NoScopes to request.
authoritystringNoFull authority URL override.
loginHintstringNoPrefill the account.
domainHintstringNoHint the home tenant/domain.
prompt'login' | 'none' | 'consent' | 'select_account'NoInteraction prompt behavior.
responseTypestringNoOAuth response type.
responseModestringNoOAuth response mode.
codeChallengestringNoPKCE code challenge.
codeChallengeMethodstringNoPKCE challenge method.
statestringNoCSRF state value.
noncestringNoOIDC nonce.

Sign in

await auth.signIn('microsoft');

Notes & caveats

  • MSAL Browser must be loaded on the page. If window.msal is absent, the provider throws: "Microsoft Authentication Library (MSAL) is not loaded. Please include the MSAL script in your HTML."
  • A missing clientId raises a MISSING_CONFIG error during configuration.
  • The library does not verify ID-token signatures in the browser — re-validate server-side if you rely on the claims.