openapi: 3.0.0
servers:
  - url: https://user-login-dev.keiki.app
  - url: https://user-login.keiki.app
info:
  title: User Auth Api
  description:
    This is the user authentication api. It allows you to sign up, sign in and manage your credentials.
  version: "1.0.0"
security:
  - ApiKeyAuth: []
paths:
  /api/v1/auth/keiki/signin:
    post:
      tags:
        - Deprecated
      description: User sign in
      requestBody:
        content:
          application/json:
            schema:
              type: object
              required:
                - email
                - password
                - device_data
              properties:
                email:
                  type: string
                  example: "test@mail.com"

                password:
                  type: string
                  example: "testPassword!@"
                device_data:
                  $ref: "schemas.yml#/schemas/DeviceData"
      responses:
        200:
          $ref: "#/components/responses/UserDataResponse"
        404:
          $ref: "#/components/responses/NotFound"
        422:
          $ref: "#/components/responses/UnprocessableEntity"
        401:
          $ref: "#/components/responses/Unauthorized"
        500:
          $ref: "#/components/responses/InternalServerError"
  /api/v2/auth/keiki/sign-in:
    post:
      tags:
        - Keiki
      description: User sign in
      requestBody:
        content:
          application/json:
            schema:
              type: object
              required:
                - email
                - password
                - device_data
              properties:
                email:
                  type: string
                  example: "test@mail.com"
                password:
                  type: string
                  example: "testPassword!@"
                device_data:
                  $ref: "schemas.yml#/schemas/DeviceData"
      responses:
        200:
          $ref: "responses.yml#/responses/UserDataResponseV2"
        404:
          $ref: "#/components/responses/NotFound"
        422:
          $ref: "#/components/responses/UnprocessableEntity"
        401:
          $ref: "#/components/responses/Unauthorized"
        500:
          $ref: "#/components/responses/InternalServerError"
  /api/v1/auth/keiki/signup:
    post:
      tags:
        - Deprecated
      description: User sign up (deprecated)
      requestBody:
        content:
          application/json:
            schema:
              type: object
              required:
                - email
                - password
                - receive_emails_with_progress
                - device_data
              properties:
                email:
                  type: string
                  example: "test@mail.com"
                password:
                  type: string
                  example: "testPassword!@"
                receive_emails_with_progress:
                  type: boolean
                  example: true
                device_data:
                  $ref: "schemas.yml#/schemas/DeviceData"
      responses:
        200:
          $ref: "#/components/responses/UserDataResponse"
        409:
          $ref: "#/components/responses/Conflict"
        422:
          $ref: "#/components/responses/UnprocessableEntity"
        500:
          $ref: "#/components/responses/InternalServerError"
  /api/v2/auth/keiki/sign-up:
    post:
      tags:
        - Keiki
      description: User sign up
      requestBody:
        content:
          application/json:
            schema:
              type: object
              required:
                - email
                - password
                - receive_emails_with_progress
                - device_data
              properties:
                email:
                  type: string
                  example: "test@mail.com"
                password:
                  type: string
                  example: "testPassword!@"
                receive_emails_with_progress:
                  type: boolean
                  example: true
                device_data:
                  $ref: "schemas.yml#/schemas/DeviceData"
      responses:
        200:
          $ref: "responses.yml#/responses/UserDataResponseV2"
        409:
          $ref: "#/components/responses/Conflict"
        422:
          $ref: "#/components/responses/UnprocessableEntity"
        500:
          $ref: "#/components/responses/InternalServerError"
  /api/v1/auth/keiki/token-signin:
    post:
      tags:
        - Deprecated
      description: User token sign in (deprecated)
      requestBody:
        content:
          application/json:
            schema:
              type: object
              required:
                - token
                - device_data
              properties:
                token:
                  type: string
                  example: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOiIxNjE2MzUzNjI2OTYxLTU0OTczMTQiLCJlbWFpbCI6InRlc3RAc2lnbnVwLmNvbSIsImJ1bmRsZV9pZCI6Imdlbi50ZWNoLmtlaWtpLndvcmxkIiwiaWF0IjoxNjQ3ODYyODI5fQ.6L_x_htsgvXYwfNp-wZbDFNYakxf2LFR4UYF6mZfLSw"
                device_data:
                  $ref: "schemas.yml#/schemas/DeviceData"
      responses:
        200:
          $ref: "#/components/responses/UserDataResponse"
        404:
          $ref: "#/components/responses/NotFound"
        422:
          $ref: "#/components/responses/UnprocessableEntity"
        500:
          $ref: "#/components/responses/InternalServerError"
  /api/v2/auth/keiki/token-sign-in:
    post:
      tags:
        - Keiki
      description: User token sign in
      requestBody:
        content:
          application/json:
            schema:
              type: object
              required:
                - token
                - device_data
              properties:
                token:
                  type: string
                  example: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOiIxNjE2MzUzNjI2OTYxLTU0OTczMTQiLCJlbWFpbCI6InRlc3RAc2lnbnVwLmNvbSIsImJ1bmRsZV9pZCI6Imdlbi50ZWNoLmtlaWtpLndvcmxkIiwiaWF0IjoxNjQ3ODYyODI5fQ.6L_x_htsgvXYwfNp-wZbDFNYakxf2LFR4UYF6mZfLSw"
                device_data:
                  $ref: "schemas.yml#/schemas/DeviceData"
      responses:
        200:
          $ref: "responses.yml#/responses/UserDataResponseV2"
        404:
          $ref: "#/components/responses/NotFound"
        422:
          $ref: "#/components/responses/UnprocessableEntity"
        500:
          $ref: "#/components/responses/InternalServerError"
  /api/v1/auth/keiki/delete-account:
    post:
      tags:
        - Keiki
      description: Delete user account
      requestBody:
        content:
          application/json:
            schema:
              type: object
              required:
                - token
                - device_data
              properties:
                token:
                  type: string
                  example: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOiIxNjE2MzUzNjI2OTYxLTU0OTczMTQiLCJlbWFpbCI6InRlc3RAc2lnbnVwLmNvbSIsImJ1bmRsZV9pZCI6Imdlbi50ZWNoLmtlaWtpLndvcmxkIiwiaWF0IjoxNjQ3ODYyODI5fQ.6L_x_htsgvXYwfNp-wZbDFNYakxf2LFR4UYF6mZfLSw"
                device_data:
                  $ref: "schemas.yml#/schemas/DeviceData"
      responses:
        200:
          description: "Delete account was successful"
        422:
          $ref: "#/components/responses/UserHasActiveSubscriptionResponse"
        500:
          $ref: "#/components/responses/InternalServerError"
  /api/v1/auth/keiki/change-password:
    post:
      tags:
        - Deprecated
      description: User change password (deprecated)
      requestBody:
        content:
          application/json:
            schema:
              type: object
              required:
                - token
                - new_password
                - current_password
                - device_data
              properties:
                token:
                  type: string
                  example: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOiIxNjE2MzUzNjI2OTYxLTU0OTczMTQiLCJlbWFpbCI6InRlc3RAc2lnbnVwLmNvbSIsImJ1bmRsZV9pZCI6Imdlbi50ZWNoLmtlaWtpLndvcmxkIiwiaWF0IjoxNjQ3ODYyODI5fQ.6L_x_htsgvXYwfNp-wZbDFNYakxf2LFR4UYF6mZfLSw"
                new_password:
                  type: string
                  example: "testPassword!@123"
                current_password:
                  type: string
                  example: "testPassword!@"
                device_data:
                  $ref: "schemas.yml#/schemas/DeviceData"
      responses:
        200:
          $ref: "#/components/responses/UserDataResponse"
        404:
          $ref: "#/components/responses/NotFound"
        422:
          $ref: "#/components/responses/UnprocessableEntity"
        500:
          $ref: "#/components/responses/InternalServerError"
  /api/v2/auth/keiki/change-password:
    post:
      tags:
        - Keiki
      description: User change password
      requestBody:
        content:
          application/json:
            schema:
              type: object
              required:
                - token
                - new_password
                - current_password
                - device_data
              properties:
                token:
                  type: string
                  example: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOiIxNjE2MzUzNjI2OTYxLTU0OTczMTQiLCJlbWFpbCI6InRlc3RAc2lnbnVwLmNvbSIsImJ1bmRsZV9pZCI6Imdlbi50ZWNoLmtlaWtpLndvcmxkIiwiaWF0IjoxNjQ3ODYyODI5fQ.6L_x_htsgvXYwfNp-wZbDFNYakxf2LFR4UYF6mZfLSw"
                new_password:
                  type: string
                  example: "testPassword!@123"
                current_password:
                  type: string
                  example: "testPassword!@"
                device_data:
                  $ref: "schemas.yml#/schemas/DeviceData"
      responses:
        200:
          $ref: "responses.yml#/responses/UserDataResponseV2"
        404:
          $ref: "#/components/responses/NotFound"
        422:
          $ref: "#/components/responses/UnprocessableEntity"
        500:
          $ref: "#/components/responses/InternalServerError"
  /api/v1/auth/keiki/send-reset-password-email:
    post:
      tags:
        - Keiki
      description: User send reset password email
      requestBody:
        content:
          application/json:
            schema:
              type: object
              required:
                - email
                - device_data
              properties:
                email:
                  type: string
                  example: "test@email.com"
                device_data:
                  $ref: "schemas.yml#/schemas/DeviceData"
      responses:
        200:
          description: "Email was sent successfully"
        404:
          $ref: "#/components/responses/NotFound"
        500:
          $ref: "#/components/responses/InternalServerError"
  /api/v1/auth/keiki/reset-password:
    post:
      tags:
        - Keiki
      description: User reset password
      requestBody:
        content:
          application/json:
            schema:
              type: object
              required:
                - reset_password_token
                - new_password
                - device_data
              properties:
                new_password:
                  type: string
                  example: "newStrongPassword!#23"
                reset_password_token:
                  type: string
                  example: "98c0b445ac133a3d0b7dd1208ed8a369"
                device_data:
                  $ref: "schemas.yml#/schemas/DeviceData"
      responses:
        200:
          description: "Password reset was successful"
        404:
          $ref: "#/components/responses/NotFound"
        422:
          $ref: "#/components/responses/UnprocessableEntity"
        410:
          $ref: "#/components/responses/Gone"
        500:
          $ref: "#/components/responses/InternalServerError"
  /api/v1/auth/keiki/validate-reset-password-token:
    post:
      tags:
        - Keiki
      description: User validate reset password
      requestBody:
        content:
          application/json:
            schema:
              type: object
              required:
                - reset_password_token
                - device_data
              properties:
                reset_password_token:
                  type: string
                  example: "98c0b445ac133a3d0b7dd1208ed8a369"
                device_data:
                  $ref: "schemas.yml#/schemas/DeviceData"
      parameters:
        - in: query
          name: reset_password_token
          schema:
            type: string
        - in: query
          name: bundle_id
          schema:
            type: string
      responses:
        200:
          description: "Password reset was successful"
        404:
          $ref: "#/components/responses/NotFound"
        422:
          $ref: "#/components/responses/UnprocessableEntity"
        410:
          $ref: "#/components/responses/Gone"
        500:
          $ref: "#/components/responses/InternalServerError"
