我正在尝试添加一个 Twitter 授权按钮,让我获得用户 oauth_token 和 oauth_token_secret,这允许我们的工具代表用户执行操作。
import NextAuth from "next-auth";
import TwitterProvider from "next-auth/providers/twitter";
export const authOptions = {
// Configure one or more authentication providers
providers: [
TwitterProvider({
clientId: process.env.TWITTER_CLIENT_ID,
clientSecret: process.env.TWITTER_CLIENT_SECRET,
version: "2.0", // opt-in to Twitter OAuth 2.0
authorization: {
url: "https://twitter.com/i/oauth2/authorize",
params: {
grant_type: "authorization_code",
scope: "users.read tweet.read tweet.write like.read list.read",
},
},
}),
// ...add more providers here
],
session: {
strategy: "jwt",
},
callbacks: {
jwt: ({ token, account, ...props }) => {
console.log({ token, account, props }, props?.profile?.data);
return token;
},
session: async ({ session, user, token }) => {
session.user = user;
session.token = token;
return session;
},
},
secret: process.env.NEXTAUTH_SECRET,
debug: true,
};
export default NextAuth(authOptions);
这是我当前使用 next-auth 提供程序的片段。
如果我选择应用类型
来自 Twitter 的本机应用程序可以进行身份验证,但不会返回客户端的秘密。这就是为什么使用 Web App 会提供机密的客户详细信息。
我遇到了同样的问题。虽然我不能 100% 确定这是否会修复它,但我能够通过重置 Twitter 客户端 ID 和机密的环境变量然后重新启动开发服务器来解决问题。
如果这没有解决,请告诉我并乐意进一步探索。