概要
Webアプリケーションの認証に、SNS連携をSDKを使用せずRest API(若しくはサードパーティライブラリ)で行いたいときに参考になるサイトのまとめです。
Facebook
Official
Endpoint
ログインダイアログ
EndPoint
https://www.facebook.com/v2.8/dialog/oauth
 
Parameter
| Parameter | Value | 
| client_id | アプリのID | 
| redirect_uri | ログイン後にリダイレクトするURL | 
| state | CSRF対策のアプリが作成する任意で固有の文字列 (option) | 
| response_type | URLパラメータとフラグメントのどちらに応答データを含むか (option) | 
| scope | カンマで区切ったアクセス許可のリスト (option) | 
response_type
- code : デフォルト。応答データはURLパラメータとして返されcodeパラメータが含まれます。
- token : 応答データはURLフラグメントとして返され、アクセストークンが含まれます。
Response fields
response_typeの指定内容でフィールドが変わる。
| Field | Description | 
| code | response_typeにcodeを指定した場合に受け取るフィールド | 
| token | response_typeにtokenを指定した場合に受け取るフィールド | 
アクセストークンのコードの交換
response_typeにcodeを指定した場合、レスポンスで受け取る認証コードを使ってアクセストークンを取得する。
[アクセストークン] (https://developers.facebook.com/docs/facebook-login/access-tokens)
EndPoint(GET)
https://graph.facebook.com/v2.8/oauth/access_token
 
Parameter
| Parameter | Value | 
| client_id | アプリのID | 
| redirect_uri | ログインダイアログで指定したリダイレクトURL | 
| client_secret | 固有のapp secret | 
| code | ログインダイアログのリダイレクトによって受け取る認証コード | 
Response fields
| Field | Description | 
| access_token | アクセストークン | 
| token_type | Fixed bearer? | 
| expires_in | アクセストークンの有効時間(秒) | 
token_typeについて言及しているドキュメントが見当たらなかった。
[The OAuth 2.0 Authorization Framework: Bearer Token Usage] (https://tools.ietf.org/html/rfc6750)
アクセストークンの検証
response_typeにtokenを指定した場合、レスポンスで受け取るトークンを検証する。
[Graph API Reference - Debug-Token] (https://developers.facebook.com/docs/graph-api/reference/v2.8/debug_token)
EndPoint(GET)
https://graph.facebook.com/debug_token
 
Parameter
| Parameter | Value | 
| input_token | 検査対象のトークン | 
| access_token | アプリのアクセストークン | 
Response fields
JSONフォーマット
| Field | Description | 
| app_id | アプリのID | 
| application | アプリ名 | 
| expires_at | アクセストークンの有効期限が切れる日付 | 
| is_valid | アクセストークンが有効かどうか | 
| issued_at | アクセストークンが発行された日付 | 
| metadata | アクセストークンのメタデータ | 
| scopes | 権限のリスト | 
| user_id | ユーザーID | 
参考
Twitter
Official
Endpoint
リクエストトークンの取得
EndPoint(POST)
https://api.twitter.com/oauth/request_token
 
Parameter
| Parameter | Value | 
| oauth_callback | リダイレクトURL | 
| oauth_consumer_key | アプリのAPI Key | 
| oauth_nonce | リクエストごとにランダムな任意の文字列 | 
| oauth_signature_method | Fixed HMAC-SHA1 | 
| oauth_signature | oauth_signature_methodで指定した方式で生成した署名 | 
| oauth_timestamp | リクエスト作成時のタイムスタンプ値 | 
| oauth_version | Fixed 1.0 | 
Response fields
| Field | Description | 
| oauth_token | リクエストトークン | 
| oauth_token_secret | リクエストトークン・シークレット | 
| oauth_callback_confirmed |  | 
ログインダイアログへリダイレクトする
EndPoint(GET)
https://api.twitter.com/oauth/authenticate?oauth_token={oauth_token}
 
Parameter
| Parameter | Value | 
| oauth_token | リクエストトークン | 
| force_login | (optional) | 
| screen_name | (optional) | 
リダイレクト先URL
Twitterのログイン画面でアプリを認証した場合に、リクエストトークンの取得時に指定したリダイレクト先URLにoauth_token、oauth_verifierパラメータが付加されてリダイレクトされる。
| Field | Description | 
| oauth_token | 認証済みのリクエストトークン | 
| oauth_verifier | リクエストトークンの確認用コード | 
リクエストトークンをアクセストークンに変換する
EndPoint(POST)
https://api.twitter.com/oauth/access_token
 
Parameter
| Parameter | Value | 
| oauth_token | 認証済みのリクエストトークン | 
| oauth_verifier | リクエストトークンの確認用コード (optional) | 
| oauth_consumer_key | アプリのAPI Key | 
| oauth_nonce | リクエストごとにランダムな任意の文字列 | 
| oauth_signature_method | Fixed HMAC-SHA1 | 
| oauth_signature | oauth_signature_methodで指定した方式で生成した署名 | 
| oauth_timestamp | リクエスト作成時のタイムスタンプ値 | 
| oauth_version | Fixed 1.0 | 
Response fields
| Field | Description | 
| oauth_token | アクセストークン | 
| oauth_token_secret | アクセストークン・シークレット | 
| user_id | ユーザーID | 
| screen_name | ユーザー名 | 
参考
Google
Official
Endpoint
Redirecting to Google's OAuth 2.0 server
EndPoint(GET)
https://accounts.google.com/o/oauth2/v2/auth
 
Parameter
| Parameter | Value | 
| response_type | Fixed code | 
| client_id | Client ID | 
| redirect_uri | ログイン後にリダイレクトするURL | 
| scope | スペースで区切ったアクセス許可のリスト | 
| state | CSRF対策の任意の文字列 | 
| access_type | onlineoroffline | 
| prompt |  | 
| login_hint |  | 
| include_granted_scopes |  | 
Response fields
| Field | Description | 
| code | 認証コード | 
Handling the OAuth 2.0 server response
EndPoint(POST)
https://www.googleapis.com/oauth2/v4/token
 
Parameter
| Parameter | Value | 
| code | ログイン後のリダイレクトによって受け取る認証コード | 
| client_id | Client ID | 
| client_secret | Client Secret | 
| redirect_uri | ログイン後にリダイレクトするURL | 
| grant_type | Fixed authorization_code | 
Response fields
| Field | Description | 
| access_token | アクセストークン | 
| refresh_token | リフレッシュトークン | 
| expires_in | アクセストークンの有効時間 | 
| token_type | Fixed Bearer | 
Using a refresh token
ログインのフローからは外れますが、アクセストークンの有効期限が失効した場合、リフレッシュトークンを使って、アクセストークンを再発行することができます。
EndPoint(POST)
https://www.googleapis.com/oauth2/v4/token
 
Parameter
| Parameter | Value | 
| refresh_token | リフレッシュトークン | 
| client_id | Client ID | 
| client_secret | Client Secret | 
| grant_type | Fixed refresh_token | 
Response fields
| Field | Description | 
| access_token | アクセストークン | 
| expires_in | アクセストークンの有効時間 | 
| token_type | Fixed Bearer | 
参考
LINE
Official
Endpoint
認証コードの取得
EndPoint
https://access.line.me/dialog/oauth/weblogin
 
Parameter
| Parameter | Value | 
| response_type | Fixed code | 
| client_id | Channel ID | 
| redirect_uri | ログイン後にリダイレクトするURL | 
| state | CSRF対策の任意の文字列 (optional) | 
Response fields
| Field | Description | 
| code | ログイン後のリダイレクトによって受け取る認証コード。発行されてから10分間有効 | 
| state | 認証コード取得時に指定した任意の文字列 | 
アクセストークンの取得
EndPoint(POST)
https://api.line.me/v1/oauth/accessToken
 
Parameter
| Parameter | Value | 
| grant_type | Fixed authorization_code | 
| client_id | Channel ID | 
| client_secret | Channel Secret | 
| code | ログイン後のリダイレクトによって受け取る認証コード | 
| redirect_uri | ログイン後にリダイレクトするURL | 
Response fields
| Field | Description | 
| mid | ユーザーID | 
| access_token | アクセストークン | 
| expires_in | アクセストークンの有効期限 | 
| refresh_token | リフレッシュトークン | 
| scope | Fixed null | 
アクセストークンの再発行
ログインフローからは外れますが、リフレッシュトークンを使用してアクセストークンを再発行することができます。
EndPoint(POST)
https://api.line.me/v1/oauth/accessToken
 
Parameter
| Parameter | Value | 
| refreshToken | リフレッシュトークン | 
Response fields
JSONフォーマット
| Field | Description | 
| mid | ユーザーID | 
| accessToken | アクセストークン | 
| expire | アクセストークンの有効期限 | 
| refreshToken | リフレッシュトークン | 
参考
OAuth
OAuth 1.0
参考
OAuth 2.0
参考
Java Library
関連記事