> ## Documentation Index
> Fetch the complete documentation index at: https://docs.didit.me/llms.txt
> Use this file to discover all available pages before exploring further.

# 程序化登录 API：直接返回访问 token

> Didit 的 POST /programmatic/login/ 用于无头认证，直接返回访问 token，无需 2FA。面向智能体设计，兼容 MCP，按量付费。



提示词：程序化登录
        将提示词复制到剪贴板



      
      

\<pre>

\`Exchange a verified Didit account's email + password for a fresh JWT access token (headless, no browser).

Endpoint:
POST https://apx.didit.me/auth/v2/programmatic/login/

Authentication:
None. Email + password is the credential.

Request body:
\- email (string, required) — Same email used at /programmatic/register/.
\- password (string, required) — Plain password (HTTPS only).

Account requirements:
The account must have a verified email and password. Accounts created through POST /programmatic/register/ work immediately after email verification. Console-created email/password accounts can also use this endpoint. OAuth-only console accounts must set a password first.

curl example:
curl -X POST https://apx.didit.me/auth/v2/programmatic/login/ \
-H "Content-Type: application/json" \
-d '{
"email": "you@yourdomain.com",
"password": "MyStr0ng!Pass"
}'

Response (200 OK):
\- access_token (string) — RS256 JWT. Pass as "Authorization: Bearer <access_token>" on every Account Management endpoint at apx.didit.me/auth/v2. DO NOT use against verification.didit.me — that host uses x-api-key.
\- refresh_token (string) — RS256 JWT for refresh flows.
\- expires_in (integer) — Default 86400 (24 hours).

Token shape:
\- 24-hour default lifetime.
\- RS256-signed.
\- No browser session is required.

Brute-force protection:
\- Progressive account lockout per email: 5 consecutive failures = 15 min lockout, 10 = 1 hour, 20 = 24 hours.
\- Per-IP rate limit: 20 attempts/minute and 100 attempts/hour.

Failure modes:
\- 400 — { "email": ["..."] } / { "password": ["..."] } field-level errors.
\- 401 — { "detail": "Invalid email or password." }
\- 403 — { "detail": "..." } when SSO policy blocks password login for the account.
\- 429 — { "detail": "Too many login attempts.", "wait": <seconds> } on lockout or per-IP limit. Honour the wait value before retrying.

Recovering your api_key:
After a successful login, call GET /organizations/me/ to enumerate organizations and applications, then GET /organizations/me/{org_id}/applications/{app_id}/ to read the api_key — see /auth-api/get-credentials.

Where to use access_token vs api_key:
\- access_token (Bearer) → https://apx.didit.me/auth/v2/... (org / app management).
\- api_key (x-api-key) → https://verification.didit.me/v3/... (sessions, workflows, billing).

For end-to-end Didit integration, paste in the full prompt at /integration/integration-prompt.`

\</pre>



      
      

粘贴到



## OpenAPI

