# POST /v2/auth

Administrator anmelden oder API-Token beziehen

Meldet einen Administrator mit email/password oder einen nicht öffentlichen API-Zugang mit key/secret an (grant-type=password). Alternativ signiert authorization_code einen 50-Zeichen-Übergabetoken samt zugelassenem App-Callback für den anschließenden Browser-Login. Header grant-type hat Vorrang vor dem gleichnamigen JSON-Feld. Administratoren mit zweitem Faktor erhalten zunächst einen eingeschränkten 2FA-Kontext. API-Logins liefern access_token oben im Antwortobjekt, Administratoren auf dem Produktionssystem üblicherweise ein _edlogin-Cookie. Konto-Kontexte in data.login.data werden später über edid gewählt; Passwörter/Secrets/Token nie protokollieren.

- Operation-ID: post_v2_auth
- Dokumentation: /docs/api/v2/operations/post-v2-auth-307d710f787a/
- OpenAPI-Version: 3.2.1
- Vollständige Spezifikation: /docs/api/v2/openapi.json
- Dokumentationsstatus: reviewed
- Ändert Zustand: ja
- Für Automation freigegeben: nein

## Server

Serverwerte stammen unverändert aus der Datei. Eine lokale Entwicklungsadresse ist keine bestätigte Produktionsadresse. `API_ORIGIN` muss auf die passende Instanz gesetzt werden.

```json
[
  {
    "url": "https://app2.edoobox.com",
    "description": "edoobox API"
  }
]
```

## Authentifizierung

Für diesen Endpunkt deklariert die Spezifikation keine OpenAPI-Authentifizierung (`security: []`). Weitere Bedingungen stehen in der Beschreibung und den edoobox-Hinweisen.

### Wirksame Security Requirements und vollständige Verfahren

```json
{
  "security": [],
  "securitySchemes": {}
}
```

## Parameter

| Name | Ort | Pflicht | Beschreibung |
| --- | --- | --- | --- |
| language | header | nein | Account language code, where the resource supports setLanguage(). |
| grant-type | header | nein | Alternativ zum JSON-Feld; wird zuerst ausgewertet. |

### Vollständige wirksame Parameterdefinitionen

```json
[
  {
    "name": "language",
    "in": "header",
    "required": false,
    "description": "Account language code, where the resource supports setLanguage().",
    "schema": {
      "type": "string",
      "examples": [
        "de"
      ]
    }
  },
  {
    "name": "grant-type",
    "in": "header",
    "required": false,
    "schema": {
      "type": "string",
      "enum": [
        "password",
        "authorization_code"
      ]
    },
    "description": "Alternativ zum JSON-Feld; wird zuerst ausgewertet."
  }
]
```

## Anfrage

