在 nodejs 后端使用 msal 时出错
Getting an error when using msal in a nodejs backend
我下载了 Web 应用程序 (NodeJs) 的示例代码 from here 并将配置参数替换为我的应用程序的值。像这样:
const config = {
auth: {
clientId: "12345678901234567890",
authority: "https://login.microsoftonline.com/09876543210987654321",
clientSecret: "*****************",
knownAuthorities: ["https://login.microsoftonline.com/09876543210987654321"
]
},
当我 运行 应用程序时,我得到以下信息:
[Wed, 17 Mar 2021 17:30:24 GMT] : : @azure/msal-node@1.0.0 : Info - getAuthCodeUrl called
[Wed, 17 Mar 2021 17:30:24 GMT] : : @azure/msal-node@1.0.0 : Verbose - initializeRequestScopes called
[Wed, 17 Mar 2021 17:30:24 GMT] : : @azure/msal-node@1.0.0 : Verbose - buildOauthClientConfiguration called
[Wed, 17 Mar 2021 17:30:24 GMT] : : @azure/msal-node@1.0.0 : Verbose - createAuthority called
[Wed, 17 Mar 2021 17:30:24 GMT] : : @azure/msal-node@1.0.0 : Verbose - Retrieving all cache keys
[Wed, 17 Mar 2021 17:30:24 GMT] : : @azure/msal-node@1.0.0 : Verbose - Getting cache key-value store
{"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://login.microsoftonline.com/09876543210987654321/v2.0/.well-known/openid-configuration","subError":"","name":"ClientAuthError"}
我不知道为什么会收到错误消息,我没有连接到 VPN 或仅使用代理连接到我的常规 ISP。
确保您已在门户上配置以下设置。
提示
如果我的方案没有生效,请打开浏览器进入隐私模式试试,排除浏览器缓存的因素。如果还是不行,多刷新几次
我项目中的代码
index.js 文件。
auth: {
clientId: "clientID",
authority: "https://login.microsoftonline.com/tenantID",
clientSecret: "yoursecret",
knownAuthorities: ["https://login.microsoftonline.com/tenantID"]
},
对我有用
就我而言,这是自签名证书的问题。我的应用程序试图调用 '.well-known/openid-configuration' GET 端点,但它被阻止了。解决方法是将 "NODE_TLS_REJECT_UNAUTHORIZED": "0" 添加到我的环境变量中。
我下载了 Web 应用程序 (NodeJs) 的示例代码 from here 并将配置参数替换为我的应用程序的值。像这样:
const config = {
auth: {
clientId: "12345678901234567890",
authority: "https://login.microsoftonline.com/09876543210987654321",
clientSecret: "*****************",
knownAuthorities: ["https://login.microsoftonline.com/09876543210987654321"
]
},
当我 运行 应用程序时,我得到以下信息:
[Wed, 17 Mar 2021 17:30:24 GMT] : : @azure/msal-node@1.0.0 : Info - getAuthCodeUrl called
[Wed, 17 Mar 2021 17:30:24 GMT] : : @azure/msal-node@1.0.0 : Verbose - initializeRequestScopes called
[Wed, 17 Mar 2021 17:30:24 GMT] : : @azure/msal-node@1.0.0 : Verbose - buildOauthClientConfiguration called
[Wed, 17 Mar 2021 17:30:24 GMT] : : @azure/msal-node@1.0.0 : Verbose - createAuthority called
[Wed, 17 Mar 2021 17:30:24 GMT] : : @azure/msal-node@1.0.0 : Verbose - Retrieving all cache keys
[Wed, 17 Mar 2021 17:30:24 GMT] : : @azure/msal-node@1.0.0 : Verbose - Getting cache key-value store
{"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://login.microsoftonline.com/09876543210987654321/v2.0/.well-known/openid-configuration","subError":"","name":"ClientAuthError"}
我不知道为什么会收到错误消息,我没有连接到 VPN 或仅使用代理连接到我的常规 ISP。
确保您已在门户上配置以下设置。
提示
如果我的方案没有生效,请打开浏览器进入隐私模式试试,排除浏览器缓存的因素。如果还是不行,多刷新几次
我项目中的代码
index.js 文件。
auth: {
clientId: "clientID",
authority: "https://login.microsoftonline.com/tenantID",
clientSecret: "yoursecret",
knownAuthorities: ["https://login.microsoftonline.com/tenantID"]
},
对我有用
就我而言,这是自签名证书的问题。我的应用程序试图调用 '.well-known/openid-configuration' GET 端点,但它被阻止了。解决方法是将 "NODE_TLS_REJECT_UNAUTHORIZED": "0" 添加到我的环境变量中。