````yaml zh/openapi-auth.json POST /programmatic/login/
openapi: 3.0.0
info:
  version: 1.0.0
  title: Didit Auth API
  description: >-
    面向开发者和 AI 代理的程序化注册与认证 API。仅需 2 次 API 调用即可完成注册，无需浏览器。对代理最友好的身份证件验证平台。


    ## Base URL


    本规范中的所有 endpoint 均托管在 `https://apx.didit.me/auth/v2`。该主机与验证
    API（`https://verification.didit.me/v3`）不同。请务必区分它们：此认证主机负责签发您的 **JWT 访问
    token**，并允许您列出和管理您的**组织**与**应用**。验证主机则是您调用会话、工作流、AML 等服务的地方，使用此 API 返回的
    **`api_key`** 进行身份验证。


    ## 认证流程运作方式


    1. `POST /programmatic/register/`：提交邮箱 + 密码。

    2. 通过电子邮件接收 6 位字母数字验证码。

    3. `POST /programmatic/verify-email/`：提交验证码。您将获得 JWT
    `access_token`、`refresh_token`、一个组织以及带有 `client_id` + `api_key` 的默认应用。

    4. 保存 `api_key`。在对 `https://verification.didit.me/v3/...` 的每次调用中将其作为
    `x-api-key` 使用。

    5. 在将来的任何机器上，`POST /programmatic/login/` 都可以用您的邮箱 + 密码换取全新的 JWT，然后调用 `GET
    /organizations/me/` 和应用 endpoint 来恢复或轮换凭据。


    JWT 仅在用于本规范中的**账户管理** endpoint 时需要；验证 API 的流量使用的是长期有效的 `api_key`，而非 JWT。


    ## 约定


    - 所有请求体和响应体均为 JSON（`Content-Type: application/json`）。

    - **在测试 `POST /programmatic/register/` 时，请使用真实、可投递的电子邮件地址。** 该 endpoint
    会同步发送验证码，因此保留测试域名（`@example.com`、`@example.org`、`@*.test`、`@*.example`、`@*.invalid`）的地址将被邮件发送系统拒绝，且请求将返回
    `500`。请将示例中的占位符 `you@yourdomain.com` 替换为您实际可以查收的收件箱。

    - 验证错误返回 HTTP `400`，具有以下两种外层结构之一：针对字段级问题的 `{"field": ["message",
    ...]}`，或针对业务规则错误的 `{"detail":
    "message"}`。少数验证器（注册时的密码强度、验证邮箱时的验证码过期）目前会响应纯数组 `["message"]`
    而不是以字段为键的形式，这是已知的服务端不一致性，因此客户端代码应同时支持这两种结构。

    - 身份验证错误将作为 `{"detail": "..."}` 返回，状态码为 HTTP `401`（无效的 bearer token）或
    `403`（缺少 bearer token / 权限不足）。

    - 速率限制响应包含一个以秒为单位的冷却时间字段 `wait`。
servers:
  - url: https://apx.didit.me/auth/v2
    description: 生产环境认证服务器
security: []
tags:
  - name: Programmatic Auth
    description: >-
      邮箱和密码账户生命周期：注册、验证、登录。返回用于访问账户管理 endpoint 的 JWT
      `access_token`，并在验证通过时一并返回您首个应用的 `client_id` 和 `api_key`。
  - name: Account Management
    description: >-
      用于列出组织以及创建、获取或更新应用的经认证 endpoint（JWT bearer）。使用这些 endpoint 可以恢复或轮换用于验证 API
      调用身份的 `api_key`。
