Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting ClientAuthError: endpoints_resolution_error: Error: could not resolve endpoints with @azure/msal-node 1.9.1 #4879

Closed
awanlin opened this issue Jun 9, 2022 · 84 comments · Fixed by #5722
Assignees
Labels
bug A problem that needs to be fixed for the feature to function as intended. msal-node Related to msal-node package tracked-internally Bugs that are tracked by Msft internally

Comments

@awanlin
Copy link

awanlin commented Jun 9, 2022

Core Library

MSAL Node (@azure/msal-node)

Core Library Version

1.9.1

Wrapper Library

Not Applicable

Wrapper Library Version

None

Description

Since upgrading from 1.9.0 to 1.9.1 we are running into the error listed in this issue below. We have a node application that runs on an interval to update profile pictures in Backstage a Developer Portal we are using. It's very simple.

Rolling back to 1.9.0 the error goes away. I'm not sure what specifically is causing this issue but I feel like it is something in PR #4744. That being said there might be simply something that we need to include to resolve this like some additional configuration.

Any help with this would be greatly appreciated!

Error Message

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/{tenantId}/v2.0/.well-known/openid-configuration

Note that {tenantId} in the URL above is our actual tenantId, just removed for security reasons.

Msal Logs

No response

MSAL Configuration

const clientConfig = {
      auth: {
        clientId,
        clientSecret,
        authority: `https://login.microsoftonline.com/${tenantId}`,
      },
    };

Relevant Code Snippets

const clientConfig = {
      auth: {
        clientId,
        clientSecret,
        authority: `https://login.microsoftonline.com/${tenantId}`,
      },
    };

    const authClient = new ConfidentialClientApplication(clientConfig);

    const tokens = await authClient.acquireTokenByClientCredential({
      scopes: ['https://graph.microsoft.com/.default'],
    });

Reproduction Steps

I'm not totally sure how to describe this:

  1. Upgrade to @azure/msal-node 1.9.1
  2. Run the application

Notice in the logs the error listed in this issue occurs

Expected Behavior

There should be no error and the process should continue to work as it did with version 1.9.0

Identity Provider

Azure AD / MSA

Browsers Affected (Select all that apply)

None (Server)

Regression

@azure/msal-node 1.9.0

Source

External (Customer)

@awanlin awanlin added bug-unconfirmed A reported bug that needs to be investigated and confirmed question Customer is asking for a clarification, use case or information. labels Jun 9, 2022
@ghost ghost assigned jasonnutter Jun 9, 2022
@ghost ghost added the Needs: Attention 👋 Awaiting response from the MSAL.js team label Jun 9, 2022
@github-actions github-actions bot added the msal-node Related to msal-node package label Jun 9, 2022
@awanlin
Copy link
Author

awanlin commented Jun 9, 2022

@Robbie-Microsoft I noticed you worked on #4744, do you have any idea why I would be running into this error?

@jasonnutter
Copy link
Contributor

@awanlin Thanks for the information. Are you using a network proxy?

@ghost ghost added answered Question has received "first qualified response" Needs: Author Feedback Awaiting response from issue author and removed Needs: Attention 👋 Awaiting response from the MSAL.js team labels Jun 10, 2022
@jasonnutter jasonnutter added the bug A problem that needs to be fixed for the feature to function as intended. label Jun 10, 2022
@ghost ghost removed bug-unconfirmed A reported bug that needs to be investigated and confirmed question Customer is asking for a clarification, use case or information. answered Question has received "first qualified response" Needs: Author Feedback Awaiting response from issue author labels Jun 10, 2022
@Alekhyasingi
Copy link

Alekhyasingi commented Jun 13, 2022

@jasonnutter I saw an ongoing issue which states the setup isn't working on network proxy but I am not using any proxies right now and it stopped working on my servers recently with the same error as mentioned above. My implementation is almost similar to what it is stated here. But version is 1.8.0 which I had to re install for some other reasons.

@awanlin
Copy link
Author

awanlin commented Jun 13, 2022

@jasonnutter no, I'm not using a network proxy, our setup is very simple

@jasonnutter jasonnutter assigned hectormmg and unassigned jasonnutter Jun 13, 2022
@jasonnutter
Copy link
Contributor

cc @EmLauber

