Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

816
Views
How to get Azure AD authentication to work in production with msal-browser in my Next.js application?

The following implementation of msal works without issues when I run it on localhost. But when I deploy it to an Azure App Service the clientId and/or tenantID seems to become undefined, even when I tried experimenting with placing the id strings directly into the file. Here is the error I get when i try to click the login button in production:

GET https://login.microsoftonline.com/undefined/v2.0/.well-known/openid-configuration 400 (Bad Request)

Uncaught (in promise) ClientAuthError: endpoints_resolution_error: Error: could not resolve endpoints. Please check network and try again. Detail: ClientAuthError: openid_config_error: Could not retrieve endpoints. Check your authority and verify the .well-known/openid-configuration endpoint returns the required endpoints. Attempted to retrieve endpoints from: https://login.microsoftonline.com/undefined/v2.0/.well-known/openid-configuration
    at t [as constructor] (_app-3866deb516d5bf6f9628.js:1)
    at new t (_app-3866deb516d5bf6f9628.js:1)
    at Function.t.createEndpointDiscoveryIncompleteError (_app-3866deb516d5bf6f9628.js:1)
    at Function.<anonymous> (_app-3866deb516d5bf6f9628.js:1)
    at _app-3866deb516d5bf6f9628.js:1
    at Object.throw (_app-3866deb516d5bf6f9628.js:1)
    at s (_app-3866deb516d5bf6f9628.js:1)

And here is the msal implementation:

import * as msal from "@azure/msal-browser";

function redirUri() {
    if (process.env.NODE_ENV == "development") {
        return "/"
    } else {
        return "https://somewebsitename.azurewebsites.net/"
    }
}

const msalConfig = {
    auth: {
        clientId: process.env.NEXT_PUBLIC_AZURE_AD_CLIENT_ID,
        authority: `https://login.microsoftonline.com/${process.env.NEXT_PUBLIC_AZURE_AD_TENANT_ID}`,
        redirectUri: redirUri()
    }
};

const msalInstance = new msal.PublicClientApplication(msalConfig);

export { msalInstance }

What is the correct way to do this?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can't get the app setting in Azure app service configuration. You can get the ClientID and tenant Id from your application configuration by doing this. process.env.clientId and process.env.tenantId

Ensure you have configured the following settings on the portal:

enter image description here

enter image description here

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!