> ## Documentation Index
> Fetch the complete documentation index at: https://docs.lovable.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Add Microsoft authentication to your app

> Add Microsoft sign-in to your app using managed Microsoft OAuth or your own Azure app registration.

> [!NOTE]
>
> This page documents **Microsoft authentication for your app's users**. It is available only for apps using the [built-in backend](https://docs.lovable.dev/features/cloud). It is not about logging in to Lovable itself with a Microsoft account (see [SAML SSO](https://docs.lovable.dev/features/business/sso.md) for using Microsoft Entra ID as your workspace's identity provider), and not about the [Microsoft 365 connector](https://docs.lovable.dev/integrations/microsoft.md) your app can use for files and email. For an overview of all login methods, see [Users and authentication](https://docs.lovable.dev/features/authentication).

Let users sign in to your app with their Microsoft account, whether that is a personal account or a work or school account managed by their organization.

Microsoft sign-in fits apps you sell to organizations that run on Microsoft 365, because their people already have an account. Microsoft sign-in also fits internal tools where sign-in is limited to your own organization's accounts, which needs your own credentials.

## Choose a setup option

Users sign in the same way with both options. The options differ in who manages the credentials and what you can control.

| Option | Choose it when |
| - | - |
| **Managed by Lovable** (the default) | You want sign-in working without an Azure account, and any Microsoft account may sign in. Lovable manages the OAuth configuration and the security updates. |
| **Your own credentials** | You want the consent screen to show your own app's name, or you want to limit who can sign in. Choose it also when you need to own the credentials for security or compliance reasons. You connect an app registration from your own Azure account and manage its credentials yourself. |

> [tab] Managed by Lovable (default)
>
> **1. Ask Lovable to add Microsoft sign-in**
>
> In the project chat, ask:
>
> ```text wrap theme={null}
> Add a Microsoft sign-in button to my app.
> ```
>
> Lovable enables the provider in **More → Users → Settings → Microsoft** and adds the sign-in button to your app's login page. If you enable it yourself in the same settings with the **Enable Microsoft sign-in** toggle, Lovable sends a message to the project chat on your behalf and adds the button. That message is treated as standard build usage and consumes credits.
>
> **2. Test the flow**
>
> Verify that:
>
> * a Microsoft sign-in button appears on your login page
> * users are redirected to Microsoft to sign in
> * users return to the app in a signed-in state
> * new users appear in **More → Users**
>
> With **Managed by Lovable**, any Microsoft account can sign in, and Microsoft's consent screen shows Lovable's name. The first time a user signs in to your app, Lovable also shows its own consent page with your project's name. To limit who can sign in or show your own app's name, switch to your own credentials.

> [tab] Your own credentials
>
> You need an Azure account with permission to create app registrations.
>
> **1. Create an app registration in the Azure Portal**
>
> In the [Azure Portal](https://portal.azure.com), go to **App registrations** and create a registration for your app. When Azure asks for **Supported account types**, choose the audience that matches who should sign in to your app: the tenant setting you pick in Lovable in the next step can only narrow this audience, not widen it, so a single-tenant registration blocks personal accounts no matter what Lovable is set to.
>
> Then create a **client secret** for the registration and copy the secret's **value** immediately. Azure shows the value only once, and it is not the same as the secret's ID. Note the registration's **Application (client) ID**, and its **Directory (tenant) ID** if you plan to restrict sign-in to your organization.
>
> **2. Enter your credentials in Lovable**
>
> In **More → Users → Settings → Microsoft**, choose **Your own credentials** and fill in:
>
> * **Client ID (Application ID)**: the Application (client) ID from your app registration.
> * **Client secret**: the secret value you copied in the previous step.
> * **Tenant ID (Directory ID)**, optional: who can sign in. Leave it empty (the default is `common`) to allow any Microsoft account, enter `organizations` to allow only work or school accounts, enter `consumers` to allow only personal accounts, or enter your Directory (tenant) ID to allow only accounts from your organization.
>
> **3. Add the redirect URLs to your Azure configuration**
>
> Copy each URL from the **Redirect URL(s)** field in Lovable into your app registration in the Azure Portal, under **Authentication → Add a platform → Web**, then confirm in Lovable which ones you added. Confirm only URLs you added in Azure, because Microsoft sign-in fails with a URL that Azure does not list. The list includes Lovable's shared callback, your app's own URL, and any custom domains attached to the project. When you attach a new custom domain later, check the list again and add the new URL in Azure.
>
> **4. Test the flow**
>
> Sign in with a Microsoft account that your tenant setting allows, and confirm the user appears in **More → Users**.
>
> > [!WARNING]
> >
> > Azure client secrets expire on the date you set when creating them, and Azure shows a secret's value only once. When the secret expires, Microsoft sign-in stops working until you create a new secret in Azure and save its value in the Microsoft auth settings.

## Managing Microsoft authentication

You can switch between **Managed by Lovable** and **Your own credentials** at any time from **More → Users → Settings → Microsoft**. Switching back to Managed by Lovable deletes your stored client ID, secret, tenant, and redirect URL selections, so switching to your own credentials again means entering them fresh. Turning **Enable Microsoft sign-in** off also clears stored credentials.

To remove the sign-in option, ask Lovable in the project chat:

```text wrap theme={null}
Remove the Microsoft sign-in button from my app.
```

You can also disable the provider in the auth settings. Lovable then sends a message to the project chat on your behalf and removes the button. That message is treated as standard build usage and consumes credits. Users who signed up with Microsoft keep their accounts but need another enabled sign-in method to get back in.

## Troubleshooting

> [accordion] Microsoft sign-in stopped working after months of working fine
>
> If you use your own credentials, your client secret has probably expired. Azure secrets expire on the date set when they were created. Create a new secret in the Azure Portal, copy its value, and save it in the Microsoft auth settings.

> [accordion] Users see a redirect error during sign-in
>
> The redirect URIs in your Azure app registration don't match the redirect URLs Lovable shows. Copy every URL from the **Redirect URL(s)** field into the Azure Portal under **Authentication → Add a platform → Web** exactly, then retry. If sign-in fails only on your published app or custom domain, also check your project's [redirect URLs](https://docs.lovable.dev/features/authentication#site-url-and-redirect-urls).

> [accordion] People from outside my organization can't sign in
>
> That is your tenant setting doing its job. If it shouldn't: in **More → Users → Settings → Microsoft**, clear the **Tenant ID (Directory ID)** field to allow any Microsoft account, or set it to `organizations` to allow work or school accounts from any organization. With your own credentials, also check that your Azure app registration's supported account types allow those accounts.

## FAQ

> [accordion] Do I need an Azure account for Microsoft sign-in?
>
> Only if you use your own credentials. In Managed by Lovable mode, Lovable provides the OAuth configuration and no Azure account is needed.

> [accordion] Can I limit Microsoft sign-in to my company's employees?
>
> Yes, with your own credentials. Enter your directory's ID in the **Tenant ID (Directory ID)** field, and only accounts from that Microsoft Entra directory can sign in. Managed by Lovable mode cannot restrict the tenant.

> [accordion] Why does the consent screen say Lovable instead of my app's name?
>
> The provider is in Managed by Lovable mode, so Microsoft shows the name of the app registration that requests sign-in, which is Lovable's. Switch to **Your own credentials** to show your own app's name.

> [accordion] Which Microsoft accounts can sign in?
>
> By default, any Microsoft account: personal accounts and work or school accounts. With your own credentials you can narrow this to work or school accounts only, personal accounts only, or a single organization.

> [accordion] Does Microsoft sign-in replace email and password sign-in?
>
> No. It is an additional sign-in method, and you can offer it alongside [email](https://docs.lovable.dev/features/email-auth.md), [Google](https://docs.lovable.dev/features/google-auth.md), [Apple](https://docs.lovable.dev/features/apple-auth.md), and other methods.

> [accordion] Can I switch between managed and my own credentials later?
>
> Yes, anytime from **More → Users → Settings → Microsoft**. Switching back to Managed by Lovable deletes your stored client ID, secret, tenant, and redirect URL selections, so switching to your own credentials again means entering them fresh. Azure shows a secret's value only once, so you may need to create a new secret then.