@EmLauber EmLauber added the tracked-internally Bugs that are tracked by Msft internally label Jun 15, 2022
@marco-bertelli
Copy link

same issue here any news? @jasonnutter ?

@hectormmg
Copy link
Member

I'm trying to reproduce the issue so I can figure out what's wrong. I'll update this issue once I have more information.

@hectormmg
Copy link
Member

@awanlin can you reproduce this issue locally in development? Or does in only happen in production?

@awanlin
Copy link
Author

awanlin commented Jun 16, 2022

@hectormmg, I ran into this error both on my local environment and once deployed to our development environment, it did not go to staging or production once I noticed the errors I cancelled the deployment. This code is in a plugin that is part of our Backstage developer portal which runs in a Docker container and deployed to AWS.

I'd be willing to share the entire code with you in some secure fashion if that helps you?

@awanlin
Copy link
Author

awanlin commented Jun 29, 2022

@hectormmg, any updates on this? Thanks in advance!

@hectormmg
Copy link
Member

@awanlin apologies for the delay, we have been investigating a possibly related issue with msal-node's network module that may be affecting the way network and HTTP errors are reported. Will update this issue when we have more information.

@awanlin
Copy link
Author

awanlin commented Jul 26, 2022

Just wanted to check in to see if there was any update on this?

We have tried using version 1.12.0 of @azure/msal-node but we still get the same error

@mudaser85
Copy link

As @awanlin mentioned, this is not working for us too. We have a very simple environment and this is the error we are receiving.
"errorCode":"endpoints_resolution_error","errorMessage":"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://undefined/organizations/v2.0/.well-known/openid-configuration","subError":"","name":"ClientAuthError"}

Any updates?

@jsbinette
Copy link

Error is still there on 1.12.1

@Robbie-Microsoft
Copy link
Collaborator

Robbie-Microsoft commented Feb 7, 2023

@jsbinette, @bgavrilMS sent me the files from your app that you sent him, so I've taken a look at your app. Based on what I saw, the only thing I can see different is that you're running your confidential client methods (acquireTokenByClientCredential) in express routes. I wrote my own express app and was unable to reproduce your issue.

So I've done the following: I've updated the custom-INetworkModule-and-network-tracing sample so that it now supports an express server and running confidential client requests via express routes. Additionally, I added a custom axios http client that can be used instead of the existing http client - we used to use axios before I updated the http client to move away from axios because it didn't function that well when run behind a proxy.

My ask to you, if you have time and are willing: play with this updated sample - copy a skeleton of your express app into this sample and run it (once with the existing http client and once with the axios http client), and see if you are still experiencing the same error. If you receive the same error with the axios http client, I suspect there is a problem in your configuration.

@cheenamalhotra
Copy link

cheenamalhotra commented Feb 23, 2023

I'm facing similar issue with v1.15.0.. tried everything from comments above, but nothing seems to work. I also incorporated the custom INetworkModule from samples, but still no luck. Here's my log, my codebase is opensource so I can share as well.. it's a VS Code extension.. link to my config >> error triggers here