```json
{
  "required": true,
  "content": {
    "application/json": {
      "schema": {
        "type": "object",
        "properties": {
          "grant-type": {
            "type": "string",
            "enum": [
              "password",
              "authorization_code"
            ]
          },
          "email": {
            "type": "string",
            "format": "email"
          },
          "password": {
            "type": "string",
            "writeOnly": true,
            "x-edoobox-sensitive": true,
            "description": "Nur synthetisches Beispiel; tatsächlich zurückgegebenes geschütztes Material sicher übergeben.",
            "minLength": 8
          },
          "key": {
            "type": "string",
            "writeOnly": true,
            "x-edoobox-sensitive": true,
            "description": "API-Schlüssel mit Präfix key_; aus dem geschützten API-Zugang beziehen."
          },
          "secret": {
            "type": "string",
            "writeOnly": true,
            "x-edoobox-sensitive": true,
            "description": "API-Secret mit Präfix sec_; nur bei Erstellung ausgegeben."
          },
          "token": {
            "type": "string",
            "writeOnly": true,
            "x-edoobox-sensitive": true,
            "description": "Nur synthetisches Beispiel; tatsächlich zurückgegebenes geschütztes Material sicher übergeben.",
            "minLength": 50,
            "maxLength": 50
          },
          "redirect_uri": {
            "type": "string",
            "description": "App-Callback beginnend mit com.edoobox.admission://, com.edoobox.scan:// oder com.edoobox.event://."
          },
          "reply": {
            "type": "string",
            "description": "cookie (Standard), code (App-Übergabe) oder token (Administrator-Tokenantwort ist umgebungsabhängig eingeschränkt)."
          },
          "remember": {
            "description": "PHP-normalisierte Remember-Auswahl; kanonisch Boolean. true verlängert Administrator-Sitzungen.",
            "examples": [
              false
            ]
          },
          "expire": {
            "type": [
              "string",
              "number"
            ],
            "description": "Optionaler API-Ablaufzeitpunkt, durch dP in Unixzeit normalisiert."
          },
          "state": {
            "type": "string",
            "writeOnly": true,
            "x-edoobox-sensitive": true,
            "description": "Signierter State aus dem authorization_code-Vorlauf bei reply=code."
          },
          "g-recaptcha-response": {
            "type": "string",
            "writeOnly": true,
            "x-edoobox-sensitive": true,
            "description": "Bedingt erforderlicher reCAPTCHA-Nachweis nach verdächtigen Anmeldeversuchen."
          }
        },
        "additionalProperties": true,
        "anyOf": [
          {
            "required": [
              "email",
              "password"
            ]
          },
          {
            "required": [
              "key",
              "secret"
            ]
          },
          {
            "required": [
              "token",
              "redirect_uri"
            ]
          }
        ],
        "description": "grant-type muss im Header oder JSON stehen. Das JSON-Schema kann die Header-Alternative nicht als erforderliches Body-Feld ausdrücken.",
        "allOf": [
          {
            "if": {
              "required": [
                "grant-type"
              ],
              "properties": {
                "grant-type": {
                  "const": "password"
                }
              }
            },
            "then": {
              "anyOf": [
                {
                  "required": [
                    "email",
                    "password"
                  ]
                },
                {
                  "required": [
                    "key",
                    "secret"
                  ]
                }
              ]
            }
          },
          {
            "if": {
              "required": [
                "grant-type"
              ],
              "properties": {
                "grant-type": {
                  "const": "authorization_code"
                }
              }
            },
            "then": {
              "required": [
                "token",
                "redirect_uri"
              ]
            }
          }
        ]
      },
      "examples": {
        "request": {
          "summary": "Administrator anmelden oder API-Token beziehen",
          "value": {
            "grant-type": "password",
            "email": "alex@example.invalid",
            "password": "Synthetic-Password-42!",
            "reply": "cookie",
            "remember": false
          }
        }
      }
    }
  }
}
```

## Antworten

HTTP-Status und Antwortinhalt gemeinsam auswerten. Die folgenden Beschreibungen und Schemata sind die Angaben der Quelldatei.

