{
  "openapi": "3.0.3",
  "info": {
    "title": "Credentials management service REST",
    "version": "v1",
    "description": ""
  },
  "servers": [
    {
      "url": "{schema}://{host}/api/{version}",
      "description": "API Server"
    }
  ],
  "paths": {
    "/endpoints/{endpointId}/tokens": {
      "parameters": [
        {
          "name": "endpointId",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          },
          "description": "Identifies the endpoint to which operations with an endpoint token are applied.",
          "example": "7d5dda9b-c9f6-427d-91ea-9891a4f62cbb"
        }
      ],
      "get": {
        "description": "Returns a JSON representation of the provisioned endpoint tokens.",
        "responses": {
          "200": {
            "description": "An array of the endpoint token objects.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TokenList"
                }
              }
            }
          }
        },
        "security": [
          {
            "oauth_2_0": [
              "endpoint:read"
            ]
          }
        ],
        "parameters": [
          {
            "name": "status",
            "in": "query",
            "description": "Filters results by the endpoint token statuses.",
            "required": false,
            "schema": {
              "type": "cm-api-types.EndpointTokenStatuses[]"
            },
            "example": [
              "Inactive",
              "Active",
              "Suspended",
              "Revoked"
            ]
          },
          {
            "name": "offset",
            "in": "query",
            "description": "The starting index from which the server should return data.",
            "required": false,
            "schema": {
              "type": "integer"
            },
            "example": 10
          },
          {
            "name": "limit",
            "in": "query",
            "description": "The maximum number of items to be returned.",
            "required": false,
            "schema": {
              "type": "integer",
              "default": 20
            },
            "example": 2
          },
          {
            "name": "order",
            "in": "query",
            "description": "The sorting order of returned tokens (from the newest to the oldest and vice versa).",
            "required": false,
            "schema": {
              "type": "string",
              "default": "DESC",
              "enum": [
                "ASC",
                "DESC"
              ]
            },
            "example": "ASC"
          }
        ]
      },
      "post": {
        "description": "Provisions a new endpoint token.",
        "responses": {
          "201": {
            "description": "The endpoint token was successfully provisioned.",
            "headers": {
              "Location": {
                "description": "The URL to access a newly created endpoint token.",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EndpointTokenProvisionResponse"
                },
                "example": {
                  "token": "02226466-e744-48ac-8f0c-a57fe4e77de4",
                  "applicationName": "sample-application-1",
                  "createdDate": "2017-03-17T11:30:02.643Z",
                  "status": "Inactive"
                }
              }
            }
          },
          "400": {
            "description": "An unknown application name.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ClientErrorResponse"
                }
              }
            }
          },
          "409": {
            "description": "A conflict has occured.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "security": [
          {
            "oauth_2_0": [
              "endpoint:update"
            ]
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/EndpointTokenProvision"
              }
            }
          }
        }
      }
    },
    "/endpoints/{endpointId}/tokens/{endpointTokenId}": {
      "parameters": [
        {
          "name": "endpointId",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          },
          "description": "Identifies the endpoint to which operations with an endpoint token are applied.",
          "example": "7d5dda9b-c9f6-427d-91ea-9891a4f62cbb"
        },
        {
          "name": "endpointTokenId",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          },
          "description": "An endpoint token ID to operate on.",
          "example": "33a64df551425fcc55e4d42a148795d9f25f89d4"
        }
      ],
      "get": {
        "description": "Returns endpoint token information.",
        "responses": {
          "200": {
            "description": "Endpoint token.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EndpointTokenStatus"
                }
              }
            }
          }
        },
        "security": [
          {
            "oauth_2_0": [
              "endpoint:read"
            ]
          }
        ]
      },
      "delete": {
        "description": "Deletes an endpoint token.",
        "responses": {
          "204": {
            "description": "The endpoint token was successfully deleted."
          }
        },
        "security": [
          {
            "oauth_2_0": [
              "endpoint:update"
            ]
          }
        ]
      }
    },
    "/endpoints/{endpointId}/tokens/{endpointTokenId}/status": {
      "parameters": [
        {
          "name": "endpointId",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          },
          "description": "Identifies the endpoint to which operations with an endpoint token are applied.",
          "example": "7d5dda9b-c9f6-427d-91ea-9891a4f62cbb"
        },
        {
          "name": "endpointTokenId",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          },
          "description": "An endpoint token ID to operate on.",
          "example": "33a64df551425fcc55e4d42a148795d9f25f89d4"
        }
      ],
      "get": {
        "description": "Returns the current status of the endpoint token.",
        "responses": {
          "200": {
            "description": "Response 200",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "security": [
          {
            "oauth_2_0": [
              "endpoint:read"
            ]
          }
        ]
      },
      "put": {
        "description": "",
        "responses": {},
        "security": [
          {
            "oauth_2_0": [
              "endpoint:update"
            ]
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/EndpointTokenStatusUpdateRequest"
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "oauth_2_0": {
        "type": "oauth2",
        "description": "CM supports OAuth 2.0 for authenticating all API requests.\n",
        "flows": {
          "implicit": {
            "authorizationUrl": "https://auth.example.com/oauth/authorize",
            "scopes": {}
          }
        }
      }
    },
    "schemas": {
      "EndpointTokenStatus": {
        "type": "object",
        "properties": {
          "status": {
            "type": "string",
            "description": "The status of the endpoint token.\n<p>\n<ul>\n  <li>`Inactive` - the token was never used</li>\n  <li>`Active` - the token was already used</li>\n  <li>`Suspended` - frozen token</li>\n  <li>`Revoked` - canceled token</li>\n<ul>\n",
            "enum": [
              "Active",
              "Inactive",
              "Suspended",
              "Revoked"
            ]
          }
        },
        "required": [
          "status"
        ]
      },
      "TokenList": {
        "type": "object",
        "properties": {
          "content": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/EndpointTokenStatus"
            },
            "description": "Array of endpoint tokens with details."
          },
          "totalElements": {
            "type": "integer",
            "description": "The total number of tokens available for this request (ignoring pagination)."
          }
        }
      },
      "EndpointTokenProvision": {
        "type": "object",
        "properties": {
          "token": {
            "type": "string",
            "description": "Endpoint token. Will be generated if not present.\n<p>\nMust not contain plus signs (`+`), number signs (`#`), forward slashes (`/`), or periods (`.`).\n",
            "pattern": "^[^+#/.]+$"
          },
          "applicationName": {
            "type": "string",
            "description": "The application name."
          }
        }
      },
      "EndpointTokenProvisionResponse": {
        "type": "object",
        "properties": {
          "token": {
            "type": "string",
            "description": "Endpoint token."
          },
          "createdDate": {
            "type": "string",
            "format": "rfc3339",
            "description": "Token creation (provisioning) time and date in ISO 8601 format."
          },
          "applicationName": {
            "type": "string",
            "description": "The application name."
          },
          "status": {
            "type": "string",
            "description": "Status of newly provisioned token is always `Inactive`.\n<br>\nToken status will be automatically changed to `Active` after first successful token validation request.\n",
            "enum": [
              "Inactive"
            ]
          }
        },
        "required": [
          "token",
          "createdDate",
          "status"
        ]
      },
      "ClientErrorResponse": {
        "type": "object",
        "properties": {
          "message": {
            "type": "string",
            "description": "Detailed error description."
          }
        },
        "required": [
          "message"
        ]
      },
      "EndpointTokenStatusUpdateRequest": {
        "type": "object",
        "properties": {
          "status": {
            "type": "string",
            "description": "The status of the endpoint token.\n<p>\n<ul>\n  <li>`Active` - the token was already used</li>\n  <li>`Suspended` - frozen token</li>\n  <li>`Revoked` - canceled token</li>\n</ul>\n",
            "enum": [
              "Active",
              "Suspended",
              "Revoked"
            ]
          }
        },
        "required": [
          "status"
        ]
      },
      "EndpointTokenStatuses": {
        "type": "string"
      }
    }
  }
}