paths:
  /programmatic/login/:
    post:
      tags:
        - Programmatic Auth
      summary: 程序化登录
      description: >-
        对任何已验证邮箱/密码的 Didit 账户进行身份验证，并接收一对 RS256 JWT（默认生命周期为 86400
        秒）。在控制台创建的邮箱/密码账户可以使用此 endpoint；仅使用 OAuth 的控制台账户必须先设置密码。
      operationId: programmatic_login
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/LoginRequest'
            examples:
              Default:
                summary: 程序化登录
                value:
                  email: you@yourdomain.com
                  password: MyStr0ng!Pass
      responses:
        '200':
          description: >-
            登录成功。返回一组全新的 JWT。将 `access_token` 作为 `Authorization: Bearer <token>`
            用于 `/organizations/me/...` 的请求，以查询 `org_id`、`app_id` 和
            `api_key`。当账户启用了身份验证器应用或通行密钥时，响应将包含 `2fa_required: true` 和一个
            `temp_token`，而不是直接返回 token。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/LoginResponse'
              examples:
                Success:
                  value:
                    access_token: eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...
                    refresh_token: eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...
                    expires_in: 86400
                    message: Login successful
        '400':
          description: 验证错误。请求体存在字段级问题。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ValidationError'
              examples:
                MissingFields:
                  summary: 空请求体
                  value:
                    email:
                      - This field is required.
                    password:
                      - This field is required.
                InvalidEmail:
                  summary: 邮箱格式错误
                  value:
                    email:
                      - Enter a valid email address.
        '401':
          description: 身份验证被拒绝。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AuthError'
              examples:
                InvalidCredentials:
                  summary: 邮箱与密码不匹配（当账户不存在时也会返回此信息，以避免用户枚举）
                  value:
                    detail: Invalid email or password.
                NotVerified:
                  summary: 账户已存在但邮箱尚未验证
                  value:
                    detail: Please verify your email address before logging in.
                SSORequired:
                  summary: 该账户属于要求 SSO 的组织
                  value:
                    detail:
                      error: sso_required
                      message: Your organization 'Acme Corp' requires SSO login.
                      organization_name: Acme Corp
                      organization_slug: acme-corp
                      sso_url: /sso/acme-corp
        '403':
          description: >-
            账户已恢复，必须先设置新的登录方式才能登录。已向该账户的地址发送了一封包含相关操作链接的邮件。如果账户所在的组织强制要求
            SSO，则会返回带有 `error:
            sso_required`、`organization_name`、`organization_slug` 和 `sso_url` 的
            `403`。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/RecoverySetupRequiredError'
              examples:
                RecoverySetupRequired:
                  summary: 已恢复且尚未设置登录方式的账户
                  value:
                    recovery_setup_required: true
                    setup_link_sent: true
                    message: >-
                      You recovered your account. Open the link we emailed you
                      to set up a new sign-in method.
                    code: recovery_setup_required
        '429':
          description: >-
            账户已锁定（该邮箱近期失败次数过多）或 IP
            受到速率限制（来自该地址的尝试次数过多）。当服务暂时在同时检查尽可能多的密码或验证码时，也会返回此错误并附带 `Retry-After:
            5` 请求头；请在指定的秒数后重试。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/RateLimitError'
              examples:
                AccountLocked:
                  summary: 渐进式锁定已触发
                  value:
                    detail: >-
                      Account temporarily locked due to too many failed login
                      attempts. Please try again later.
                IPRateLimited:
                  summary: 来自此 IP 的请求超过每分钟 20 次或每小时 100 次
                  value:
                    detail: >-
                      Too many login attempts from this IP address. Please wait
                      before trying again.
                PasswordChecksBusy:
                  summary: 正在进行的密码检查过多
                  value:
                    detail: >-
                      Too many sign-in attempts are being processed right now.
                      Please try again in a few seconds.
      security:
        - {}
      x-codeSamples:
        - lang: curl
          label: cURL
          source: |-
            curl -X POST https://apx.didit.me/auth/v2/programmatic/login/ \
              -H "Content-Type: application/json" \
              -d '{
                "email": "you@yourdomain.com",
                "password": "MyStr0ng!Pass"
              }'
        - lang: python
          label: Python
          source: |-
            from didit import Didit

            # This call needs no API key.
            client = Didit()

            result = client.account.login(
                email="you@yourdomain.com",
                password="MyStr0ng!Pass",
            )
            print(result)
        - lang: javascript
          label: Node.js
          source: |-
            import Didit from "@didit-protocol/sdk-node";

            // This call needs no API key.
            const didit = new Didit();

            const result = await didit.account.login({
              email: "you@yourdomain.com",
              password: "MyStr0ng!Pass",
            });
            console.log(result);
        - lang: go
          label: Go
          source: "ctx := context.Background()\n// This call needs no API key.\nclient := didit.NewClient()\n\nresult, err := client.Account.Login(ctx, didit.LoginRequest{\n\tEmail:    \"you@yourdomain.com\",\n\tPassword: \"MyStr0ng!Pass\",\n})\nif err != nil {\n\tlog.Fatal(err)\n}\nfmt.Printf(\"%+v\\n\", result)"
        - lang: java
          label: Java
          source: |-
            import me.didit.Didit;
            import me.didit.types.LoginRequest;

            // This call needs no API key.
            Didit client = new Didit();

            var result = client.account().login(LoginRequest.builder()
                    .email("you@yourdomain.com")
                    .password("MyStr0ng!Pass")
                    .build());
            System.out.println(result);
        - lang: php
          label: PHP
          source: |-
            <?php

            require 'vendor/autoload.php';

            use Didit\DiditClient;

            // This call needs no API key.
            $didit = new DiditClient();

            $result = $didit->account->login([
                'email' => 'you@yourdomain.com',
                'password' => 'MyStr0ng!Pass',
            ]);
            print_r($result->toArray());
        - lang: ruby
          label: Ruby
          source: |-
            require "didit"

            # This call needs no API key.
            didit = Didit::Client.new

            result = didit.account.login(
              email: "you@yourdomain.com",
              password: "MyStr0ng!Pass"
            )
            puts result.to_h
        - lang: csharp
          label: .NET
          source: |-
            using System;
            using System.Text.Json;
            using Didit;

            // This call needs no API key.
            using var client = new DiditClient();

            var result = await client.Account.LoginAsync(new LoginRequest
            {
                Email = "you@yourdomain.com",
                Password = "MyStr0ng!Pass",
            });
            Console.WriteLine(JsonSerializer.Serialize(result));
