You need to enable JavaScript to run this app. NextAuth配置Azure AD登录:本地环境正常但生产构建环境运行失效
优惠活动
大模型
产品
解决方案
定价
更多

NextAuth配置Azure AD登录:本地环境正常但生产构建环境运行失效

问题场景

使用 NextAuth 配置 Azure AD 登录功能,本地 localhost 开发环境下可正常使用,生产构建部署到线上环境后功能失效,运行时返回的报错信息如下:
运行时报错

当前自定义登录提供者配置

providers: [
{
  id: "msal",
  name: "Microsoft Login",
  type: "oauth",
  version: "2.0",
  scope: "https://graph.microsoft.com/user.read",
  params: { grant_type: "authorization_code" },
  accessTokenUrl: process.env.MSAL_TOKEN_ACCESS,
  requestTokenUrl: process.env.MSAL_TOKEN_REQUEST,
  authorizationUrl: process.env.MSAL_TOKEN_AUTHORIZE,
  profileUrl: "https://graph.microsoft.com/oidc/userinfo",
  profile: (profile) => {
    return {
      id: profile.sub,
      name: profile.name,
      last_name: profile.family_name,
      first_name: profile.given_name,
      email: profile.email,
    };
  },
  clientId: process.env.MS_CLIENT_ID,
  clientSecret: process.env.MS_CLIENT_SECRET,
},
],

内容的提问来源于stack exchange,提问作者Avner Russler

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.11.01 22:57:02