What steps are needed to enable Azure AD authentication using msal-browser for a Next.js application in a production environment?

While testing my implementation of msal on localhost, everything runs smoothly. However, once deployed to an Azure App Service, the clientId or tenantID values appear to become undefined. I even attempted hardcoding the id strings into the file but still encountered issues. The error that occurs when trying to click the login button in production is:

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)

Here is how the msal implementation looks:

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 }

How should I properly tackle this issue?

Answer №1

To access the app setting in Azure app service configuration, you will need to retrieve the ClientID and tenant Id from your application configuration using the process.env.clientId and process.env.tenantId parameters.

Make sure to configure the necessary settings on the portal by following these links:

https://i.sstatic.net/WdTcc.png

https://i.sstatic.net/ZkVrI.png

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

If the cursor hovers over an image, the onmouseover function does not work properly

Currently, I am developing a PHP page to display data from a database in a tabular format. Each column in the table represents an 'ATC Station'. When active, additional data is displayed upon hovering over the cell. Everything was running smooth ...

Having issues with NextJs not displaying the correct page upon loading (only showing / )

I've encountered an issue with my NextJs site hosted on AWS S3. Whenever I try to access a specific URL, like /blog, it directs me to the /index page instead of the proper page. How can I go about debugging this issue and resolving it? Any insights o ...

Three.js - Exploring the Significance of "THREE" within the THREE.scene Framework

Just starting out in JavaScript and experimenting with animations using three.js library. I'm trying to grasp the meaning behind: const scene = new THREE.Scene(); Why is the "THREE" necessary in THREE.Scene? Could we not simply write const scene = n ...

Authentication at the machine level

Every time I try to send a form to a different page on my ASP.NET website, it prompts me for windows authentication. Is there a way to disable this feature? ...

Checking if a module is loaded through dynamic route code splitting

One issue with code splitting is that when the module is large, the initial loading time may result in a blank screen and delay for the user. function errorLoading(err) { console.error('Dynamic page loading failed', err); } fu ...

Is there a method to stop react-select (Select.Async) from erasing the search input value when it loses focus?

Situation: In my setup, I have a standard select element (categories), which dictates the options displayed in a Select.Async component from react-select. Problem: Consider this scenario: a user is searching for an option within Select.Async whil ...

AngularJS chatbox widget for interactive communication

Currently, I am in the process of developing the back-end for a web application utilizing angularJS. One of the key features is allowing users to communicate with each other through a pop-up chat box similar to those found in Gmail or Facebook. My goal is ...

How can you customize the appearance of the filledInput component within a TextField component in Material UI?

I need some guidance on how to change the color of the FilledInput component within a TextField. Unlike InputProps, FilledInputProps are not directly accessible for styling with classes. Any suggestions on how I can customize the styling of the FilledInpu ...

Having difficulty passing the new state value using props in ReactJS

I am facing an issue with sending state values from parent to child components. Initially, the state value is empty but after making an API call, the state value gets updated. However, the props in my child component are still stuck with the initial empty ...

What sets apart a string constant from a string enclosed in quotation marks? And what techniques exist to transform one into the other?

Calling an asynchronous function: const variable = 'something' await MyAsyncFunction.execute(variable) No output is displayed. But if I change it to: await MyAsyncFunction.execute('something') It works!! Can someone please explain h ...

Tips for accessing and adjusting an ngModel that is populated by an attribute assigned via ngFor

Looking for guidance on how to modify an input with ngModel attribute derived from ngFor, and update its value in the component. Here is my code snippet for reference: HTML FRONT The goal here is to adjust [(ngModel)] = "item.days" based on button click ...

The AJAX request sends the <div> element instead of the <button> element

I'm puzzled as to why this ajax call is passing the div id instead of the button id that I intended. <?php while($info = mysqli_fetch_array($sql)) { echo "<tr> <th>" .$info[& ...

The CSS classes for the dropzonejs are not being properly updated for editing purposes

I'm currently facing an issue where I am attempting to include an editable area inside a dropzone, but for some reason, the editable area is not visible within the dropzone and the CSS classes are not being applied. <a href="#" editable-text="us ...

Utilizing Jest to Mock a jQuery Method within a Promise

I have created a function that utilizes a jQuery function named dataFunc, which is expected to return an object. Instead of testing the dataFunc function itself, I want to focus on testing the promise it produces. To achieve this, I need to mock the respo ...

Is there a way to modify the code of a component in react so that it retrieves the data as an array?

I am currently facing an issue where I can only upload a single image using this component. Is there a way to modify my code so that I can upload multiple images by simply dragging and dropping them? Below is the code for my component: import React, { us ...

Generate - Create 2 different versions of the web application

Currently, I am in the process of learning Grunt and exploring ways to generate 2 variations of an application with different configuration settings. My goal is to have one version where a boolean in a specific .js file is set to false, and another versio ...

Ways to position loading animation in the center and create a lightbox effect for the rest of the page

I have implemented a custom loader in CSS with the following styles: .loader { border: 16px solid #f3f3f3; /* Light grey */ border-top: 16px solid #3498db; /* Blue */ border-radius: 50%; width: 80px; height: 80px; animation: spin 2s linear inf ...

Viewing an immutable concealed field in Angular

My situation is quite unique as I have an Angular app embedded within a legacy ASP.NET webforms app (specifically in the header and footer). Authentication still happens through Webforms without any token service in place. The challenge arises when Angula ...

Angular 2, React, or any other modern framework.getList()?.map

I have experience working on multiple angular 1 projects and I absolutely enjoyed it. We have several upcoming projects where I need to recommend JavaScript frontend libraries/frameworks. With the decline of angular 1 and mixed reviews about angular 2&apos ...

How come .trim() isn't cooperating with me?

I am encountering an issue with this particular piece of javascript. Every time I attempt to use it, nothing is displayed in my div. Instead, it simply adds ?weight=NumberInputed&measure=lbsOrkgs&submit=Submit to the URL. <h2>What size d ...