メインコンテンツまでスキップ

Token エンドポイント

OpenID Connect および OAuth 2.0 に準拠し、Access Token と ID Token を発行するエンドポイント。

POST /oauth2/token

リクエスト​

リクエストヘッダー​

クライアント認証に Basic 認証を用いることができます。
クライアント情報の Client ID と Client Secret を ":" で連結し、Base64 エンコードしたものを Authorization ヘッダーに指定します。

Authorization: Basic {base64_encode(client_id + ":" + client_secret)}

リクエストヘッダーの指定は、Body パラメーターの client_id, client_secret の指定より優先されます。

Body パラメーター​

パラメータ名型必須説明
client_idstring※クライアント情報の Client ID の値。
Authorization ヘッダーを指定しない場合必須
client_secretstring※クライアント情報の Client Secret の値。
Authorization ヘッダーを指定しない場合必須
grant_typestring○authorization_code 固定
codestring○認可コード
redirect_uristring○Authorization エンドポイント で指定した redirect_uri
code_verifierstring※認可コード横取り攻撃対策(PKCE, RFC7636)に準拠した値
※Authorization エンドポイント で code_challenge を指定した場合に必須

リクエストサンプル​

Authorization ヘッダーを指定する場合
curl -X POST https://fea825aa5e.auth.socialplus.jp/oauth2/token \
-H 'Content-Type: application/x-www-form-urlencoded; charset=utf-8' \
-H 'Authorization: Basic ZDJmYzU1NGExYzpmZDBiY2YyNTlkYjQ0YmJlZDU1ZTU0ZjNjY2NlM2U1OQ==' \
-d 'grant_type=authorization_code' \
-d 'code=st0c89RJMsNqigK6XCvmloDQAwt1NDInu35JLdBp' \
-d 'redirect_uri=https://client.example.com/auth/callback'
Authorization ヘッダーを指定しない場合
curl -X POST https://fea825aa5e.auth.socialplus.jp/oauth2/token \
-H 'Content-Type: application/x-www-form-urlencoded; charset=utf-8' \
-d 'client_id=d2fc554a1c' \
-d 'client_secret=fd0bcf259db44bbed55e54f3ccce3e59' \
-d 'grant_type=authorization_code' \
-d 'code=st0c89RJMsNqigK6XCvmloDQAwt1NDInu35JLdBp' \
-d 'redirect_uri=https://client.example.com/auth/callback'

エラーレスポンス​

特に指定がない限りは 400 Bad Request とともに、エラーコード(error)とエラーメッセージ(error_description)を含む JSON オブジェクトを返します。

エラーレスポンス例
HTTP/1.1 400 Bad Request
Content-Type: application/json

{
"error": "invalid_grant",
"error_description": "Authorization code is invalid."
}
エラーコードエラーメッセージ説明
invalid_request{{parameter}} is required.code, grant_type, redirect_uri の指定がない。
unsupported_grant_typeUnsupported grant_type.grant_type の値が不正である。
invalid_clientclient_id or client_secret is invalid.client_id, client_secret の値が不正である、あるいは指定がない。
invalid_grantAuthorization code is invalid.code の値が不正または未指定、あるいは使用済みである。
invalid_grantUser does not exist.指定された code が発行されたユーザーが存在しない。
invalid_grantredirect_uri is invalid.redirect_uri の値が不正である。
invalid_grantcode_verifier is invalid.code_verifier の値が不正である。
invalid_requestcode_verifier format is invalid.code_verifier の形式が不正である。

関連: 共通のエラー

成功レスポンス​

リクエストに成功すると、HTTP ステータスコード 200 OK と、Access Token、ID Token を含む JSON オブジェクトを返します。

成功時のレスポンス例
HTTP/1.1 200 OK
Content-Type: application/json
Cache-Control: no-store
Pragma: no-cache

{
"access_token": "0fe9cfe59efca93d602abaf8d1a378afd2b1a05e",
"id_token": "eyJ0eXAiOiJKV1Q...a1G3sf3Wx0PwYiDw",
"token_type": "Bearer",
"expires_in": 3600
}
パラメータ名型必須説明
access_tokenstring○Access Token。Userinfo エンドポイント へのリクエストに使用します。
id_tokenstring○ID Token。ユーザー認証情報を含む改ざん検知用の署名付きトークンです。詳しくは ID Token のページをご確認ください。
token_typestring○Bearer 固定
expires_innumber○Access Token の有効期限の秒数

関連ドキュメント​