[Information]: Authority URL set to: https://login.microsoftonline.com/organizations - []
[Information]: [Thu, 23 Feb 2023 13:35:37 GMT] : @azure/[email protected] : Info - acquireTokenByDeviceCode called - []
[Verbose]: [Thu, 23 Feb 2023 13:35:37 GMT] : @azure/[email protected] : Verbose - initializeRequestScopes called - []
[Verbose]: [Thu, 23 Feb 2023 13:35:37 GMT] : [710b563e-4e25-4cec-aed6-7670724f6d53] : @azure/[email protected] : Verbose - buildOauthClientConfiguration called - []
[Verbose]: [Thu, 23 Feb 2023 13:35:37 GMT] : [710b563e-4e25-4cec-aed6-7670724f6d53] : @azure/[email protected] : Verbose - building oauth client configuration with the authority: https://login.microsoftonline.com/organizations - []
[Verbose]: [Thu, 23 Feb 2023 13:35:37 GMT] : [710b563e-4e25-4cec-aed6-7670724f6d53] : @azure/[email protected] : Verbose - createAuthority called - []
[Verbose]: [Thu, 23 Feb 2023 13:35:37 GMT] : @azure/[email protected] : Trace - Retrieving all cache keys - []
[Verbose]: [Thu, 23 Feb 2023 13:35:37 GMT] : @azure/[email protected] : Trace - Getting cache key-value store - []
[Verbose]: [Thu, 23 Feb 2023 13:35:37 GMT] : @azure/[email protected] : Verbose - Attempting to get cloud discovery metadata in the config - []
[Verbose]: [Thu, 23 Feb 2023 13:35:37 GMT] : @azure/[email protected] : Verbose - Did not find cloud discovery metadata in the config... Attempting to get cloud discovery metadata from the cache. - []
[Verbose]: [Thu, 23 Feb 2023 13:35:37 GMT] : @azure/[email protected] : Verbose - Did not find cloud discovery metadata in the cache... Attempting to get cloud discovery metadata from the network. - []
[Error]: [Thu, 23 Feb 2023 13:35:37 GMT] : @azure/[email protected] : Error - A non-MSALJS error was thrown while attempting to get the cloud instance discovery metadata.
Error: TypeError
Error Description: The "listener" argument must be of type function. Received an instance of Object - []
[Verbose]: [Thu, 23 Feb 2023 13:35:37 GMT] : @azure/[email protected] : Verbose - Did not find cloud discovery metadata from the network... Attempting to get cloud discovery metadata from hardcoded values. - []
[Verbose]: [Thu, 23 Feb 2023 13:35:37 GMT] : @azure/[email protected] : Verbose - Found cloud discovery metadata from hardcoded values. - []
[Verbose]: [Thu, 23 Feb 2023 13:35:37 GMT] : @azure/[email protected] : Trace - Getting cache key-value store - []
[Verbose]: [Thu, 23 Feb 2023 13:35:37 GMT] : @azure/[email protected] : Trace - Getting cache key-value store - []
[Verbose]: [Thu, 23 Feb 2023 13:35:37 GMT] : @azure/[email protected] : Trace - Setting cache key value store - []
[Error]: Login failed: 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://undefined/organizations/v2.0/.well-known/openid-configuration - []
[Error]: 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://undefined/organizations/v2.0/.well-known/openid-configuration - []

Unclear why authority URL is not being respected even though it's received by buildOauthClientConfiguration correctly... would appreciate any tips!

@cheenamalhotra
Copy link

It seems to get fixed by updating the below dependencies:

Before (fails):

    "http-proxy-agent": "^2.1.0",
    "https-proxy-agent": "^2.2.1"

After (works):

    "http-proxy-agent": "^5.0.0",
    "https-proxy-agent": "^5.0.0",

Thanks @bgavrilMS and @Robbie-Microsoft for the hint :)

@Robbie-Microsoft Robbie-Microsoft linked a pull request Feb 24, 2023 that will close this issue
@Robbie-Microsoft
Copy link
Collaborator

@cheenamalhotra thanks so much for our debugging session today! I believe I've identified the root cause of the issue and have linked the PR with a fix.

@chanphillip
Copy link

My node backend suddently stopped working today (1/3/2023) and showed the error mentioned here. Any workaround for now? also any schedule for the update release? Thank you

@Robbie-Microsoft
Copy link
Collaborator

@chanphillip The linked PR should be in next Monday's (March 6, 2023) build.

@Robbie-Microsoft
Copy link
Collaborator

@chanphillip The linked PR should be in next Monday's (March 6, 2023) build.

We had to push back yesterday's (March 6, 2023) monthly release to today (March 7, 2023), there was an issue with a PR that had to go out.

@jsbinette
Copy link

@Robbie-Microsoft works! with 1.16.0. THANK YOU!

@bgavrilMS
Copy link
Member

Big thanks to @cheenamalhotra for finding a consistent repro for this and to @Robbie-Microsoft for figuring out a fix.

@baelene
Copy link

baelene commented Jul 6, 2023

Hello,

I still have this issue.

In my package.json

     "@azure/msal-node": "1.18.0", //I've tried with 14, 16 and 17
    "http-proxy-agent": "^5.0.0",
    "https-proxy-agent": "^5.0.0"

My config

