Basic authentication

Use basic authentication to connect to an API using a username and password passed in the header.

Tip: If you need to add additional properties or validation to your connection, see x-ntx-connection-properties and x-ntx-connection-validation.

How to use basic authentication

To add basic authentication to your OpenAPI Specification:

  1. Add a securityDefinitions object before the final closing brace of your OpenAPI Specification.
  2. Create an object inside the securityDefinitions object to define your basic authentication security.
  3. Inside the object, add the property type with a value of basic.
  4. Inside the HTTP method of each operation that requires basic authentication, add a security array.
  5. Inside the security array, add an object containing a property with:
    1. The key of the security definition object you created earlier.
    2. An empty array as the property's value.

Where to use basic authentication

Use basic authentication in:

  • The securityDefinitions object.
  • The security array of each HTTP method that requires basic authentication.
{
  "swagger": "2.0",
  "host": "api.example.com",
  "schemes": [ "https" ],
  "produces": [ "application/json" ],
  "consumes": [ "application/json" ],
  "paths": {
    "/example": {
      "post": {
        "summary": "Example operation",
        "security": [
          {
            "myBasicAuth": []
          }
        ],
        "parameters": [...],
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
  "securityDefinitions": {
    "myBasicAuth": {
      "type": "basic"
    }
  }
}