```json
{
  "200": {
    "description": "Je nach Grant Login-Kontext mit optionalem Login-Payload, Cookie-/Tokenmodus oder {state,redirect_uri} für App-Übergabe; API-access_token steht auf oberster Ebene. reply=code kann ausschließlich {code} liefern.",
    "content": {
      "application/json": {
        "example": {
          "success": true,
          "error": false,
          "data": {
            "edid": "edid_synthetic_login_context",
            "cookie": "_edlogin",
            "token": false
          }
        },
        "schema": {
          "type": "object",
          "properties": {
            "success": {
              "type": "boolean"
            },
            "error": {
              "type": [
                "boolean",
                "string"
              ]
            },
            "error_code": {
              "type": "string"
            },
            "data": {
              "type": "object",
              "properties": {
                "edid": {
                  "type": "string",
                  "description": "Opaker Login-Kontext edid aus der Authentifizierungsantwort. Keine Objekt- oder Datenbank-ID.",
                  "examples": [
                    "edid_synthetic_login_context"
                  ]
                },
                "login": {
                  "type": "object",
                  "additionalProperties": true
                },
                "token": {
                  "type": [
                    "string",
                    "boolean"
                  ],
                  "x-edoobox-sensitive": true
                },
                "cookie": {
                  "type": [
                    "string",
                    "boolean"
                  ]
                },
                "code": {
                  "type": "string",
                  "x-edoobox-sensitive": true,
                  "description": "Geschütztes Authentifizierungs- oder Wiederherstellungsmaterial; nicht protokollieren."
                },
                "state": {
                  "type": "string",
                  "x-edoobox-sensitive": true,
                  "description": "Geschütztes Authentifizierungs- oder Wiederherstellungsmaterial; nicht protokollieren."
                },
                "redirect_uri": {
                  "type": "string"
                }
              },
              "additionalProperties": true
            },
            "type": {
              "type": "string"
            }
          },
          "additionalProperties": true
        }
      }
    }
  },
  "400": {
    "description": "Invalid request.",
    "content": {
      "application/json": {
        "example": {
          "success": false,
          "error": "ED40006"
        }
      }
    }
  },
  "401": {
    "description": "Missing/expired token, missing account context, account paused or model-specific authorization failure.",
    "content": {
      "application/json": {
        "example": {
          "success": false,
          "error": "ED40103"
        }
      }
    }
  },
  "402": {
    "description": "Missing/invalid action data or subscription/operation restriction.",
    "content": {
      "application/json": {
        "example": {
          "success": false,
          "error": "ED80100"
        }
      }
    }
  },
  "403": {
    "description": "Permission denied. Browser CORS rejection may have an empty body.",
    "content": {
      "application/json": {
        "example": {
          "success": false,
          "error": "ED40340"
        }
      }
    }
  },
  "404": {
    "description": "Unknown resource/action or unsupported method.",
    "content": {
      "application/json": {
        "example": {
          "success": false,
          "error": "ED80019"
        }
      }
    }
  },
  "422": {
    "description": "Validation failed.",
    "content": {
      "application/json": {
        "example": {
          "success": false,
          "error": "ED80020"
        }
      }
    }
  },
  "429": {
    "description": "Request/login rate limit exceeded. Honor Retry-After when supplied; legacy rate-limit paths may omit it. Retry only proven reads within a bounded deadline; a mutation is never automatically replayed after an ambiguous response.",
    "content": {
      "application/json": {
        "example": {
          "success": false,
          "error": "ED42902"
        }
      }
    },
    "headers": {
      "Retry-After": {
        "description": "Optional server delay in whole seconds or an HTTP date. Absence is not permission for an immediate retry.",
        "schema": {
          "type": "string",
          "examples": [
            "30"
          ]
        }
      }
    }
  },
  "502": {
    "description": "Server-side operation failed.",
    "content": {
      "application/json": {
        "example": {
          "success": false,
          "error": "ED50201"
        }
      }
    }
  }
}
```

## Aufrufbeispiele

Anpassen vor dem Ausführen. Platzhalter und veröffentlichte Beispiele sind synthetisch. Die Beispiele senden hier keine Anfrage; sie ergänzen keine unbekannten Pflichtfelder.

### cURL

```sh
# Request Body: synthetisches Beispiel aus der Spezifikation; Werte und Vollständigkeit vor Verwendung prüfen.
: "${API_ORIGIN:?API_ORIGIN setzen}"
cat > payload.json <<'EDOOBOX_JSON_EXAMPLE'
{
  "grant-type": "password",
  "email": "alex@example.invalid",
  "password": "Synthetic-Password-42!",
  "reply": "cookie",
  "remember": false
}
EDOOBOX_JSON_EXAMPLE
curl --request 'POST' \
  --url "${API_ORIGIN%/}"'/v2/auth' \
  --header 'Content-Type: application/json' \
  --data-binary '@payload.json'
```

### JavaScript (Node.js)

