Skip to content
This repository has been archived by the owner on Jun 30, 2023. It is now read-only.

OAuth2 #113

Closed
mironal opened this issue Mar 26, 2022 · 2 comments · Fixed by #116
Closed

OAuth2 #113

mironal opened this issue Mar 26, 2022 · 2 comments · Fixed by #116

Comments

@mironal
Copy link
Owner

mironal commented Mar 26, 2022

@mironal
Copy link
Owner Author

mironal commented Mar 29, 2022

For Confidential Clients

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 での認証方法を説明します.

image

Walkthrough (手順)

1. GET oauth2/authorize

https://twitter.com/i/oauth2/authorize に適切なパラメータを付けてリクエストし、Twitter の認証画面(下記スクリーンショット)を開きます。

Parameters

https://developer.twitter.com/en/docs/authentication/oauth-2-0/authorization-codeParameters の部分を参照

redirect_uri は Developer Portal で設定したものと同じにしないとエラーになります.

Response

認証すると redirect_uristatecode がついた状態でリダイレクトされます.

ex) https://www.example.com?state=state&code=VGNibzFWSWREZm01bjN1N3dicWlNUG1oa2xRRVNNdmVHelJGY2hPWGxNd2dxOjE2MjIxNjA4MjU4MjU6MToxOmFjOjE

スクリーンショット

image

2. POST oauth2/token - Access Token

https://api.twitter.com/2/oauth2/token に適切なパラメータを付けてリクエストします。

  • 先程取得した code を使用します
  • Basic 認証を使用します

リクエスト例は以下の通り.

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

@mironal
Copy link
Owner Author

mironal commented Mar 29, 2022

For Public Clients

image

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant