{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "anyOf": [
    {
      "type": "object",
      "properties": {
        "iss": {
          "type": "string",
          "maxLength": 2048,
          "pattern": "^https:\\/\\/[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)*(?::(?:6553[0-5]|655[0-2][0-9]|65[0-4][0-9]{2}|6[0-4][0-9]{3}|[1-5][0-9]{4}|[1-9][0-9]{0,3}))?(?:\\/[\\x21\\x22\\x24-\\x2e\\x30-\\x3e\\x40-\\x5b\\x5d-\\x7e]*)*(?![\\s\\S])"
        },
        "aud": {
          "type": "string",
          "maxLength": 2048,
          "pattern": "^https:\\/\\/[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)*(?::(?:6553[0-5]|655[0-2][0-9]|65[0-4][0-9]{2}|6[0-4][0-9]{3}|[1-5][0-9]{4}|[1-9][0-9]{0,3}))?(?:\\/[\\x21\\x22\\x24-\\x2e\\x30-\\x3e\\x40-\\x5b\\x5d-\\x7e]*)*(?![\\s\\S])"
        },
        "sub": {
          "type": "string",
          "maxLength": 294,
          "pattern": "^autonym:[a-z2-7]{32}@[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)*$"
        },
        "client_id": {
          "anyOf": [
            {
              "type": "string",
              "pattern": "^cl_[0-7][0-9A-HJKMNP-TV-Z]{25}(?![\\s\\S])"
            },
            {
              "type": "string",
              "maxLength": 2048,
              "pattern": "^https:\\/\\/(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\\.)*(?!(?:[0-9]+|0x[0-9a-f]*)(?![a-z0-9-]))[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?::(?:6553[0-5]|655[0-2][0-9]|65[0-4][0-9]{2}|6[0-4][0-9]{3}|[1-5][0-9]{4}|[1-9][0-9]{0,3}))?(?:\\/(?!(?:\\.|%2[eE]){1,2}(?:[/?]|(?![\\s\\S])))[\\x21\\x22\\x24-\\x2e\\x30-\\x3e\\x40-\\x5b\\x5d-\\x7e]*)+(?:\\?[\\x21\\x22\\x24-\\x5b\\x5d-\\x7e]*)?(?![\\s\\S])"
            }
          ]
        },
        "jti": {
          "type": "string",
          "pattern": "^[A-Za-z0-9_-]{16,128}(?![\\s\\S])"
        },
        "iat": {
          "type": "integer",
          "minimum": 0,
          "maximum": 253402300799
        },
        "exp": {
          "type": "integer",
          "minimum": 0,
          "maximum": 253402300799
        },
        "cnf": {
          "type": "object",
          "properties": {
            "jkt": {
              "type": "string",
              "pattern": "^[A-Za-z0-9_-]{42}[AEIMQUYcgkosw048]$"
            }
          },
          "required": [
            "jkt"
          ],
          "additionalProperties": false
        },
        "autonym_grant_id": {
          "type": "string",
          "pattern": "^gr_[0-7][0-9A-HJKMNP-TV-Z]{25}(?![\\s\\S])"
        },
        "autonym_purpose": {
          "type": "string",
          "enum": [
            "booking",
            "recommendation",
            "safety",
            "fulfilment",
            "personalisation",
            "research",
            "care",
            "medical",
            "employment",
            "advertising"
          ]
        },
        "act": {
          "type": "object",
          "properties": {
            "client_id": {
              "anyOf": [
                {
                  "type": "string",
                  "pattern": "^cl_[0-7][0-9A-HJKMNP-TV-Z]{25}(?![\\s\\S])"
                },
                {
                  "type": "string",
                  "maxLength": 2048,
                  "pattern": "^https:\\/\\/(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\\.)*(?!(?:[0-9]+|0x[0-9a-f]*)(?![a-z0-9-]))[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?::(?:6553[0-5]|655[0-2][0-9]|65[0-4][0-9]{2}|6[0-4][0-9]{3}|[1-5][0-9]{4}|[1-9][0-9]{0,3}))?(?:\\/(?!(?:\\.|%2[eE]){1,2}(?:[/?]|(?![\\s\\S])))[\\x21\\x22\\x24-\\x2e\\x30-\\x3e\\x40-\\x5b\\x5d-\\x7e]*)+(?:\\?[\\x21\\x22\\x24-\\x5b\\x5d-\\x7e]*)?(?![\\s\\S])"
                }
              ]
            }
          },
          "required": [
            "client_id"
          ],
          "additionalProperties": false
        },
        "scope": {
          "type": "string",
          "maxLength": 16384,
          "pattern": "^[\\x21\\x23-\\x5b\\x5d-\\x7e]+(?: [\\x21\\x23-\\x5b\\x5d-\\x7e]+)*(?![\\s\\S])"
        },
        "authorization_details": {
          "minItems": 1,
          "maxItems": 4,
          "type": "array",
          "items": {
            "oneOf": [
              {
                "type": "object",
                "properties": {
                  "type": {
                    "type": "string",
                    "const": "urn:autonym:authorization-details:contribute"
                  },
                  "contribute": {
                    "minItems": 1,
                    "maxItems": 32,
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "domain": {
                          "type": "string",
                          "pattern": "^[a-z][a-z0-9_.-]{0,63}$"
                        },
                        "keys": {
                          "minItems": 1,
                          "maxItems": 128,
                          "type": "array",
                          "items": {
                            "type": "string",
                            "pattern": "^[a-z][a-z0-9_.-]{0,63}$"
                          }
                        }
                      },
                      "required": [
                        "domain",
                        "keys"
                      ],
                      "additionalProperties": false
                    }
                  },
                  "max_events": {
                    "type": "integer",
                    "exclusiveMinimum": 0,
                    "maximum": 100000
                  },
                  "allow_confirmation": {
                    "type": "boolean"
                  }
                },
                "required": [
                  "type",
                  "contribute",
                  "max_events",
                  "allow_confirmation"
                ],
                "additionalProperties": false,
                "description": "The RFC 9396 authorization_details entry that requests a contribution grant (A6.2). Domains are unique, and so are the keys of each domain."
              }
            ]
          }
        }
      },
      "required": [
        "iss",
        "aud",
        "sub",
        "client_id",
        "jti",
        "iat",
        "exp",
        "cnf",
        "autonym_grant_id",
        "autonym_purpose",
        "scope"
      ],
      "additionalProperties": false
    },
    {
      "type": "object",
      "properties": {
        "iss": {
          "type": "string",
          "maxLength": 2048,
          "pattern": "^https:\\/\\/[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)*(?::(?:6553[0-5]|655[0-2][0-9]|65[0-4][0-9]{2}|6[0-4][0-9]{3}|[1-5][0-9]{4}|[1-9][0-9]{0,3}))?(?:\\/[\\x21\\x22\\x24-\\x2e\\x30-\\x3e\\x40-\\x5b\\x5d-\\x7e]*)*(?![\\s\\S])"
        },
        "aud": {
          "type": "string",
          "maxLength": 2048,
          "pattern": "^https:\\/\\/[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)*(?::(?:6553[0-5]|655[0-2][0-9]|65[0-4][0-9]{2}|6[0-4][0-9]{3}|[1-5][0-9]{4}|[1-9][0-9]{0,3}))?(?:\\/[\\x21\\x22\\x24-\\x2e\\x30-\\x3e\\x40-\\x5b\\x5d-\\x7e]*)*(?![\\s\\S])"
        },
        "sub": {
          "type": "string",
          "maxLength": 294,
          "pattern": "^autonym:[a-z2-7]{32}@[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)*$"
        },
        "client_id": {
          "anyOf": [
            {
              "type": "string",
              "pattern": "^cl_[0-7][0-9A-HJKMNP-TV-Z]{25}(?![\\s\\S])"
            },
            {
              "type": "string",
              "maxLength": 2048,
              "pattern": "^https:\\/\\/(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\\.)*(?!(?:[0-9]+|0x[0-9a-f]*)(?![a-z0-9-]))[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?::(?:6553[0-5]|655[0-2][0-9]|65[0-4][0-9]{2}|6[0-4][0-9]{3}|[1-5][0-9]{4}|[1-9][0-9]{0,3}))?(?:\\/(?!(?:\\.|%2[eE]){1,2}(?:[/?]|(?![\\s\\S])))[\\x21\\x22\\x24-\\x2e\\x30-\\x3e\\x40-\\x5b\\x5d-\\x7e]*)+(?:\\?[\\x21\\x22\\x24-\\x5b\\x5d-\\x7e]*)?(?![\\s\\S])"
            }
          ]
        },
        "jti": {
          "type": "string",
          "pattern": "^[A-Za-z0-9_-]{16,128}(?![\\s\\S])"
        },
        "iat": {
          "type": "integer",
          "minimum": 0,
          "maximum": 253402300799
        },
        "exp": {
          "type": "integer",
          "minimum": 0,
          "maximum": 253402300799
        },
        "cnf": {
          "type": "object",
          "properties": {
            "jkt": {
              "type": "string",
              "pattern": "^[A-Za-z0-9_-]{42}[AEIMQUYcgkosw048]$"
            }
          },
          "required": [
            "jkt"
          ],
          "additionalProperties": false
        },
        "autonym_grant_id": {
          "type": "string",
          "pattern": "^gr_[0-7][0-9A-HJKMNP-TV-Z]{25}(?![\\s\\S])"
        },
        "autonym_purpose": {
          "type": "string",
          "enum": [
            "booking",
            "recommendation",
            "safety",
            "fulfilment",
            "personalisation",
            "research",
            "care",
            "medical",
            "employment",
            "advertising"
          ]
        },
        "act": {
          "type": "object",
          "properties": {
            "client_id": {
              "anyOf": [
                {
                  "type": "string",
                  "pattern": "^cl_[0-7][0-9A-HJKMNP-TV-Z]{25}(?![\\s\\S])"
                },
                {
                  "type": "string",
                  "maxLength": 2048,
                  "pattern": "^https:\\/\\/(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\\.)*(?!(?:[0-9]+|0x[0-9a-f]*)(?![a-z0-9-]))[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?::(?:6553[0-5]|655[0-2][0-9]|65[0-4][0-9]{2}|6[0-4][0-9]{3}|[1-5][0-9]{4}|[1-9][0-9]{0,3}))?(?:\\/(?!(?:\\.|%2[eE]){1,2}(?:[/?]|(?![\\s\\S])))[\\x21\\x22\\x24-\\x2e\\x30-\\x3e\\x40-\\x5b\\x5d-\\x7e]*)+(?:\\?[\\x21\\x22\\x24-\\x5b\\x5d-\\x7e]*)?(?![\\s\\S])"
                }
              ]
            }
          },
          "required": [
            "client_id"
          ],
          "additionalProperties": false
        },
        "authorization_details": {
          "minItems": 1,
          "maxItems": 4,
          "type": "array",
          "items": {
            "oneOf": [
              {
                "type": "object",
                "properties": {
                  "type": {
                    "type": "string",
                    "const": "urn:autonym:authorization-details:contribute"
                  },
                  "contribute": {
                    "minItems": 1,
                    "maxItems": 32,
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "domain": {
                          "type": "string",
                          "pattern": "^[a-z][a-z0-9_.-]{0,63}$"
                        },
                        "keys": {
                          "minItems": 1,
                          "maxItems": 128,
                          "type": "array",
                          "items": {
                            "type": "string",
                            "pattern": "^[a-z][a-z0-9_.-]{0,63}$"
                          }
                        }
                      },
                      "required": [
                        "domain",
                        "keys"
                      ],
                      "additionalProperties": false
                    }
                  },
                  "max_events": {
                    "type": "integer",
                    "exclusiveMinimum": 0,
                    "maximum": 100000
                  },
                  "allow_confirmation": {
                    "type": "boolean"
                  }
                },
                "required": [
                  "type",
                  "contribute",
                  "max_events",
                  "allow_confirmation"
                ],
                "additionalProperties": false,
                "description": "The RFC 9396 authorization_details entry that requests a contribution grant (A6.2). Domains are unique, and so are the keys of each domain."
              }
            ]
          }
        }
      },
      "required": [
        "iss",
        "aud",
        "sub",
        "client_id",
        "jti",
        "iat",
        "exp",
        "cnf",
        "autonym_grant_id",
        "autonym_purpose",
        "authorization_details"
      ],
      "additionalProperties": false
    }
  ],
  "description": "RFC 9068 access-token claims of a record grant (A6.3). exp is after iat by at most 3,600 seconds, and never after the grant expires."
}