components:
  schemas:
    LoginRequest:
      type: object
      required:
        - email
        - password
      properties:
        email:
          type: string
          format: email
          example: you@yourdomain.com
        password:
          type: string
          example: MyStr0ng!Pass
    LoginResponse:
      type: object
      properties:
        access_token:
          type: string
          description: 'RS256 签名的 JWT。用作账户管理 endpoint 的 `Authorization: Bearer <token>`。'
        refresh_token:
          type: string
        expires_in:
          type: integer
          description: 访问 token 的生命周期（秒），默认 86400。
          example: 86400
        message:
          type: string
          example: Login successful
    ValidationError:
      description: >-
        验证错误主体。预期的包装格式为针对字段级错误的 `{field: ["message", ...]}` 映射，或针对业务规则错误的
        `{detail: "..."}` 单键包装格式。少数验证器（注册时的密码强度、邮箱验证时的验证码有效性）当前会返回单纯的数组
        `["message"]`（已知的服务端不一致情况）。以下架构保留了该单纯数组分支，以便根据本规范生成的客户端代码可以反序列化当前的响应，但新的客户端代码应将其视为以相关字段为键的形式（`{password:
        [...]}` 或 `{code: [...]}`），服务端契约也将逐步统一为该结构。
      oneOf:
        - type: object
          additionalProperties:
            type: array
            items:
              type: string
          example:
            email:
              - Enter a valid email address.
        - type: object
          properties:
            detail:
              type: string
          example:
            detail: An account with this email already exists.
        - type: array
          items:
            type: string
          example:
            - Invalid or expired verification code.
    AuthError:
      type: object
      description: 认证 / 授权 / 未找到错误响应封装。
      properties:
        detail:
          type: string
          example: Invalid access token
    RecoverySetupRequiredError:
      type: object
      description: >-
        账户已恢复，目前尚未设置登录方式。未签发任何
        token；已向该账户的地址发送了一封包含设置新方式的一次性链接的邮件。打开该链接，完成设置，然后重新登录。
      required:
        - recovery_setup_required
        - setup_link_sent
        - message
        - code
      properties:
        recovery_setup_required:
          type: boolean
          example: true
        setup_link_sent:
          type: boolean
          example: true
        message:
          type: string
          example: >-
            You recovered your account. Open the link we emailed you to set up a
            new sign-in method.
        code:
          type: string
          enum:
            - recovery_setup_required
          example: recovery_setup_required
    RateLimitError:
      type: object
      description: 速率限制或递进式锁定响应。`wait` 为冷却时间（秒）。
      properties:
        detail:
          type: string
          example: >-
            Too many login attempts from this IP address. Please wait before
            trying again.

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.