openapi: 3.0.0
info:
  title: Authlier API
  description: Authentication and site management system
  version: 1.0.0
servers:
  - url: https://authlier.com/v1/
    description: API server

components:
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: authorization
    SecretKeyAuth:
      type: apiKey
      in: header
      name: secret-Key
    SiteAdminToken:
      type: http
      scheme: bearer
      bearerFormat: JWT

  schemas:
    Site:
      type: object
      properties:
        id:
          type: string
          description: Site ID
        site_name:
          type: string
          description: Name of the site
        domain:
          type: string
          description: Domain name
        redirect_url:
          type: string
          description: URL to redirect after login
        email_required:
          type: boolean
          description: Whether email is required
        phone_required:
          type: boolean
          description: Whether phone is required
        token_expiry_hours:
          type: integer
          description: Token expiry duration in hours
        active:
          type: boolean
          description: Whether site is active
        api_key:
          type: string
          description: Site API key

    SiteUser:
      type: object
      properties:
        id:
          type: string
          description: User ID
        username:
          type: string
          description: Username
        is_active:
          type: boolean
          description: Whether user is active
        is_verified:
          type: boolean
          description: Whether user is verified
        site:
          type: string
          description: Associated site ID
        email:
          type: string
          description: Email
        phone:
          type: string
          description: Phone number
        metadata:
          type: string
          description: Unique user info for your site
        password:
          type: string
          description: User password
        token:
          type: string
          description: Used to return a secure user token

    ChallengeResponse:
      type: object
      properties:
        success:
          type: boolean
          description: Challenge processing status

paths:
  /site/:
    get:
      security:
        - SiteAdminToken: []
      summary: List sites
      responses:
        '200':
          description: List of sites
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Site'
    post:
      security:
        - SiteAdminToken: []
      summary: Create new site
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Site'
      responses:
        '201':
          description: Site created successfully
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Site'

  /site/{id}/:
    get:
      security:
        - SiteAdminToken: []
      summary: Get site details
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Site details
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Site'
    put:
      security:
        - SiteAdminToken: []
      summary: Update site
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Site'
      responses:
        '200':
          description: Updated site
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Site'
    delete:
      security:
        - SiteAdminToken: []
      summary: Delete site
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
      responses:
        '204':
          description: Site deleted

  /siteuser/:
    get:
      security:
        - ApiKeyAuth: []
        - SecretKeyAuth: []
      summary: List site users
      responses:
        '200':
          description: List of users
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/SiteUser'
    post:
      security:
        - ApiKeyAuth: []
        - SecretKeyAuth: []
      summary: Create new user
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                username:
                  type: string
                  description: User username
                password:
                  type: string
                  description: User password
                email:
                  type: string
                  description: User email
                phone:
                  type: string
                  description: User phone
                metadata:
                  type: string
                  description: User metadata
      responses:
        '201':
          description: User created successfully
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SiteUser'

  /siteuser/{id}/:
    get:
      security:
        - ApiKeyAuth: []
        - SecretKeyAuth: []
      summary: Get user details
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
      responses:
        '200':
          description: User details
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SiteUser'
    put:
      security:
        - ApiKeyAuth: []
        - SecretKeyAuth: []
      summary: Update user
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SiteUser'
      responses:
        '200':
          description: Updated user
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SiteUser'
    delete:
      security:
        - ApiKeyAuth: []
        - SecretKeyAuth: []
      summary: Delete user
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
      responses:
        '204':
          description: User deleted

  /user_authenticate/:
    post:
      security:
        - ApiKeyAuth: []
        - SecretKeyAuth: []
      summary: Authenticate with token
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                token:
                  type: string
                  description: Authentication secure user token
      responses:
        '200':
          description: Authentication successful
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SiteUser'
        '401':
          description: Invalid credentials

    put:
      security:
        - ApiKeyAuth: []
        - SecretKeyAuth: []
      summary: Refresh token (invalidate current token)
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                token:
                  type: string
                  description: A secure user token
      responses:
        '200':
          description: Token refreshed
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SiteUser'

    delete:
      security:
        - ApiKeyAuth: []
        - SecretKeyAuth: []
      summary: Revoke secure user token
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                token:
                  type: string
                  description: A secure user token
      responses:
        '200':
          description: Token revoked

    patch:
      security:
        - ApiKeyAuth: []
        - SecretKeyAuth: []
      summary: Login with username/password
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                username:
                  type: string
                password:
                  type: string
      responses:
        '200':
          description: Authentication successful
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SiteUser'
        '401':
          description: Invalid credentials

  /user_challenge/:
    get:
      summary: Process authentication challenge
      parameters:
        - name: type
          in: query
          required: true
          schema:
            type: string
        - name: q
          in: query
          required: true
          schema:
            type: string
        - name: site
          in: query
          required: true
          schema:
            type: string
        - name: password
          in: query
          schema:
            type: string
      responses:
        '200':
          description: Challenge processed successfully
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ChallengeResponse'
        '404':
          description: Challenge not found

  /user_password_reset/:
    post:
      security:
        - ApiKeyAuth: []
        - SecretKeyAuth: []
      summary: Initiate password reset
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                email:
                  type: string
      responses:
        '200':
          description: Password reset initiated

tags:
  - name: Sites
    description: Site management operations
  - name: Users
    description: Site user management operations
  - name: Authentication
    description: User authentication operations