components:
  responses:
    UserDataResponse:
      description: Response that contains user data (deprecated)
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/UserData"

    NotFound:
      description: User was not found in db
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/UserNotFoundError"
    UnprocessableEntity:
      description: Request data did not pass validation
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/ValidationFailedError"
    Unauthorized:
      description: Authorization failed
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/UnauthorizedError"
    Conflict:
      description: User exists
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/UserExists"
    Gone:
      description: Reset password token expired
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/ResetPasswordTokenExpiredError"
    UserHasActiveSubscriptionResponse:
      description: User has active subscription
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/UserHasActiveSubscription"
    InternalServerError:
      description: Internal server error
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/Error"
  schemas:
    UserData:
      type: object
      properties:
        user_data:
          type: object
          required:
            - token
            - email
            - is_subscribed
          properties:
            token:
              type: string
              description: User token
            email:
              type: string
              description: User email
            is_subscribed:
              type: boolean
              description: Web user subscription status
            sub_cancel_link:
              type: string
              description: Web user cancellation link
            accessed_content:
              type: array
              description: User accessed content
              items:
                type: object
                properties:
                  id:
                    type: string
            user_type:
              type: string
              description: User type
              enum:
                - App
                - Web
      example:
        user_data:
          token: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOiIxNjE2MzUzNjI2OTYxLTU0OTczMTQiLCJlbWFpbCI6InRlc3RAc2lnbnVwLmNvbSIsImJ1bmRsZV9pZCI6Imdlbi50ZWNoLmtlaWtpLndvcmxkIiwiaWF0IjoxNjQ3ODYyODI5fQ.6L_x_htsgvXYwfNp-wZbDFNYakxf2LFR4UYF6mZfLSw"
          email: "test@email.com"
          is_subsribed: true
          sub_cancel_link: "url of cancellation page"
          accessed_content:
            - id: "games"
            - id: "printables_packs_full"
          user_type: App



    UserNotFoundError:
      type: object
      properties:
        error:
          type: string
          default: "USER_NOT_FOUND"
      required:
        - error
    ValidationFailedError:
      type: object
      properties:
        error:
          type: string
          default: "VALIDATION_FAILED"
      required:
        - error
    UnauthorizedError:
      type: object
      properties:
        error:
          type: string
          default: "UNAUTHRORIZED"
    UserExists:
      type: object
      properties:
        error:
          type: string
          default: "USER_EXISTS"
    ResetPasswordTokenExpiredError:
      type: object
      properties:
        error:
          type: string
          default: "RESET_PASSWORD_TOKEN_EXPIRED"
    UserHasActiveSubscription:
      type: object
      properties:
        error:
          type: string
          default: "USER_HAS_ACTIVE_SUBSCRIPTION"
    Error:
      type: object
      properties:
        error:
          type: string

  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      name: x-api-key
      in: header
tags:
  - name: Keiki
    description: Requests to keiki login module
  - name: Deprecated
    description: Deprecated requests