const azureAdConfig = {
auth: {
clientId: module.config.azure.clientId,
authority: https://login.microsoftonline.com/${module.config.azure.tenantId},
clientSecret: module.config.azure.clientSecret,
knownAuthorities: [https://login.microsoftonline.com/${module.config.azure.tenantId}]
},
system: {
loggerOptions: {
loggerCallback(loglevel, message, containsPii) {
console.log(message);
},
piiLoggingEnabled: false,
logLevel: msal.LogLevel.Verbose,
},
proxyUrl: module.config.azure.proxyUrl
}
};

My server log:

[Thu, 06 Jul 2023 11:13:49 GMT] : @azure/[email protected] : Info - getAuthCodeUrl called
[Thu, 06 Jul 2023 11:13:49 GMT] : @azure/[email protected] : Verbose - initializeRequestScopes called
[Thu, 06 Jul 2023 11:13:49 GMT] : [7ffb7816-8a7e-4a3e-8d53-93a8ad2ecbc5] : @azure/[email protected] : Verbose - buildOauthClientConfiguration called
[Thu, 06 Jul 2023 11:13:49 GMT] : [7ffb7816-8a7e-4a3e-8d53-93a8ad2ecbc5] : @azure/[email protected] : Verbose - building oauth client configuration with the authority: https://lod8c210-54c7-4039-a88b-4417f80773fe
[Thu, 06 Jul 2023 11:13:49 GMT] : [7ffb7816-8a7e-4a3e-8d53-93a8ad2ecbc5] : @azure/[email protected] : Verbose - createAuthority called
[Thu, 06 Jul 2023 11:13:49 GMT] : @azure/[email protected] : Verbose - Attempting to get cloud discovery metadata in the config
[Thu, 06 Jul 2023 11:13:49 GMT] : @azure/[email protected] : Verbose - The host is included in knownAuthorities. Creating new cloud discovery metadata from the host.
[Thu, 06 Jul 2023 11:13:49 GMT] : @azure/[email protected] : Verbose - Found cloud discovery metadata in the config.
ClientAuthError: endpoints_resolution_error: Error: could not resolve endpoints. Please check network and try again. Detail: ClientAuthError: openid_config_error: Could not retr authority and verify the .well-known/openid-configuration endpoint returns the required endpoints. Attempted to retrieve endpoints from: https://login.microsoftonline.com/$mytenantId/v2.0/.well-known/openid-configuration
at ClientAuthError.AuthError [as constructor] (/Users/eric/dev/ecosys/ecosys-src/ecosys-core-frontend/node_modules/@azure/msal-common/dist/index.cjs.js:499:24)
at new ClientAuthError (/Users/eric/dev/ecosys/ecosys-src/ecosys-core-frontend/node_modules/@azure/msal-common/dist/index.cjs.js:819:28)
at Function.ClientAuthError.createEndpointDiscoveryIncompleteError (/Users/eric/dev/ecosys/ecosys-src/ecosys-core-frontend/node_modules/@azure/msal-common/dist/index.cjs.js:
at Function. (/Users/eric/dev/ecosys/ecosys-src/ecosys-core-frontend/node_modules/@azure/msal-common/dist/index.cjs.js:8391:47)
at step (/Users/eric/dev/ecosys/ecosys-src/ecosys-core-frontend/node_modules/@azure/msal-common/dist/index.cjs.js:79:23)
at Object.throw (/Users/eric/dev/ecosys/ecosys-src/ecosys-core-frontend/node_modules/@azure/msal-common/dist/index.cjs.js:60:53)
at rejected (/Users/eric/dev/ecosys/ecosys-src/ecosys-core-frontend/node_modules/@azure/msal-common/dist/index.cjs.js:51:65)
at processTicksAndRejections (internal/process/task_queues.js:95:5) {
errorCode: 'endpoints_resolution_error',
errorMessage: 'Error: could not resolve endpoints. Please check network and try again. Detail: ClientAuthError: openid_config_error: Could not retrieve endpoints. Check your aell-known/openid-configuration endpoint returns the required endpoints. Attempted to retrieve endpoints from: https://login.microsoftonline.com/$mytenantId-configuration',
subError: ''

And IN my proxy, it's look like microsoftonline close the connection with a 302

URL: http://login.microsoftonline.com/$mytenantId/v2.0/.well-known/openid-configuration
Status: Redirect
Response Code: 302 Found
Method: GET
Content Type: -

Content-Length: 0
Location: https://login.microsoftonline.com:443/$mytenantId/v2.0/.well-known/openid-configuration
client-request-id: 81204f1b-f103-4066-8c03-c98294d230db
Date: Thu, 06 Jul 2023 11:13:49 GMT
Connection: close

If I curl same the URL with my proxy, I receive a 200 with the correct payload.

Thank you for your help

@ghost
Copy link

ghost commented Aug 30, 2023

I am facing this issue with a network proxy, and can't seem to get past it in any way at all. It works fine in development but fails when pushed to production.

@thetminko
Copy link

I am getting the same issue with v1.18.2.

class Test {

  constructor() {
    const config: Configuration = {
      auth: {
        clientId,
        authority,
        clientCertificate: {
          thumbprint,
          privateKey
        }
      },
      system: {
        proxyUrl,
        loggerOptions: {
          loggerCallback: (level: LogLevel, message) => {
            // If (level === LogLevel.Info) {
            this.logger.info(message);
            // }
          },
          logLevel: LogLevel.Verbose
        }
      }
    };

    this.client = new ConfidentialClientApplication(config);
  }

  getAuthUrl() {
    const { state, nonce } = req;
    const { redirectUri } = this.options;
    return this.client.getAuthCodeUrl({ scopes, redirectUri, state, nonce });
  }

  async getIdToken(req: any) {
    const { code } = req;
    const { redirectUri } = this.options;
    const tokens = await this.client.acquireTokenByCode({ code, scopes, redirectUri });
  }

}
2023-09-06T20:44:07.240+08:00	2023-09-06 20:44:07 [info] [gG8cw1xo] [POST /auth/api/login/request] [aadService]: [Wed, 06 Sep 2023 12:44:07 GMT] : @azure/[email protected] : Info - getAuthCodeUrl called

2023-09-06T20:44:07.240+08:00	2023-09-06 20:44:07 [info] [gG8cw1xo] [POST /auth/api/login/request] [aadService]: [Wed, 06 Sep 2023 12:44:07 GMT] : @azure/[email protected] : Verbose - initializeRequestScopes called

2023-09-06T20:44:07.241+08:00	2023-09-06 20:44:07 [info] [gG8cw1xo] [POST /auth/api/login/request] [aadService]: [Wed, 06 Sep 2023 12:44:07 GMT] : [09b965f1-a14d-4b4c-91cf-a18a75a5ac97] : @azure/[email protected] : Verbose - buildOauthClientConfiguration called

2023-09-06T20:44:07.241+08:00	2023-09-06 20:44:07 [info] [gG8cw1xo] [POST /auth/api/login/request] [aadService]: [Wed, 06 Sep 2023 12:44:07 GMT] : [09b965f1-a14d-4b4c-91cf-a18a75a5ac97] : @azure/[email protected] : Verbose - building oauth client configuration with the authority: https://login.microsoftonline.com/{tenantId}

2023-09-06T20:44:07.241+08:00	2023-09-06 20:44:07 [info] [gG8cw1xo] [POST /auth/api/login/request] [aadService]: [Wed, 06 Sep 2023 12:44:07 GMT] : [09b965f1-a14d-4b4c-91cf-a18a75a5ac97] : @azure/[email protected] : Verbose - createAuthority called

2023-09-06T20:44:07.243+08:00	2023-09-06 20:44:07 [info] [gG8cw1xo] [POST /auth/api/login/request] [aadService]: [Wed, 06 Sep 2023 12:44:07 GMT] : @azure/[email protected] : Verbose - Attempting to get cloud discovery metadata in the config

2023-09-06T20:44:07.243+08:00	2023-09-06 20:44:07 [info] [gG8cw1xo] [POST /auth/api/login/request] [aadService]: [Wed, 06 Sep 2023 12:44:07 GMT] : @azure/[email protected] : Verbose - Did not find cloud discovery metadata in the config... Attempting to get cloud discovery metadata from the cache.

2023-09-06T20:44:07.244+08:00	2023-09-06 20:44:07 [info] [gG8cw1xo] [POST /auth/api/login/request] [aadService]: [Wed, 06 Sep 2023 12:44:07 GMT] : @azure/[email protected] : Verbose - Did not find cloud discovery metadata in the cache... Attempting to get cloud discovery metadata from the network.

2023-09-06T20:44:07.412+08:00	2023-09-06 20:44:07 [info] [gG8cw1xo] [POST /auth/api/login/request] [aadService]: [Wed, 06 Sep 2023 12:44:07 GMT] : @azure/[email protected] : Warning - A CloudInstanceDiscoveryErrorResponse was returned. The cloud instance discovery network request's status code is: NaN

2023-09-06T20:44:07.412+08:00	2023-09-06 20:44:07 [info] [gG8cw1xo] [POST /auth/api/login/request] [aadService]: [Wed, 06 Sep 2023 12:44:07 GMT] : @azure/[email protected] : Warning - The CloudInstanceDiscoveryErrorResponse error is unknown_error

2023-09-06T20:44:07.412+08:00	2023-09-06 20:44:07 [info] [gG8cw1xo] [POST /auth/api/login/request] [aadService]: [Wed, 06 Sep 2023 12:44:07 GMT] : @azure/[email protected] : Warning - The CloudInstanceDiscoveryErrorResponse error description is An unknown error occured.

2023-09-06T20:44:07.412+08:00	Http status code: NaN

2023-09-06T20:44:07.412+08:00	Http status message: Unknown

2023-09-06T20:44:07.412+08:00	Headers: {}

2023-09-06T20:44:07.412+08:00	2023-09-06 20:44:07 [info] [gG8cw1xo] [POST /auth/api/login/request] [aadService]: [Wed, 06 Sep 2023 12:44:07 GMT] : @azure/[email protected] : Warning - Setting the value of the CloudInstanceDiscoveryMetadata (returned from the network) to []

2023-09-06T20:44:07.412+08:00	2023-09-06 20:44:07 [info] [gG8cw1xo] [POST /auth/api/login/request] [aadService]: [Wed, 06 Sep 2023 12:44:07 GMT] : @azure/[email protected] : Verbose - Attempting to find a match between the developer's authority and the CloudInstanceDiscoveryMetadata returned from the network request.

2023-09-06T20:44:07.413+08:00	2023-09-06 20:44:07 [info] [gG8cw1xo] [POST /auth/api/login/request] [aadService]: [Wed, 06 Sep 2023 12:44:07 GMT] : @azure/[email protected] : Warning - The developer's authority was not found within the CloudInstanceDiscoveryMetadata returned from the network request.

2023-09-06T20:44:07.413+08:00	2023-09-06 20:44:07 [info] [gG8cw1xo] [POST /auth/api/login/request] [aadService]: [Wed, 06 Sep 2023 12:44:07 GMT] : @azure/[email protected] : Verbose - Creating custom Authority for custom domain scenario.

2023-09-06T20:44:07.413+08:00	2023-09-06 20:44:07 [info] [gG8cw1xo] [POST /auth/api/login/request] [aadService]: [Wed, 06 Sep 2023 12:44:07 GMT] : @azure/[email protected] : Verbose - cloud discovery metadata was successfully returned from getCloudDiscoveryMetadataFromNetwork()

2023-09-06T20:44:07.574+08:00	2023-09-06 20:44:07 [error] [gG8cw1xo] [POST /auth/api/login/request] [Responder]: 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/{tenantId}/v2.0/.well-known/openid-configuration

2023-09-06T20:44:07.574+08:00	at ClientAuthError.AuthError [as constructor] (/apps/app/app-backend/node_modules/@azure/msal-common/dist/index.cjs.js:499:24)

2023-09-06T20:44:07.574+08:00	at new ClientAuthError (/apps/app/app-backend/node_modules/@azure/msal-common/dist/index.cjs.js:819:28)

2023-09-06T20:44:07.574+08:00	at ClientAuthError.createEndpointDiscoveryIncompleteError (/apps/app/app-backend/node_modules/@azure/msal-common/dist/index.cjs.js:856:16)

2023-09-06T20:44:07.574+08:00	at Function.<anonymous> (/apps/app/app-backend/node_modules/@azure/msal-common/dist/index.cjs.js:8395:47)

2023-09-06T20:44:07.574+08:00	at step (/apps/app/app-backend/node_modules/@azure/msal-common/dist/index.cjs.js:79:23)

2023-09-06T20:44:07.574+08:00	at Object.throw (/apps/app/app-backend/node_modules/@azure/msal-common/dist/index.cjs.js:60:53)

2023-09-06T20:44:07.574+08:00	at rejected (/apps/app/app-backend/node_modules/@azure/msal-common/dist/index.cjs.js:51:65)

2023-09-06T20:44:07.574+08:00	at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Any idea what could be the problem?

@Robbie-Microsoft
Copy link
Collaborator

@thetminko Please upgrade your msal-node version from 1.18.2 to 2.1.0. If your issue still persists, then please create a new issue.

@oshihirii
Copy link

oshihirii commented Nov 8, 2023

I am getting the same 500 error when trying to call an Azure Function in local development environment from Postman:

endpoints_resolution_error: Endpoints cannot be resolved.

Calling the live function endpoint works fine.

package.json:

{
  "name": "",
  "version": "1.0.0",
  "description": "",
  "main": "src/functions/*.js",
  "scripts": {
    "start": "func start",
    "test": "echo \"No tests yet...\""
  },
  "dependencies": {
    "@azure/functions": "^4.0.0-alpha.1",
    "@azure/msal-node": "^2.5.1",
    "axios": "^1.6.0"
  },
  "devDependencies": {
    "azure-functions-core-tools": "^4.x"
  }
}

Node.js, using v4 programming model in Azure Functions.

Relevant function code:

const msal = require('@azure/msal-node');  
const axios = require('axios');

const msal_config = {
    auth: {
        clientId: process.env["azure_ad_app_registration_client_id"],
        authority: `https://login.microsoftonline.com/${process.env["azure_ad_app_registration_tenant_id"]}`,
        clientSecret: process.env["azure_ad_app_registration_client_secret"],
    }
};

const cca = new msal.ConfidentialClientApplication(msal_config);

const clientCredentialRequest = {
    scopes: ["https://graph.microsoft.com/.default"],
};
const response = await cca.acquireTokenByClientCredential(clientCredentialRequest);

const token = response.accessToken;

// context.log is broken in Azure Functions, it's not synchronous, apparently this has been a known issue for a long time    
// https://github.com/Azure/azure-functions-host/issues/9238
// apparently this is a fix available in this pull request:
// https://github.com/Azure/azure-functions-host/pull/9657
context.log('token'):
context.log(token):

return { jsonBody: {"some_key": "some value"} }

@oshihirii
Copy link

oshihirii commented Nov 9, 2023

In case it helps anyone, an update to my last message...

I had been troubleshooting this for two days.

I stripped down all my function code, and the only thing that was causing the error was getting the token.

So I asked myself:

'Why can't i get a token from my local computer'?

I created a GET request in Postman to get a token with the details below, and the token came back immediately.

So there were no invisible reasons (network/security etc) for not being able to get a token from my computer.

The settings for the request were:

POST URI:  
https://login.microsoftonline.com/<my-tenant-id>/oauth2/v2.0/token

Headers:  
Content-Type: application/x-www-form-urlencoded

Body (x-www-form-url-encoded):  
client_id:  <my_app_registration_client_id>
client_secret:  <my_app_registration_secret>
scope:  https://graph.microsoft.com/.default
grant_type:  client_credentials

After that, I started up the local function again with func start and it started up A LOT faster.

I then made a call to the local function endpoint and got a response almost immediately.

So, something in the process of getting a token (outside of the function context) 'freed up' the code in the function to work correctly and to be able to retrieve and use a token.

EDIT 01:

24 hours later, without changing any code, tried calling the local function endpoint again and I get the same 500 error as before:

"endpoints_resolution_error: Endpoints cannot be resolved"

This time, trying to get a token in Postman just to 'make it work' isn't working like it did yesterday.

EDIT 02:

I use Starlink, I swtiched to using a VPN and the error went away and func start starts up A LOT faster.

I have no idea why using Starlink would prevent msal-node from being able to get a token to use with Microsoft Graph.

@chrishiestand
Copy link

I had this problem and couldn't figure out the cause until I tried upgrading node.js from v14 to v16+. After doing more testing with node v18 it seems to be working fine. Although I didn't see it documented in the javascript sdk documentation, @azure/[email protected]'s package.json states it requires node >= 18.0.0.

So another potential fix: upgrade node.js.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A problem that needs to be fixed for the feature to function as intended. msal-node Related to msal-node package tracked-internally Bugs that are tracked by Msft internally
Projects
None yet
Development

Successfully merging a pull request may close this issue.