Closed mironal closed 2 years ago
The following is an explanation of how to authenticate with OAuth 2.0 when Confidential Clients are selected on the Twitter Developer Portal.
以下のように Twitter Developer Portal で Confidential Clients を選択した場合の OAuth 2.0 での認証方法を説明します.
https://twitter.com/i/oauth2/authorize
に適切なパラメータを付けてリクエストし、Twitter の認証画面(下記スクリーンショット)を開きます。
https://developer.twitter.com/en/docs/authentication/oauth-2-0/authorization-code の
Parameters
の部分を参照
redirect_uri
は Developer Portal で設定したものと同じにしないとエラーになります.
認証すると redirect_uri
に state
と code
がついた状態でリダイレクトされます.
https://api.twitter.com/2/oauth2/token
に適切なパラメータを付けてリクエストします。
code
を使用しますリクエスト例は以下の通り.
curl --location --request POST 'https://api.twitter.com/2/oauth2/token' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'code=VGNibzFWSWREZm01bjN1N3dicWlNUG1oa2xRRVNNdmVHelJGY2hPWGxNd2dxOjE2MjIxNjA4MjU4MjU6MToxOmFjOjE' \
--data-urlencode 'grant_type=authorization_code' \
--data-urlencode 'client_id=rG9n6402A3dbUJKzXTNX4oWHJ' \
--data-urlencode 'redirect_uri=https://www.example.com' \
--data-urlencode 'code_verifier=challenge'
https://developer.twitter.com/en/docs/authentication/oauth-2-0/user-access-token