---
title: /authentication
slug: dev/CLSt-authentication
docTags: 
createdAt: 2023-02-23T17:07:09.000Z
---

{
  "id": "Z9XOBdUfRvnybsDMTFpKf",
  "type": "api-oas-v2",
  "data": {
    "method": "POST",
    "url": "/authentication",
    "description": "Creates a JWT token for a user session which should be used to authenticate other requests as a bearer token. The token is valid for 24 h.",
    "contentType": "application/json",
    "request": {
      "pathParameters": [],
      "headerParameters": [],
      "queryParameters": [],
      "bodyDataParameters": [
        {
          "kind": "required",
          "name": "body",
          "type": "object",
          "schema": [
            {
              "name": "strategy",
              "kind": "optional",
              "type": "string",
              "description": "Authentication strategy",
              "example": "local"
            },
            {
              "name": "email",
              "kind": "optional",
              "type": "string",
              "description": "Your email address",
              "example": "myEmail@clemap.ch"
            },
            {
              "name": "password",
              "kind": "optional",
              "type": "string",
              "description": "Your password",
              "example": "myPassword123"
            }
          ],
          "isExpanded": true
        }
      ],
      "formDataParameters": [],
      "oAuthParameters": []
    },
    "responses": [
      {
        "statusCode": "201",
        "description": "successful operation",
        "jsonExample": "",
        "isExpanded": true,
        "schema": [
          {
            "kind": "optional",
            "type": "object",
            "schema": [
              {
                "name": "accessToken",
                "kind": "optional",
                "type": "string",
                "example": "VeryLongToken"
              },
              {
                "name": "user",
                "kind": "optional",
                "type": "object",
                "example": "",
                "schema": [
                  {
                    "name": "_id",
                    "kind": "optional",
                    "type": "string",
                    "example": "myUserId"
                  },
                  {
                    "name": "email",
                    "kind": "optional",
                    "type": "string",
                    "example": "myEmail@clemap.ch"
                  }
                ]
              }
            ],
            "isExpanded": true
          }
        ]
      },
      {
        "statusCode": "401",
        "description": "Unauthorized",
        "jsonExample": "",
        "isExpanded": true,
        "schema": [
          {
            "kind": "optional",
            "type": "object",
            "schema": [
              {
                "name": "name",
                "kind": "optional",
                "type": "string",
                "description": "name",
                "example": "NotAuthenticated"
              },
              {
                "name": "message",
                "kind": "optional",
                "type": "string",
                "description": "name",
                "example": "Invalid login"
              },
              {
                "name": "code",
                "kind": "optional",
                "type": "number",
                "description": "name",
                "example": 401
              },
              {
                "name": "className",
                "kind": "optional",
                "type": "string",
                "description": "name",
                "example": "not-authenticated"
              },
              {
                "name": "errors",
                "kind": "optional",
                "type": "object",
                "description": "name",
                "example": "",
                "schema": []
              }
            ],
            "isExpanded": true
          }
        ]
      }
    ],
    "examples": {
      "languages": [
        {
          "id": "1OdUQCKT6elgqH41rt99h",
          "language": "curl",
          "label": "cURL",
          "code": "curl --request POST \\\n     --url /authentication \\\n     --header 'accept: application/json'"
        },
        {
          "id": "gu8hgYgb6KKHG4sXZTdlJ",
          "language": "javascript",
          "label": "javascript",
          "code": "var myHeaders = new Headers();\nmyHeaders.append(\"accept\", \"application/json\");\nmyHeaders.append(\"content-type\", \"application/json\");\n\nvar requestOptions = {\n   method: 'POST',\n   headers: myHeaders,\n   redirect: 'follow'\n};\n\nfetch(\"/authentication\", requestOptions)\n   .then(response => response.text())\n   .then(result => console.log(result))\n   .catch(error => console.log('error', error));"
        },
        {
          "id": "BcGy9tpSYJ9_uB5Tna4uD",
          "language": "ruby",
          "label": "Ruby",
          "code": "require \"uri\"\nrequire \"json\"\nrequire \"net/http\"\n\nurl = URI(\"/authentication\")\n\nhttp = Net::HTTP.new(url.host, url.port);\nrequest = Net::HTTP::Post.new(url)\nrequest[\"accept\"] = \"application/json\"\nrequest[\"content-type\"] = \"application/json\"\n\nresponse = http.request(request)\nputs response.read_body\n"
        },
        {
          "id": "Xl_4PGzsZP1lBRaXfyyrt",
          "language": "python",
          "label": "Python",
          "code": "import requests\nimport json\n\nurl = \"/authentication\"\n\npayload = {}\nheaders = {\n   'accept': 'application/json',\n   'content-type': 'application/json'\n}\n\nresponse = requests.request(\"POST\", url, headers=headers, data=payload)\n\nprint(response.text)\n"
        }
      ],
      "selectedLanguageId": "1OdUQCKT6elgqH41rt99h"
    },
    "results": {
      "languages": [
        {
          "id": "response-0-201",
          "language": "201",
          "code": "// successful operation\n{\n  \"accessToken\": \"VeryLongToken\",\n  \"user\": {\n    \"_id\": \"myUserId\",\n    \"email\": \"myEmail@clemap.ch\"\n  }\n}"
        },
        {
          "id": "response-1-401",
          "language": "401",
          "code": "// Unauthorized\n{\n  \"name\": \"NotAuthenticated\",\n  \"message\": \"Invalid login\",\n  \"code\": 401,\n  \"className\": \"not-authenticated\",\n  \"errors\": {}\n}"
        }
      ],
      "selectedLanguageId": "response-0-201"
    }
  },
  "children": [
    {
      "id": "WJFKlvVOmccQYH8hsdTyt",
      "type": "paragraph",
      "children": [
        {
          "text": "Creates a JWT token for a user session which should be used to authenticate other requests as a bearer token. The token is valid for 24 h."
        }
      ]
    }
  ]
}