{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/usps/json-schema/usps-authorization-code-credentials-schema.json",
  "title": "Authorization Code Credentials Token Request",
  "description": "The client credentials in addition to the authorization code received earlier are used to get access and refresh tokens. The credentials of the client application that are verified by the authorization server. The value of the grant_type is 'authorization_code'.",
  "x-generated": "2026-11-11",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/usps-oauth-openapi.yml#/components/schemas/AuthorizationCodeCredentials",
  "required": [
    "code",
    "redirect_uri"
  ],
  "allOf": [
    {
      "$ref": "#/$defs/ClientCredentials"
    },
    {
      "type": "object",
      "properties": {
        "redirect_uri": {
          "description": "The authorization code redirect Uniform Resource Identifier (URI) for the third-party application to receive the authorization code. This is used to verify the identify of the requester. The request will not be redirected to this URI.\n",
          "type": "string"
        },
        "code": {
          "description": "The authorization code previously received by the client application.",
          "type": "string"
        }
      },
      "additionalProperties": false
    }
  ],
  "additionalProperties": false,
  "$defs": {
    "AuthorizationCodeCredentials": {
      "title": "Authorization Code Credentials Token Request",
      "description": "The client credentials in addition to the authorization code received earlier are used to get access and refresh tokens. The credentials of the client application that are verified by the authorization server. The value of the grant_type is 'authorization_code'.",
      "required": [
        "code",
        "redirect_uri"
      ],
      "allOf": [
        {
          "$ref": "#/$defs/ClientCredentials"
        },
        {
          "type": "object",
          "properties": {
            "redirect_uri": {
              "description": "The authorization code redirect Uniform Resource Identifier (URI) for the third-party application to receive the authorization code. This is used to verify the identify of the requester. The request will not be redirected to this URI.\n",
              "type": "string"
            },
            "code": {
              "description": "The authorization code previously received by the client application.",
              "type": "string"
            }
          },
          "additionalProperties": false
        }
      ],
      "additionalProperties": false
    },
    "ClientCredentials": {
      "title": "Client Credentials Token Request",
      "description": "The client credentials are used to get an access token. The credentials of the client application that are verified by the authorization server. The value of the grant_type is 'client_credentials'",
      "required": [
        "client_id",
        "client_secret"
      ],
      "allOf": [
        {
          "$ref": "#/$defs/TokenRequest"
        },
        {
          "type": "object",
          "properties": {
            "client_id": {
              "description": "The unique identifier issued to the client application making the request. Used for authenticating the client application.\n\nYou will need to add an app to get a client Id and secret. These are the Consumer Key and Consumer Secret values respectfully in the API developer portal.\n",
              "type": "string"
            },
            "client_secret": {
              "description": "The shared secret issued to the client application making the request. Used for authenticating the client application.\n\nYou will need to add an app to get a client Id and secret. These are the Consumer Key and Consumer Secret values respectfully in the API developer portal.\n",
              "type": "string"
            }
          },
          "additionalProperties": false
        }
      ],
      "additionalProperties": false
    },
    "RefreshTokenCredentials": {
      "title": "Refresh Token Credentials Request",
      "description": "The client credentials in addition to the refresh token received earlier are used to get access and refresh tokens. The credentials of the client application that are verified by the authorization server. The value of the grant_type is 'refresh_token'.",
      "required": [
        "refresh_token"
      ],
      "allOf": [
        {
          "$ref": "#/$defs/ClientCredentials"
        },
        {
          "type": "object",
          "properties": {
            "refresh_token": {
              "description": "The refresh token value to be used to issue a new access token.",
              "type": "string"
            }
          },
          "additionalProperties": false
        }
      ],
      "additionalProperties": false
    },
    "TokenRequest": {
      "title": "Token Request",
      "description": "The base object for an OAuth token request, in accordance with OAuth industry standards.",
      "type": "object",
      "required": [
        "grant_type"
      ],
      "oneOf": [
        {
          "$ref": "#/$defs/AuthorizationCodeCredentials"
        },
        {
          "$ref": "#/$defs/ClientCredentials"
        },
        {
          "$ref": "#/$defs/RefreshTokenCredentials"
        }
      ],
      "properties": {
        "grant_type": {
          "description": "The OAuth standard flow being requested by the client application.",
          "type": "string",
          "enum": [
            "client_credentials",
            "refresh_token",
            "authorization_code"
          ]
        },
        "scope": {
          "description": "The OAuth2 scope being requested. A client application may request a subset of scope that has already been configured during registration.\n\nThe default scope registered for the client application is used as default when the scope is omitted.\n\n**Only specify the scope in the request when the client application requires less scope, i.e. less access to APIs, than the default.**\n",
          "type": "string",
          "default": ""
        }
      },
      "additionalProperties": true
    }
  }
}