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

Token エンドポイント

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

POST /oauth2/token

リクエスト

Body パラメーター

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

リクエストサンプル

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_tokenstringAccess Token。Userinfo エンドポイント へのリクエストに使用します。
id_tokenstringID Token。ユーザー認証情報を含む改ざん検知用の署名付きトークンです。詳しくは ID Token のページをご確認ください。
token_typestringBearer 固定
expires_innumberAccess Token の有効期限の秒数

関連ドキュメント