简体   繁体   English

如何使用 next-auth 获取额外的 scope 数据?

[英]How to get additional scope data using next-auth?

I am using next-auth with discord authentication, I added the guilds to my scope but I am not able to get the guild data, how can this be done?我正在使用带有 discord 身份验证的 next-auth,我将公会添加到我的 scope 但我无法获取公会数据,这怎么办?

const options = {
  providers: [
    Providers.Discord({
      clientId: process.env.DISCORD_CLIENT_ID,
      clientSecret: process.env.DISCORD_CLIENT_SECRET,
      scope: "identify guilds",
    }),
  ],
};

Also ran into this using the Discord OAuth2.还使用 Discord OAuth2 遇到了这个问题。 I found it in NextAuth's docs here:我在 NextAuth 的文档中找到了它:

https://next-auth.js.org/configuration/providers#oauth-provider-options https://next-auth.js.org/configuration/providers#oauth-provider-options

Basically, you add scope as a general option after the provider array.基本上,您在 provider 数组之后添加范围作为一般选项。

providers: [
  Providers.Discord({
    clientId: process.env.DISCORD_CLIENT_ID,
    clientSecret: process.env.DISCORD_CLIENT_SECRET,
  }),
  {
    id: 'customProvider',
    name: 'CustomProvider',
    type: 'oauth',
    version: '2.0',
    scope: ''  // Make sure to request the users email address
  }
]

Most recent build lets you override any pattern (deeply merged so that you only have to type the fields you wish to update).最近的构建允许您覆盖任何模式(深度合并,以便您只需键入要更新的字段)。

Came here looking for this exact answer, and this is what I used:来到这里寻找这个确切的答案,这就是我使用的:

 DiscordProvider({ clientId: process.env.DISCORD_CLIENT_ID, clientSecret: process.env.DISCORD_CLIENT_SECRET, authorization: { params: { scope: 'identify guilds' } }, }),

For anyone looking for scopes for different Providers (Google, Facebook, ...), the scope key is not necessarily always at the same place, so be sure to look at your provider's doc on the Next-Auth website: https://next-auth.js.org/providers对于寻找不同提供商(Google、Facebook 等)范围的任何人,scope 密钥不一定总是在同一位置,因此请务必在 Next-Auth 网站上查看您的提供商的文档: https:// next-auth.js.org/providers

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM