auth.js 或 next-auth 中的 Twitter Oauth 2.0 权限范围配置仅获取 users.read tweet.readoffline.access 范围

问题描述 投票:0回答:1

我给出的范围是什么,我只获得 users.read tweet.readoffline.access 范围,例如来自 twitter 的 url https://x.com/i/oauth2/authorize?scope=users.read+tweet.read+offline .访问.

这是我检查过的代码https://github.com/nextauthjs/next-auth/discussions/4251并尝试根据它来实现,但它不起作用。无论我做什么,只有三个范围可用。

import TwitterProvider from 'next-auth/providers/twitter';
export const config = {
  debug: true,
  pages: {
    signIn: '/sign-up',
  },
  providers: [
    TwitterProvider({
      //@ts-ignore
      version: '2.0', // opt-in to Twitter OAuth 2.0
      authorization: {
        url: 'https://x.com/i/oauth2/authorize',
        params: {
          scope: 'users.read tweet.read tweet.write offline.access',
        },
      profile(profile) {
        return {
          id: profile.data.id,
          name: profile.data.name,
          image: profile.data.profile_image_url,
          email: profile.data.email,
          username: profile.data.username,
        };
      },
    }),
  ],
javascript typescript next.js next-auth auth.js
1个回答
0
投票

我也面临这个问题,当我在 auth.js 的 node_modules 中看到 twitter.js 文件时,发现授权 URL 是用此 URL 字符串硬编码的 https://x.com/i/oauth2/authorize?scope=users。阅读 推文. 离线阅读. 访问 要修复它,请按照我的步骤操作。

供 youtube 视频参考

  1. 按您要添加的范围更改 twitter.js 文件是 https://x.com/i/oauth2/authorize?scope=tweet.read tweet.write users.read like.write like.read list .读取列表.离线写入.访问.
  2. 当您在 .gitignore 文件内的 node_modules 中进行更改时,我们需要修补 auth.js 包。
  3. 使用 npm i patch-package 安装补丁包并运行命令 npx patch-package @auth/core 4.删除node_modules并在package.json添加postinstall命令⇒“postinstall”:“patch-package”。
  4. 安装node_modules并运行就可以了。
© www.soinside.com 2019 - 2024. All rights reserved.