コンテンツへスキップ
NextAuth.js v4からの移行?こちらを ご確認ください。.

providers/twitter

組み込みのTwitter統合。

TwitterProfile

ユーザー検索

インデックス可能

[claims: string]: unknown

プロパティ

data

data: {
  created_at: string;
  description: string;
  email: string;
  entities: {
     description: {
        hashtags: {
           end: number;
           start: number;
           tag: string;
        }[];
     };
     url: {
        urls: {
           display_url: string;
           end: number;
           expanded_url: string;
           start: number;
           url: string;
        }[];
     };
  };
  id: string;
  location: string;
  name: string;
  pinned_tweet_id: string;
  profile_image_url: string;
  protected: boolean;
  url: string;
  username: string;
  verified: boolean;
};
created_at?
optional created_at: string;
description?
optional description: string;

ユーザーが指定した場合、このユーザーのプロファイル説明(バイオとも呼ばれる)のテキスト。

このフィールドを返すには、承認リクエストのクエリパラメーターにuser.fields=descriptionを追加します。

email?
optional email: string;
注記

現在、Twitterではメールアドレスはサポートされていません。

entities?
optional entities: {
  description: {
     hashtags: {
        end: number;
        start: number;
        tag: string;
     }[];
  };
  url: {
     urls: {
        display_url: string;
        end: number;
        expanded_url: string;
        start: number;
        url: string;
     }[];
  };
};

このオブジェクトとその子フィールドには、ユーザーの説明に特別な意味を持つテキストに関する詳細が含まれています。

このフィールドを返すには、承認リクエストのクエリパラメーターにuser.fields=entitiesを追加します。

entities.description
description: {
  hashtags: {
     end: number;
     start: number;
     tag: string;
  }[];
};

ユーザーの説明にあるURL、ハッシュタグ、キャッシュタグ、またはメンションに関する詳細が含まれています。

entities.description.hashtags
hashtags: {
  end: number;
  start: number;
  tag: string;
  }[];
entities.url
url: {
  urls: {
     display_url: string;
     end: number;
     expanded_url: string;
     start: number;
     url: string;
  }[];
};

ユーザーのプロファイルウェブサイトに関する詳細が含まれています。

entities.url.urls
urls: {
  display_url: string;
  end: number;
  expanded_url: string;
  start: number;
  url: string;
  }[];

ユーザーのプロファイルウェブサイトに関する詳細が含まれています。

id
id: string;

このユーザーの一意の識別子。大きな整数を処理できない言語やツールでの問題を避けるため、文字列として返されます。

location?
optional location: string;

ユーザーが指定した場合、ユーザーのプロファイルに指定された場所。これは自由形式の値であるため、有効な場所を示していない場合がありますが、場所クエリを使用した検索を実行する際に曖昧に評価される場合があります。

このフィールドを返すには、承認リクエストのクエリパラメーターにuser.fields=locationを追加します。

name
name: string;

このユーザーのフレンドリーな名前で、プロファイルに表示されます。

pinned_tweet_id?
optional pinned_tweet_id: string;

このユーザーのピン留めされたツイートの一意の識別子。

承認リクエストのクエリパラメーターにexpansions=pinned_tweet_idを追加することで、includes.tweetsで展開されたオブジェクトを取得できます。

profile_image_url?
optional profile_image_url: string;

ユーザーのプロファイルに表示される、このユーザーのプロファイル画像のURL。

protected?
optional protected: boolean;
url?
optional url: string;

ユーザーのプロファイルに指定されている場合、URL。

このフィールドを返すには、承認リクエストのクエリパラメーターにuser.fields=urlを追加します。

username
username: string;

このユーザーのTwitterハンドル(スクリーン名)。

verified?
optional verified: boolean;

このユーザーが検証済みのTwitterユーザーかどうかを示します。

このフィールドを返すには、承認リクエストのクエリパラメーターにuser.fields=verifiedを追加します。

includes?

optional includes: {
  tweets: {
     id: string;
     text: string;
  }[];
};
tweets?
optional tweets: {
  id: string;
  text: string;
  }[];

default()

default(config): OAuthConfig<TwitterProfile>

ページにTwitterログインを追加します。

設定

コールバックURL

https://example.com/api/auth/callback/twitter

設定

import { Auth } from "@auth/core"
import Twitter from "@auth/core/providers/twitter"
 
const request = new Request(origin)
const response = await Auth(request, {
  providers: [
    Twitter({
      clientId: TWITTER_CLIENT_ID,
      clientSecret: TWITTER_CLIENT_SECRET,
    }),
  ],
})

リソース

OAuth 2

TwitterはOAuth 2をサポートしており、現在はオプトインです。有効にするには、プロバイダーの設定にversion: "2.0"を追加するだけです。

Twitter({
  clientId: process.env.TWITTER_ID,
  clientSecret: process.env.TWITTER_SECRET,
  version: "2.0", // opt-in to Twitter OAuth 2.0
})

この変更は簡単ですが、Twitter APIとどのようにやり取りできるかを変更することに注意してください。詳細については、公式のTwitter OAuth 2ドキュメントをご覧ください。

現在、Twitter OAuth 2.0 はメールアドレスをサポートしていません。

備考

現在、Twitter は OAuth 1.0 仕様を使用する唯一の組み込みプロバイダーです。これは、access_tokenrefresh_token は取得できませんが、それぞれ oauth_tokenoauth_token_secret を取得することを意味します。アダプターを使用している場合は、これらのトークンをデータベーススキーマに追加することを忘れないでください。

💡

ユーザーのメールアドレスを取得するには、アプリの権限で「ユーザーからメールアドレスを要求する」オプションを有効にする必要があります。

デフォルトでは、Auth.js は Twitter プロバイダーがOAuth 2仕様に基づいていると想定しています。

💡

Twitter プロバイダーにはデフォルト設定が付属しています。ユースケースに合わせてデフォルト設定をオーバーライドするには、組み込み OAuth プロバイダーのカスタマイズを確認してください。

免責事項 デフォルト設定のバグを見つけたと思われる場合は、issue を作成できます。

Auth.js は仕様に厳密に準拠しており、プロバイダーによる仕様からのずれについては責任を負うことができません。issue を作成できますが、問題が仕様への非準拠である場合、解決策を追求できない場合があります。より詳しいヘルプが必要な場合は、Discussionsで質問してください。

パラメーター

パラメーター
configOAuthUserConfig<TwitterProfile>

戻り値

OAuthConfig<TwitterProfile>

Auth.js © Balázs Orbán and Team -2024