```javascript
// Request Body: synthetisches Beispiel aus der Spezifikation; Werte und Vollständigkeit vor Verwendung prüfen.
const required = (name) => {
  const value = process.env[name];
  if (!value) throw new Error(`Set ${name}`);
  return value;
};
let path = "/v2/auth";
const origin = required('API_ORIGIN');
const url = new URL((origin.endsWith('/') ? origin.slice(0, -1) : origin) + path);
const headers = {};
headers['Content-Type'] = "application/json";
const body = JSON.stringify({
  "grant-type": "password",
  "email": "alex@example.invalid",
  "password": "Synthetic-Password-42!",
  "reply": "cookie",
  "remember": false
});
const response = await fetch(url, { method: "POST", headers, body, redirect: 'manual' });
const text = await response.text();
console.log(response.status, text);
// HTTP-Status und dokumentierte error/success-Felder gemeinsam prüfen.
```

### Python

```python
# Request Body: synthetisches Beispiel aus der Spezifikation; Werte und Vollständigkeit vor Verwendung prüfen.
import os
import urllib.parse
import urllib.request
import urllib.error

path = "/v2/auth"
url = os.environ["API_ORIGIN"].rstrip("/") + path
headers = {}
headers["Content-Type"] = "application/json"
body = "{\"grant-type\":\"password\",\"email\":\"alex@example.invalid\",\"password\":\"Synthetic-Password-42!\",\"reply\":\"cookie\",\"remember\":false}".encode("utf-8")

# Redirects nicht automatisch verfolgen.
class NoRedirect(urllib.request.HTTPRedirectHandler):
    def redirect_request(self, req, fp, code, msg, headers, newurl):
        return None
request = urllib.request.Request(url, headers=headers, method="POST", data=body)
try:
    response = urllib.request.build_opener(NoRedirect).open(request, timeout=30)
except urllib.error.HTTPError as error:
    response = error
print(response.status, response.read().decode("utf-8", errors="replace"))
# HTTP-Status und dokumentierte error/success-Felder gemeinsam prüfen.
```

## Vollständige Operationsdefinition und edoobox-Hinweise

Alle Originalfelder einschliesslich `x-edoobox-*`, requestBody und responses bleiben erhalten. Teilweise dokumentierte Schemata sind kein vollständiger Validierungsvertrag.

