openapi: 3.0.0
info:
  version: 1.0.0
  title: Authentication API
  description: >
    Obtain an OAuth2 access token from Amazon Cognito using the
    **client_credentials** grant.


    The returned `access_token` must be sent as a `Bearer` token in the

    `Authorization` header when calling the Check In Service API endpoints

    defined in [openapi.yaml](openapi.yaml).
servers:
  - url: https://cps-poc-api-access.auth.eu-south-2.amazoncognito.com
    description: Authentication Server
paths:
  /oauth2/token:
    post:
      operationId: getAccessToken
      summary: Obtain Access Token
      description: >
        Exchange client credentials for a bearer token.


        **Equivalent curl request:**

        ```

        curl --location
        'https://cps-poc-api-access.auth.eu-south-2.amazoncognito.com/oauth2/token'
        \
          --header 'Content-Type: application/x-www-form-urlencoded' \
          --data-urlencode 'grant_type=client_credentials' \
          --data-urlencode 'client_id=<your_client_id>' \
          --data-urlencode 'client_secret=<your_client_secret>'
        ```
      tags:
        - Authentication
      requestBody:
        required: true
        content:
          application/x-www-form-urlencoded:
            schema:
              $ref: '#/components/schemas/TokenRequest'
            example:
              grant_type: client_credentials
              client_id: someId
              client_secret: someSecret
      responses:
        '200':
          description: Token issued successfully
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TokenResponse'
              example:
                access_token: eyJraWQiOiJhYmNkZWYxMjM0NTY3ODkw...
                expires_in: 3600
                token_type: Bearer
        '400':
          description: Bad Request – invalid or missing parameters
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TokenError'
              example:
                error: invalid_request
                error_description: grant_type is required
        '401':
          description: Unauthorized – invalid client credentials
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TokenError'
              example:
                error: invalid_client
                error_description: Client authentication failed
components:
  schemas:
    TokenRequest:
      type: object
      required:
        - grant_type
        - client_id
        - client_secret
      properties:
        grant_type:
          type: string
          description: Must be `client_credentials`
          enum:
            - client_credentials
          example: client_credentials
        client_id:
          type: string
          description: The OAuth2 client ID issued by Amazon Cognito
          example: '4356456'
        client_secret:
          type: string
          description: The OAuth2 client secret issued by Amazon Cognito
          example: 123ga
    TokenResponse:
      type: object
      properties:
        access_token:
          type: string
          description: >-
            Bearer token to include in the `Authorization` header of API
            requests
        expires_in:
          type: integer
          description: Token lifetime in seconds
          example: 3600
        token_type:
          type: string
          description: Always `Bearer`
          example: Bearer
    TokenError:
      type: object
      properties:
        error:
          type: string
          description: OAuth2 error code
        error_description:
          type: string
          description: Human-readable error detail
