4

I'm trying to add a Twitter authorization button that gets me user oauth_token & oauth_token_secret which allows our tool to do actions against on the user's behalf.

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);


This is my current snippet using the next-auth provider.

If I select the Type of App

enter image description here

Native App from Twitter works authentication but doesn't return the client's secret. that's why using Web App gives confidential client details.

But processing with that returns an invalid header error. enter image description here

Hasham Minhas
  • 436
  • 3
  • 13

2 Answers2

1

1

--header  Authorization: Basic Base64.code()

Base64.code() compiled an incorrect key and secret, resulting in invalid request headers There are two sets of Twitter backend

  1. API Key and API Key Secret

  2. Client ID and Client Secret

Please use 2

Base64.encode(String.format("%s:%s",Client ID, Client Secret).getBytes(Charset.forName("UTF-8"))
bamboo
  • 11
  • 3
0

I was running into this same issue. While I am not 100% sure if this will fix it, I was able to resolve by resetting my environment variables for the Twitter Client ID and Secret and then restarting the dev server.

If this doesn't resolve, let me know and happy to explore further.

Jack_Lynch
  • 15
  • 5