```json
{
  "operationId": "post_v2_auth",
  "summary": "Administrator anmelden oder API-Token beziehen",
  "description": "Meldet einen Administrator mit email/password oder einen nicht öffentlichen API-Zugang mit key/secret an (grant-type=password). Alternativ signiert authorization_code einen 50-Zeichen-Übergabetoken samt zugelassenem App-Callback für den anschließenden Browser-Login. Header grant-type hat Vorrang vor dem gleichnamigen JSON-Feld. Administratoren mit zweitem Faktor erhalten zunächst einen eingeschränkten 2FA-Kontext. API-Logins liefern access_token oben im Antwortobjekt, Administratoren auf dem Produktionssystem üblicherweise ein _edlogin-Cookie. Konto-Kontexte in data.login.data werden später über edid gewählt; Passwörter/Secrets/Token nie protokollieren.",
  "tags": [
    "auth"
  ],
  "security": [],
  "parameters": [
    {
      "name": "language",
      "in": "header",
      "required": false,
      "description": "Account language code, where the resource supports setLanguage().",
      "schema": {
        "type": "string",
        "examples": [
          "de"
        ]
      }
    },
    {
      "name": "grant-type",
      "in": "header",
      "required": false,
      "schema": {
        "type": "string",
        "enum": [
          "password",
          "authorization_code"
        ]
      },
      "description": "Alternativ zum JSON-Feld; wird zuerst ausgewertet."
    }
  ],
  "responses": {
    "200": {
      "description": "Je nach Grant Login-Kontext mit optionalem Login-Payload, Cookie-/Tokenmodus oder {state,redirect_uri} für App-Übergabe; API-access_token steht auf oberster Ebene. reply=code kann ausschließlich {code} liefern.",
      "content": {
        "application/json": {
          "example": {
            "success": true,
            "error": false,
            "data": {
              "edid": "edid_synthetic_login_context",
              "cookie": "_edlogin",
              "token": false
            }
          },
          "schema": {
            "type": "object",
            "properties": {
              "success": {
                "type": "boolean"
              },
              "error": {
                "type": [
                  "boolean",
                  "string"
                ]
              },
              "error_code": {
                "type": "string"
              },
              "data": {
                "type": "object",
                "properties": {
                  "edid": {
                    "type": "string",
                    "description": "Opaker Login-Kontext edid aus der Authentifizierungsantwort. Keine Objekt- oder Datenbank-ID.",
                    "examples": [
                      "edid_synthetic_login_context"
                    ]
                  },
                  "login": {
                    "type": "object",
                    "additionalProperties": true
                  },
                  "token": {
                    "type": [
                      "string",
                      "boolean"
                    ],
                    "x-edoobox-sensitive": true
                  },
                  "cookie": {
                    "type": [
                      "string",
                      "boolean"
                    ]
                  },
                  "code": {
                    "type": "string",
                    "x-edoobox-sensitive": true,
                    "description": "Geschütztes Authentifizierungs- oder Wiederherstellungsmaterial; nicht protokollieren."
                  },
                  "state": {
                    "type": "string",
                    "x-edoobox-sensitive": true,
                    "description": "Geschütztes Authentifizierungs- oder Wiederherstellungsmaterial; nicht protokollieren."
                  },
                  "redirect_uri": {
                    "type": "string"
                  }
                },
                "additionalProperties": true
              },
              "type": {
                "type": "string"
              }
            },
            "additionalProperties": true
          }
        }
      }
    },
    "400": {
      "description": "Invalid request.",
      "content": {
        "application/json": {
          "example": {
            "success": false,
            "error": "ED40006"
          }
        }
      }
    },
    "401": {
      "description": "Missing/expired token, missing account context, account paused or model-specific authorization failure.",
      "content": {
        "application/json": {
          "example": {
            "success": false,
            "error": "ED40103"
          }
        }
      }
    },
    "402": {
      "description": "Missing/invalid action data or subscription/operation restriction.",
      "content": {
        "application/json": {
          "example": {
            "success": false,
            "error": "ED80100"
          }
        }
      }
    },
    "403": {
      "description": "Permission denied. Browser CORS rejection may have an empty body.",
      "content": {
        "application/json": {
          "example": {
            "success": false,
            "error": "ED40340"
          }
        }
      }
    },
    "404": {
      "description": "Unknown resource/action or unsupported method.",
      "content": {
        "application/json": {
          "example": {
            "success": false,
            "error": "ED80019"
          }
        }
      }
    },
    "422": {
      "description": "Validation failed.",
      "content": {
        "application/json": {
          "example": {
            "success": false,
            "error": "ED80020"
          }
        }
      }
    },
    "429": {
      "description": "Request/login rate limit exceeded. Honor Retry-After when supplied; legacy rate-limit paths may omit it. Retry only proven reads within a bounded deadline; a mutation is never automatically replayed after an ambiguous response.",
      "content": {
        "application/json": {
          "example": {
            "success": false,
            "error": "ED42902"
          }
        }
      },
      "headers": {
        "Retry-After": {
          "description": "Optional server delay in whole seconds or an HTTP date. Absence is not permission for an immediate retry.",
          "schema": {
            "type": "string",
            "examples": [
              "30"
            ]
          }
        }
      }
    },
    "502": {
      "description": "Server-side operation failed.",
      "content": {
        "application/json": {
          "example": {
            "success": false,
            "error": "ED50201"
          }
        }
      }
    }
  },
  "x-edoobox-mutates-state": true,
  "requestBody": {
    "required": true,
    "content": {
      "application/json": {
        "schema": {
          "type": "object",
          "properties": {
            "grant-type": {
              "type": "string",
              "enum": [
                "password",
                "authorization_code"
              ]
            },
            "email": {
              "type": "string",
              "format": "email"
            },
            "password": {
              "type": "string",
              "writeOnly": true,
              "x-edoobox-sensitive": true,
              "description": "Nur synthetisches Beispiel; tatsächlich zurückgegebenes geschütztes Material sicher übergeben.",
              "minLength": 8
            },
            "key": {
              "type": "string",
              "writeOnly": true,
              "x-edoobox-sensitive": true,
              "description": "API-Schlüssel mit Präfix key_; aus dem geschützten API-Zugang beziehen."
            },
            "secret": {
              "type": "string",
              "writeOnly": true,
              "x-edoobox-sensitive": true,
              "description": "API-Secret mit Präfix sec_; nur bei Erstellung ausgegeben."
            },
            "token": {
              "type": "string",
              "writeOnly": true,
              "x-edoobox-sensitive": true,
              "description": "Nur synthetisches Beispiel; tatsächlich zurückgegebenes geschütztes Material sicher übergeben.",
              "minLength": 50,
              "maxLength": 50
            },
            "redirect_uri": {
              "type": "string",
              "description": "App-Callback beginnend mit com.edoobox.admission://, com.edoobox.scan:// oder com.edoobox.event://."
            },
            "reply": {
              "type": "string",
              "description": "cookie (Standard), code (App-Übergabe) oder token (Administrator-Tokenantwort ist umgebungsabhängig eingeschränkt)."
            },
            "remember": {
              "description": "PHP-normalisierte Remember-Auswahl; kanonisch Boolean. true verlängert Administrator-Sitzungen.",
              "examples": [
                false
              ]
            },
            "expire": {
              "type": [
                "string",
                "number"
              ],
              "description": "Optionaler API-Ablaufzeitpunkt, durch dP in Unixzeit normalisiert."
            },
            "state": {
              "type": "string",
              "writeOnly": true,
              "x-edoobox-sensitive": true,
              "description": "Signierter State aus dem authorization_code-Vorlauf bei reply=code."
            },
            "g-recaptcha-response": {
              "type": "string",
              "writeOnly": true,
              "x-edoobox-sensitive": true,
              "description": "Bedingt erforderlicher reCAPTCHA-Nachweis nach verdächtigen Anmeldeversuchen."
            }
          },
          "additionalProperties": true,
          "anyOf": [
            {
              "required": [
                "email",
                "password"
              ]
            },
            {
              "required": [
                "key",
                "secret"
              ]
            },
            {
              "required": [
                "token",
                "redirect_uri"
              ]
            }
          ],
          "description": "grant-type muss im Header oder JSON stehen. Das JSON-Schema kann die Header-Alternative nicht als erforderliches Body-Feld ausdrücken.",
          "allOf": [
            {
              "if": {
                "required": [
                  "grant-type"
                ],
                "properties": {
                  "grant-type": {
                    "const": "password"
                  }
                }
              },
              "then": {
                "anyOf": [
                  {
                    "required": [
                      "email",
                      "password"
                    ]
                  },
                  {
                    "required": [
                      "key",
                      "secret"
                    ]
                  }
                ]
              }
            },
            {
              "if": {
                "required": [
                  "grant-type"
                ],
                "properties": {
                  "grant-type": {
                    "const": "authorization_code"
                  }
                }
              },
              "then": {
                "required": [
                  "token",
                  "redirect_uri"
                ]
              }
            }
          ]
        },
        "examples": {
          "request": {
            "summary": "Administrator anmelden oder API-Token beziehen",
            "value": {
              "grant-type": "password",
              "email": "alex@example.invalid",
              "password": "Synthetic-Password-42!",
              "reply": "cookie",
              "remember": false
            }
          }
        }
      }
    }
  },
  "x-edoobox-runtimeMutationGuard": false,
  "x-edoobox-documentationReview": {
    "file": "docs/openapi/operation-contracts/05-auth.json",
    "notes": []
  },
  "x-edoobox-source": {
    "file": "application/controllers/V2.php",
    "method": "coreV2",
    "line": 28
  },
  "x-edoobox-documentationStatus": "reviewed",
  "x-edoobox-readOnly": false,
  "x-edoobox-safeForAutomation": false,
  "x-edoobox-permission": {
    "resource": "auth",
    "short": "auth",
    "checkedByDispatcher": false,
    "levels": [],
    "description": "No account-JWT resource permission levels are applied. Authentication requirements, if any, are defined by this route source-specific boundary and dedicated security scheme."
  }
}
```
