openapi: 3.0.0
info:
  title: Authentication
  description: APIs to authenticate admin
  version: 1.0.0
components:
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT

# sigup api
paths:
  /api/user/signup:
    post:
      summary: Register new user
      description: >-
        Register new user with provided information.
      tags: ["User Authentication"]
      requestBody:
        description: JSON object containing name, email and password
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                name:
                  type: string
                  example: john.doe
                email:
                  type: string
                  example: john.doe@gmail.com
                password:
                  type: string
                  example: password123
              required:
                - name
                - email
                - password
      responses:
        "200":
          description: Successful response containing access_token and refresh_token
          content:
            application/json:
              schema:
                type: object
                properties:
                  access_token:
                    type: string
                    example: >-
                      eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoxLCJpYXQiOjE2MjU2MzQ2MjIsImV4cCI6MTYyNTYzODIyMn0.cw_wzroU98q3N8zKhhD9rGQypFBDZfA8xb6CFkbUx7w
                  refresh_token:
                    type: string
                    example: >-
                      eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoxLCJpYXQiOjE2MjU2MzQ2MjIsImV4cCI6MTYyNzIzODIyMn0.rMf_tzwwdtlmRmpKZT3TqjrUMAcrX9SBJAaSKyRxtKs
                required:
                  - access_token
                  - refresh_token
        "400":
          description: Bad request error message
        "401":
          description: Unauthorized error message
        "500":
          description: Internal Server Error

  /api/user/signin:
    post:
      summary: Authenticate admin and return access_token and refresh_token
      description: >-
        Authenticate user with given credentials and return access_token and
        refresh_token in response.
      tags: ["User Authentication"]
      requestBody:
        description: JSON object containing email and password
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                username:
                  type: string
                  example: john.doe
                password:
                  type: string
                  example: password123
              required:
                - username
                - password
      responses:
        "200":
          description: Successful response containing access_token and refresh_token
          content:
            application/json:
              schema:
                type: object
                properties:
                  access_token:
                    type: string
                    example: >-
                      eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoxLCJpYXQiOjE2MjU2MzQ2MjIsImV4cCI6MTYyNTYzODIyMn0.cw_wzroU98q3N8zKhhD9rGQypFBDZfA8xb6CFkbUx7w
                  refresh_token:
                    type: string
                    example: >-
                      eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoxLCJpYXQiOjE2MjU2MzQ2MjIsImV4cCI6MTYyNzIzODIyMn0.rMf_tzwwdtlmRmpKZT3TqjrUMAcrX9SBJAaSKyRxtKs
                required:
                  - access_token
                  - refresh_token
        "400":
          description: Bad request error message
        "401":
          description: Unauthorized error message
        "500":
          description: Internal Server Error

  # refresh api
  /api/user/refresh:
    post:
      summary: Verify the refresh_token and returns new access_token and refresh_token
      description: >-
        This api verifies the refresh_token and returns new access_token and new refresh_token
      tags: ["User Authentication"]
      requestBody:
        description: JSON object containing valid refresh_token
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                refresh_token:
                  type: string
                  example: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoyLCJ1c2VybmFtZSI6InJhcGF0aWNvbGxlY3Rpb24iLCJ1c2VyX3R5cGUiOiJmYXJtZXIiLCJsZWRnZXJfaWQiOjg0LCJpYXQiOjE2NzY4Nzk5NzcsImV4cCI6MTY3Njg4MDI3N30.KXJ3_-VImWCPHIQyICklVmzZCYTg3PQYAg8OqH9flqE
              required:
                - refresh_token
      responses:
        "200":
          description: Successful response
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: boolean
                    example: >-
                      true
                  message:
                    type: string
                    example: >-
                      Data saved successfully!!!
                required:
                  - status
                  - message
        "400":
          description: Bad request error message
        "401":
          description: Unauthorized error message
        "500":
          description: Internal Server Error

  # logout api
  /api/user/logout:
    post:
      summary: Logs out the admin
      description: >-
        This api verifies the refresh_token and revokes the refresh_token from the database
      tags: ["User Authentication"]
      security:
        - BearerAuth: []
      requestBody:
        description: JSON object containing valid refresh_token
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                refresh_token:
                  type: string
                  example: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoyLCJ1c2VybmFtZSI6InJhcGF0aWNvbGxlY3Rpb24iLCJ1c2VyX3R5cGUiOiJmYXJtZXIiLCJsZWRnZXJfaWQiOjg0LCJpYXQiOjE2NzY4Nzk5NzcsImV4cCI6MTY3Njg4MDI3N30.KXJ3_-VImWCPHIQyICklVmzZCYTg3PQYAg8OqH9flqE
              required:
                - refresh_token
      responses:
        "200":
          description: Successful response
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: boolean
                    example: >-
                      true
                  message:
                    type: string
                    example: >-
                      Logged out successfully!!!
                required:
                  - status
                  - message
        "400":
          description: Bad request error message
        "401":
          description: Unauthorized error message
        "500":
          description: Internal Server Error

  /api/user/forgot-password:
    post:
      summary: Sends an OTP to the user email address
      description: >-
        This api verifies the email and sends 6 digit OTP to the user's email address
      tags: ["User Authentication"]
      security:
        - BearerAuth: []
      requestBody:
        description: JSON object containing valid email
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                email:
                  type: string
                  example: john.doe@gmail.com
              required:
                - email
      responses:
        "200":
          description: Successful response
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: boolean
                    example: >-
                      true
                  message:
                    type: string
                    example: >-
                      OTP has been sent to your email address.
                required:
                  - status
                  - message
        "400":
          description: Bad request error message
        "401":
          description: Unauthorized error message
        "500":
          description: Internal Server Error

  /api/user/update-password:
    post:
      summary: verifies the OTP and updates the password
      description: >-
        This api verifies the email and OTP and updates the password of the user
      tags: ["User Authentication"]
      security:
        - BearerAuth: []
      requestBody:
        description: JSON object containing valid email,otp and password
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                email:
                  type: string
                  example: john.doe@gmail.com
                otp:
                  type: number
                  example: 123456
                password:
                  type: string
                  example: Abcde@12345
              required:
                - email
                - otp
                - password
      responses:
        "200":
          description: Successful response
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: boolean
                    example: >-
                      true
                  message:
                    type: string
                    example: >-
                      Password updated successfully!!!
                required:
                  - status
                  - message
        "400":
          description: Bad request error message
        "401":
          description: Unauthorized error message
        "500":
          description: Internal Server Error
  /api/user/google-login:
    post:
      summary: This endpoint is used to log the user in using their Google account
      description: >-
        User clicks on sign in with google and they will be logged in using this endpoint
      tags: ["User Authentication"]
      security:
        - BearerAuth: []
      requestBody:
        description: JSON object containing valid id_token and access_token
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                id_token:
                  type: string
                  example: ejflakwjjfkalfjlwakefjawfj;wfkjoalkfawjf;akwfjak
                access_token:
                  type: string
                  example: ejflakwjjfkalfjlwakefjawfj;wfkjoalkfawjf;akwfjak
              required:
                - id_token
                - access_token
      responses:
        "200":
          description: Successful response
          content:
            application/json:
              schema:
                type: object
                properties:
                  access_token:
                    type: string
                    example: >-
                      ejlfkajlkjalfjalkfjw
                  refresh_token:
                    type: string
                    example: >-
                      ekflawjlakfjwlakfjwf
                required:
                  - access_token
                  - refresh_token
        "400":
          description: Bad request error message
        "401":
          description: Unauthorized error message
        "500":
          description: Internal Server Error
