openapi: 3.0.3
info:
  title: cx-iam-service
  version: v1
  description: |-
    This API provides access to user details like:
    - Basic details: name, email, phone
    - Roles: access to which applications (Authorization)
    Also provides ways to modify user details and validate authentication details
  contact:
    name: Platform Team
    email: 2c369a0e.carlsberggroup.onmicrosoft.com@emea.teams.ms
servers:
  - url: http://localhost:3000
    description: IAM Service API server url
tags:
  - name: appUsersSearch
    description: User search API endpoints
  - name: configuration
    description: Configuration API endpoints
  - name: salesOrgUsersSearch
    description: Search users by salesOrg API endpoints
  - name: userAuthentication
    description: User authentication API endpoints
  - name: userContacts
    description: User contacts API endpoints
  - name: userCreation
    description: User creation API endpoints
  - name: userCustomers
    description: User customers API endpoints
  - name: userDetails
    description: User details API endpoints
  - name: userPassword
    description: User password API endpoints
  - name: userRoles
    description: User roles API endpoints
  - name: userSearch
    description: User search API endpoints
  - name: userStatus
    description: User status API endpoints
paths:
  /apps/{appCode}/users:
    get:
      operationId: searchSalesOrgUsers
      parameters:
        - $ref: '#/components/parameters/roleName'
        - $ref: '#/components/parameters/type'
        - $ref: '#/components/parameters/searchExpressions'
        - $ref: '#/components/parameters/page'
        - $ref: '#/components/parameters/size'
      description: |-
        Returns a pages of Users that are linked to the given App according to the request parameters.

        Can occur the errors:
              
              Invalid applicationCode
              Invalid roleName for the selected applicationCode
      summary: Search SalesOrg Users
      tags:
        - appUsersSearch
      responses:
        '200':
          $ref: '#/components/responses/UserPage'
        '400':
          $ref: '#/components/responses/BadRequest'
    parameters:
      - $ref: '#/components/parameters/appCode'
  /config/azuread:
    get:
      summary: Get Azure AD configuration
      description: Get the azure AD configuration
      tags:
        - configuration
      operationId: fetchAzureAdConfiguration
      responses:
        '200':
          $ref: '#/components/responses/AzureAdConfig'
  /salesorgs/{salesOrgCode}/users:
    get:
      tags:
        - salesOrgUsersSearch
      operationId: fetchUsersbySalesOrg
      parameters:
        - $ref: '#/components/parameters/applicationCode'
        - $ref: '#/components/parameters/roleName'
        - $ref: '#/components/parameters/type'
        - $ref: '#/components/parameters/searchExpressions'
        - $ref: '#/components/parameters/page'
        - $ref: '#/components/parameters/size'
        - $ref: '#/components/parameters/customerCodes'
      responses:
        '200':
          description: This endpoint returns one of two objects
          content:
            application/json:
              schema:
                oneOf:
                  - $ref: '#/components/schemas/UserPage'
                  - $ref: '#/components/schemas/UserList'
        '400':
          $ref: '#/components/responses/BadRequest'
      description: |-
        Returns a list of Users that have a customer position or a role in the given SalesOrg according 
        to the request parameters. (do not use page params)
                  
          OR

        Without customer code param and using pageable params ->  
        Returns a page list of Users that are linked to the given SalesOrg according to the request parameters.

        Can occur the errors:
                        
            Invalid salesOrgCode
            Invalid applicationCode
            Invalid roleName for the selected applicationCode
      summary: Get users by salesOrg
    parameters:
      - $ref: '#/components/parameters/salesOrgCode'
  /auth/eid:
    post:
      operationId: validateExternalUserEidAndPassword
      responses:
        '200':
          $ref: '#/components/responses/SuccessfulAuthentication'
        '400':
          $ref: '#/components/responses/BadRequest'
        '404':
          description: |-
            Can occour:

                User does not exist or user authentication failed
      summary: Validate eid and password
      description: |-
        Validate external user's eid and password.

        Can occur the error:

             User authentication failed
      tags:
        - userAuthentication
      requestBody:
        $ref: '#/components/requestBodies/EidAndPassword'
  /auth/email:
    post:
      operationId: validateExternalUserEmailAndPassword
      responses:
        '200':
          $ref: '#/components/responses/SuccessfulAuthentication'
        '400':
          $ref: '#/components/responses/BadRequest'
        '404':
          description: |-
            Can occour:

                User does not exist or user authentication failed
      summary: Validate email and password
      description: |-
        Validate external user's email and password.

        Can occur the error:

             User authentication failed
      tags:
        - userAuthentication
      requestBody:
        $ref: '#/components/requestBodies/EmailAndPassword'
  /auth/phone:
    post:
      operationId: validateExternalUserPhoneAndPassword
      responses:
        '200':
          $ref: '#/components/responses/SuccessfulAuthentication'
        '400':
          $ref: '#/components/responses/BadRequest'
        '404':
          description: |-
            Can occour:

                User does not exist or user authentication failed
      summary: Validate phone and password
      description: |-
        Validate external user's phone and password.

        Can occur the error:

             User authentication failed
      tags:
        - userAuthentication
      requestBody:
        $ref: '#/components/requestBodies/PhoneAndPassword'
  /auth/otp/generate:
    post:
      operationId: generateExternalUserOtp
      responses:
        '200':
          $ref: '#/components/responses/UserOtp'
        '400':
          $ref: '#/components/responses/BadRequest'
        '404':
          description: |-
            Can occour:

                User not found
      summary: Generate OTP
      description: Generate OTP for external user's by eid
      tags:
        - userAuthentication
      requestBody:
        $ref: '#/components/requestBodies/OtpDetails'
  /auth/otp/validate:
    post:
      operationId: validateExternalUserOtp
      responses:
        '200':
          $ref: '#/components/responses/SuccessfulAuthentication'
        '400':
          $ref: '#/components/responses/BadRequest'
        '404':
          description: |-
            Can occour:

                User does not exist or user authentication failed
      summary: Validate OTP
      tags:
        - userAuthentication
      description: |-
        Validate external user's OTP.

        Can occur the error:

             User authentication failed
      requestBody:
        $ref: '#/components/requestBodies/OtpAuth'
  /auth/log/{userEid}/session:
    post:
      operationId: logInternalUserSession
      responses:
        '200':
          $ref: '#/components/responses/SuccessfulAuthentication'
        '400':
          $ref: '#/components/responses/BadRequest'
        '404':
          description: |-
            Can occour:

                User does not exist or is not internal user
      summary: Log internal user's session
      description: Log internal user's session.
      tags:
        - userAuthentication
    parameters:
      - $ref: '#/components/parameters/userEid'
  /users/{userEid}/email:
    put:
      operationId: updateUserEmail
      responses:
        '200':
          $ref: '#/components/responses/User'
        '404':
          description: |-
            Can occour:

                User Not Found
      tags:
        - userContacts
      summary: Update user default email
      description: Updates the user email
      requestBody:
        $ref: '#/components/requestBodies/UserEmail'
    post:
      operationId: addUserEmail
      responses:
        '200':
          $ref: '#/components/responses/User'
        '400':
          $ref: '#/components/responses/BadRequest'
        '404':
          description: |-
            Can occour:

                User not found
      summary: Add user email
      description: Adds an email to an user
      requestBody:
        $ref: '#/components/requestBodies/UserEmail'
      tags:
        - userContacts
    delete:
      operationId: disableUserEmail
      parameters:
        - $ref: '#/components/parameters/email'
      responses:
        '200':
          $ref: '#/components/responses/User'
        '404':
          description: |-
            Can occour:

                User Not Found
      summary: Disable user email
      description: Disables an user email
      tags:
        - userContacts
    parameters:
      - $ref: '#/components/parameters/userEid'
  /users/{userEid}/phone:
    put:
      operationId: updateUserPhone
      responses:
        '200':
          $ref: '#/components/responses/User'
        '404':
          description: |-
            Can occour:

                User Not Found
      summary: Update user phone
      description: Updates the user phone number
      requestBody:
        $ref: '#/components/requestBodies/UserPhone'
      tags:
        - userContacts
    post:
      operationId: addUserPhone
      responses:
        '200':
          $ref: '#/components/responses/User'
        '400':
          $ref: '#/components/responses/BadRequest'
        '404':
          description: |-
            Can occour:

                User Not Found
      tags:
        - userContacts
      summary: Add user phone
      description: Add a phone number to a user
      requestBody:
        $ref: '#/components/requestBodies/UserPhone'
    delete:
      operationId: disableUserPhone
      parameters:
        - $ref: '#/components/parameters/phone'
      responses:
        '200':
          $ref: '#/components/responses/User'
        '404':
          description: |-
            Can occour:

                User Not Found
      summary: Disable user phone
      description: Disables an user phone
      tags:
        - userContacts
    parameters:
      - $ref: '#/components/parameters/userEid'
  /users:
    get:
      operationId: searchUsers
      parameters:
        - $ref: '#/components/parameters/queryEid'
        - $ref: '#/components/parameters/type'
        - name: email
          in: query
          required: false
          schema:
            type: string
          example: me@carlsberg.com
          description: The user's email address
        - name: phone
          in: query
          required: false
          schema:
            type: string
          description: The user's phone number
          example: '+8562055009424'
        - $ref: '#/components/parameters/searchExpressions'
      responses:
        '200':
          $ref: '#/components/responses/UserList'
        '400':
          $ref: '#/components/responses/BadRequest'
        '404':
          description: |-
            Can occour:

                User Not Found
      summary: Returns a list of Users
      description: |-
        Returns a list of Users given a list of eid's. (if only eid list is used)

          OR

        Returns a list of Users given the request parameters.

        Can occur the errors:

            Users eids are limited up to 20 eids
            One and only one of the parameters must be present: 'email', 'phone', 'searchExpression'
            SearchExpressions are limited up to 5
            Invalid combination of parameters: 'type', 'email'
      tags:
        - userSearch
    post:
      operationId: createExternalUser
      responses:
        '200':
          $ref: '#/components/responses/User'
        '400':
          $ref: '#/components/responses/BadRequest'
        '404':
          description: |-
            Can occour:

                User not found
      description: |-
        Creates an external user (non CB).

        Can occur the errors:

            There is already a user with that email address.
            The email address belongs to potential internal user.
            There is already a user with that phone number.
      summary: Creates an external user
      tags:
        - userCreation
      requestBody:
        $ref: '#/components/requestBodies/NewUser'
  /users/customers/{userEid}:
    post:
      operationId: changeCustomerPosition
      responses:
        '200':
          $ref: '#/components/responses/User'
        '400':
          $ref: '#/components/responses/BadRequest'
        '404':
          description: |-
            Can occour:

                User Not Found
      tags:
        - userCustomers
      description: |-
        Allows to link or unlink a user to a customer

        Can occur the error:
            
            Invalid salesOrgCode
      summary: (un)link a user to a customer
      requestBody:
        $ref: '#/components/requestBodies/CustomerPosition'
    parameters:
      - $ref: '#/components/parameters/userEid'
  /users/{userEid}/name:
    post:
      operationId: updateUserName
      responses:
        '200':
          $ref: '#/components/responses/User'
      summary: Update user name
      description: Updates a external user (nonCB) first and last name.
      tags:
        - userDetails
      requestBody:
        $ref: '#/components/requestBodies/UserFullName'
    parameters:
      - $ref: '#/components/parameters/userEid'
  /users/{userEid}/azuredata:
    get:
      operationId: fetchInternalUserAzureData
      responses:
        '200':
          $ref: '#/components/responses/UserAzureFederation'
        '404':
          description: |-
            Can occour:

                User Not Found
      summary: Fetch user azureId data
      description: Fetch internal user Azure ID data
      tags:
        - userDetails
    parameters:
      - $ref: '#/components/parameters/userEid'
  /users/{userEid}/password:
    post:
      operationId: setUserPassword
      responses:
        '204':
          description: User password updated
      summary: Set password
      description: Set external user password
      tags:
        - userPassword
      requestBody:
        $ref: '#/components/requestBodies/NewPassword'
    parameters:
      - $ref: '#/components/parameters/userEid'
  /users/{userEid}/roles/assignable:
    get:
      operationId: fetchUserAssignableRoles
      parameters:
        - $ref: '#/components/parameters/grantor'
      responses:
        '200':
          $ref: '#/components/responses/Roles'
        '400':
          $ref: '#/components/responses/BadRequest'
      description: |-
        Given a user and a grantor, provides a list of roles that a grantor can grant to that user

        Can occour the error:
          
            Grantor cannot be equals to the Grantee
      summary: Fetch user assignable roles
      tags:
        - userRoles
    parameters:
      - $ref: '#/components/parameters/userEid'
  /users/{userEid}/roles/grantUserRole:
    post:
      operationId: enableUserRole
      parameters:
        - $ref: '#/components/parameters/grantor'
      responses:
        '200':
          $ref: '#/components/responses/User'
        '400':
          description: |-
            Can occour:

                Grantor cannot be equals to the Grantee
        '404':
          description: |-
            Can occour:

                User Not Found
      description: |-
        Given a user and a grantor, grants a specific role to the user

        Can occour the error:
          
            Grantor cannot be equals to the Grantee
            Invalid grantorEid
            Invalid applicationCode
            Invalid roleName for the selected applicationCode
      summary: Grant role to a user
      tags:
        - userRoles
      requestBody:
        $ref: '#/components/requestBodies/UserRole'
    parameters:
      - $ref: '#/components/parameters/userEid'
  /users/{userEid}/roles/revokeUserRole:
    post:
      operationId: disableRoleForUser
      parameters:
        - $ref: '#/components/parameters/grantor'
      responses:
        '200':
          $ref: '#/components/responses/User'
        '400':
          description: |-
            Can occour:

                Grantor cannot be equals to the Grantee
        '404':
          description: |-
            Can occour:

                User Not Found
      summary: Revoke a role to a user
      description: |-
        Given a user (grantee) and a grantor, revoke a specific role to the grantee

        Can occour the error:
          
            Grantor cannot be equals to the Grantee
            Invalid grantorEid
            Invalid applicationCode
            Invalid roleName for the selected applicationCode
      requestBody:
        $ref: '#/components/requestBodies/UserRole'
      tags:
        - userRoles
    parameters:
      - $ref: '#/components/parameters/userEid'
  /users/{userEid}/roles/grantSalesOrgRole:
    post:
      operationId: enableRoleForUserSalesOrg
      parameters:
        - $ref: '#/components/parameters/grantor'
      responses:
        '200':
          $ref: '#/components/responses/User'
        '400':
          description: |-
            Can occour:

                Grantor cannot be equals to the Grantee
        '404':
          description: |-
            Can occour:

                User Not Found
      description: |-
        Given a user (grantee) and a grantor, grant a specific role to the grantee for a specific Sales Org

        Can occour the error:
          
            Grantor cannot be equals to the Grantee
            Invalid grantorEid
            Invalid applicationCode
            Invalid roleName for the selected applicationCode
      summary: Grant a role for a Sales Org
      requestBody:
        $ref: '#/components/requestBodies/UserSalesOrgRole'
      tags:
        - userRoles
    parameters:
      - $ref: '#/components/parameters/userEid'
  /users/{userEid}/roles/revokeSalesOrgRole:
    post:
      operationId: disableRoleForUserSalesOrg
      parameters:
        - $ref: '#/components/parameters/grantor'
      responses:
        '200':
          $ref: '#/components/responses/User'
        '400':
          description: |-
            Can occour:

                Grantor cannot be equals to the Grantee
        '404':
          description: |-
            Can occour:

                User Not Found
      summary: Revoke a role for a Sales Org
      description: |-
        Given a user (grantee) and a grantor, revoke a specific role to the grantee for a specific Sales Org

        Can occour the error:
          
            Grantor cannot be equals to the Grantee
            Invalid grantorEid
            Invalid applicationCode
            Invalid roleName for the selected applicationCode
      requestBody:
        $ref: '#/components/requestBodies/UserSalesOrgRole'
      tags:
        - userRoles
    parameters:
      - $ref: '#/components/parameters/userEid'
  /users/{userEid}/roles/grantCustomerRole:
    post:
      operationId: enableRoleForUserSalesOrgCustomer
      parameters:
        - $ref: '#/components/parameters/grantor'
      responses:
        '200':
          $ref: '#/components/responses/User'
        '400':
          description: |-
            Can occour:

                Grantor cannot be equals to the Grantee
        '404':
          description: |-
            Can occour:

                User Not Found
      summary: Grant Role for user customer
      description: |-
        Given a user (grantee) and a grantor, grant a specific role to the grantee for a specific Sales Org and customer

        Can occour the error:
          
            Grantor cannot be equals to the Grantee
            Invalid grantorEid
            Invalid applicationCode
            Invalid roleName for the selected applicationCode
      requestBody:
        $ref: '#/components/requestBodies/UserSalesOrgCustomerRole'
      tags:
        - userRoles
    parameters:
      - $ref: '#/components/parameters/userEid'
  /users/{userEid}/roles/revokeCustomerRole:
    post:
      operationId: disableRoleForUserSalesOrgCustomer
      parameters:
        - $ref: '#/components/parameters/grantor'
      responses:
        '200':
          $ref: '#/components/responses/User'
        '400':
          description: |-
            Can occour:

                Grantor cannot be equals to the Grantee
        '404':
          description: |-
            Can occour:

                User Not Found
      summary: Revoke Role for user customer
      description: |
        Given a user (grantee) and a grantor, revoke a specific role to the grantee for a specific Sales Org and customer

        Can occour the error:
          
            Grantor cannot be equals to the Grantee
            Invalid grantorEid
            Invalid applicationCode
            Invalid roleName for the selected applicationCode
      requestBody:
        $ref: '#/components/requestBodies/UserSalesOrgCustomerRole'
      tags:
        - userRoles
    parameters:
      - $ref: '#/components/parameters/userEid'
  /users/{userEid}/roles:
    post:
      deprecated: true
      operationId: changeUserRole
      parameters:
        - $ref: '#/components/parameters/grantor'
        - $ref: '#/components/parameters/operation'
        - $ref: '#/components/parameters/rolePlacement'
      requestBody:
        content:
          application/json:
            schema:
              oneOf:
                - $ref: '#/components/schemas/UserRole'
                - $ref: '#/components/schemas/UserSalesOrgRole'
                - $ref: '#/components/schemas/UserSalesOrgCustomerRole'
      responses:
        '200':
          $ref: '#/components/responses/User'
        '400':
          description: |-
            Can occour:

                Grantor cannot be equals to the Grantee
        '404':
          description: |-
            Can occour:

                User Not Found
                Invalid grantorEid
                Invalid applicationCode
                Invalid roleName for the selected applicationCode
      description: |-
        One endpoint to grant/revoke them all

        For userRoles
                
                - use UserRoles on body
                - use operaton = ENABLE/DISABLE to grant/revoke role
                - use rolePlacement = user
              
        For userSalesOrgRoles
            
                - use userSalesOrgRoles on body
                - use operaton = ENABLE/DISABLE to grant/revoke role
                - use rolePlacement = salesOrg
            
        For userSalesOrgCustomerRoles

                - use userSalesOrgCustomerRoles on body
                - use operaton = ENABLE/DISABLE to grant/revoke role
                - use rolePlacement = customer
                
        Can occour the error:
          
            Grantor cannot be equals to the Grantee
            Invalid grantorEid
            Invalid applicationCode
            Invalid roleName for the selected applicationC
      summary: Grant/Revoke roles
      tags:
        - userRoles
    parameters:
      - $ref: '#/components/parameters/userEid'
  /users/{userEid}:
    get:
      operationId: fetchUserByEid
      responses:
        '200':
          $ref: '#/components/responses/User'
        '404':
          description: |-
            Can occour:

                User Not Found
      summary: Get user by eid
      description: Given a valid user unique identifier (EID), this method returns the details of that user
      tags:
        - userSearch
    parameters:
      - $ref: '#/components/parameters/userEid'
  /users/federated/azure/{azureId}:
    get:
      operationId: fetchUserByAzureId
      responses:
        '200':
          $ref: '#/components/responses/User'
        '404':
          description: |-
            Can occour:

                User Not Found
      tags:
        - userSearch
      summary: Get User by Azure Id
      description: Get an Internal User by its Azure Id
    parameters:
      - $ref: '#/components/parameters/azureId'
  /users/azuredata/status:
    get:
      summary: Update users status
      responses:
        '200':
          description: OK - Bulk update completed for x users
      operationId: updateUsersStatus
      description: |-
        Updates all users status by matching with Azure Id status.
        Status can be:
            
            ENABLED
            DISABLED
      tags:
        - userStatus
    put:
      summary: Update user status
      operationId: updateUserStatus
      responses:
        '200':
          description: OK - User status updated
        '404':
          description: |-
            Can occour:

                User Not Found
      description: |-
        Update user status.
        Status can be:
            
            ENABLED
            DISABLED
      parameters:
        - schema:
            type: string
          in: query
          name: userEid
          description: 'The user Eid '
          required: true
          example: ffdc66e5-6b93-4814-8d56-b5dfd8f2aa2c
        - $ref: '#/components/parameters/newStatus'
      tags:
        - userStatus
components:
  schemas:
    NewUser:
      type: object
      x-stoplight:
        id: 17103b83f263a
      title: New User
      description: Represents a new user to be created.
      properties:
        firstName:
          maxLength: 50
          minLength: 1
          type: string
          description: User first name
          example: John
        lastName:
          maxLength: 50
          minLength: 1
          type: string
          description: User last name
          example: Doe
        email:
          type: string
          description: If needed, the first email to be added to the user
          example: me@carlsberg.com
        phone:
          type: string
          description: If needed, the first phone number to be added to the user
          example: '+8562055009424'
      required:
        - firstName
        - lastName
    UserFullName:
      title: User Full Name
      x-stoplight:
        id: 10k30j4uul9c6
      type: object
      description: |-
        Represents the user full name: first and last name.
        Used for updating the user details: full name
      properties:
        firstName:
          maxLength: 50
          minLength: 1
          type: string
          description: User first name
          example: John
        lastName:
          maxLength: 50
          minLength: 1
          type: string
          description: User last name
          example: Doe
      required:
        - firstName
        - lastName
    NewPassword:
      type: object
      x-stoplight:
        id: b1cfc827f7030
      title: Password Update
      description: Represents a password to be updated on the user
      properties:
        password:
          type: string
          description: The password
          example: password123!
      required:
        - password
    UserPhone:
      type: object
      x-stoplight:
        id: a7090901c7a80
      title: User Phone Update
      description: Represents a phone number to be updated on the user
      properties:
        phone:
          type: string
          description: User phone number
          pattern: ^\+?[1-9]\d{1,14}$
          minLength: 1
          format: regex
          example: '238327123'
        default:
          type: boolean
          example: true
          description: Specifies whether it is the default user's phone.
      required:
        - phone
    UserEmail:
      x-stoplight:
        id: e82338a0a4c7f
      type: object
      title: User Email Update
      description: Represents a email to be updated on the user
      x-examples:
        Example 1:
          email: me@carlsberg.com
          default: true
      properties:
        email:
          type: string
          example: me@carlsberg.com
          description: User email
        default:
          type: boolean
          example: true
          description: Specifies whether it is the default user's email.
      required:
        - email
    SuccessfulAuthentication:
      type: object
      x-stoplight:
        id: c20cfc76778ff
      description: User success for authentication
      properties:
        authenticationDate:
          type: string
          format: date-time
          description: Authentication date
          example: '2020-06-15 17:23:27'
        eid:
          type: string
          description: Identifier
          example: ffdc66e5-6b93-4814-8d56-b5dfd8f2aa2c
      title: SuccessfulAuthentication
    EidAndPassword:
      type: object
      x-stoplight:
        id: ff7ff86b2d272
      properties:
        eid:
          type: string
          description: EID to be validated
          example: ffdc66e5-6b93-4814-8d56-b5dfd8f2aa2c
        password:
          type: string
          description: Password to be validated
          example: password123!
      required:
        - eid
        - password
      description: EID and Password for request input and validation
      title: EidAndPassword
    PhoneAndPassword:
      type: object
      x-stoplight:
        id: f714fe010618a
      description: Phone and Password for request input and validation
      properties:
        phoneNumber:
          type: string
          description: Phone number to be validated
          example: '+8562093106336'
        password:
          type: string
          description: Password to be validated
          example: password123!
      required:
        - phoneNumber
        - password
      title: PhoneAndPassword
    EmailAndPassword:
      type: object
      x-stoplight:
        id: f07e541d5f2f8
      description: Email and Password for request input and validation
      properties:
        email:
          type: string
          description: Email to be validated
          example: me@carlsberg.com
        password:
          type: string
          description: Password to be validated
          example: password123!
      required:
        - email
        - password
      title: EmailAndPassword
    OtpAuth:
      x-stoplight:
        id: 12657425944c1
      type: object
      description: EID and OTP for request input and validation
      properties:
        eid:
          type: string
          description: EID to be validate
          example: ffdc66e5-6b93-4814-8d56-b5dfd8f2aa2c
        medium:
          type: string
          enum:
            - PHONE
            - EMAIL
          description: Medium to send the OTP
          example: PHONE
        otp:
          type: string
          description: One-time-Password to be validated
          example: b8aa6e401de7771edaeee8c481eea7d079c931e5ced3c7740a8b7ffb704b76287bed1279abf69e04
      required:
        - eid
        - medium
        - otp
      title: OtpAuth
    OtpDetails:
      x-stoplight:
        id: a2546c5a63d62
      type: object
      description: EID and Medium for OTP generation
      properties:
        eid:
          type: string
          description: EID to be validated
          example: ffdc66e5-6b93-4814-8d56-b5dfd8f2aa2c
        medium:
          type: string
          enum:
            - PHONE
            - EMAIL
          description: Medium to send the OTP
          example: PHONE
      required:
        - eid
        - medium
      title: OtpDetails
    UserOtp:
      type: object
      x-stoplight:
        id: 7df06b1d999c2
      description: User One-time-Password to be validated data model
      properties:
        otp:
          type: string
          description: User One-time-Password
          example: b8aa6e401de7771edaeee8c481eea7d079c931e5ced3c7740a8b7ffb704b76287bed1279abf69e04
        expiresAt:
          type: string
          format: date-time
          description: Password expiration Date
          example: '2021-04-29 07:33:49'
      title: UserOtp
    UserAzureFederation:
      type: object
      x-stoplight:
        id: c4a2b6951bac7
      description: A representation of a user from azure id
      properties:
        eid:
          type: string
          description: The identifier for the user
          example: ffdc66e5-6b93-4814-8d56-b5dfd8f2aa2c
        userPrincipalName:
          type: string
          description: Designation of the user
          example: John Doe
        azureUserId:
          type: string
          description: Azure identifier for the user
          example: ffdc66e5-6b93-4814-8d56-b5dfd8f2aa2c
      title: UserAzureFederation
    AzureAdConfig:
      type: object
      x-stoplight:
        id: b98727fba695a
      description: Configuration representation for Azure
      properties:
        tenantId:
          type: string
          description: Tenant id number
          example: 69d313de-076a-43b7-8474-16bde8472ac7
        clientId:
          type: string
          description: Client id number
          example: 69d313de-076a-43b7-8474-16bde8472ac7
        clientSecret:
          type: string
          description: Client secret
          example: 69d313de-076a-43b7-8474-16bde8472ac7
      title: AzureAdConfig
    Sort:
      description: Indicates the sorting status of a dataset or collection, providing flags for whether the data is sorted, unsorted, or considered empty
      type: object
      x-stoplight:
        id: pfl1ni0tqttk5
      x-examples:
        Example 1:
          sorted: true
          unsorted: true
          empty: true
      title: Sort
      properties:
        sorted:
          type: boolean
          example: true
          description: Boolean field indicating whether the object is sorted
        unsorted:
          type: boolean
          example: true
          description: Boolean field indicating whether the object is unsorted
        empty:
          type: boolean
          example: true
          description: Boolean field indicating the absence of any sorting type.
    Pageable:
      description: Pageable request model
      type: object
      x-stoplight:
        id: 9gh8yd6k2bzpu
      x-examples:
        Example 1:
          sort:
            sorted: true
            unsorted: true
            empty: true
          pageNumber: 1
          pageSize: 1
          paged: true
          unpaged: true
          offset: 1
      properties:
        sort:
          $ref: '#/components/schemas/Sort'
        pageNumber:
          type: integer
          format: int32
          example: 1
          description: Page number value
        pageSize:
          type: integer
          format: int32
          example: 1
          description: Page size value
        paged:
          type: boolean
          example: true
        unpaged:
          type: boolean
          example: true
        offset:
          type: integer
          format: int64
          example: 1
      title: Pageable
    UserList:
      type: object
      x-stoplight:
        id: 76d599d5c19c3
      description: The Users list model
      properties:
        users:
          type: array
          description: List of users
          items:
            $ref: '#/components/schemas/User'
          example:
            - eid: dfa44075-8999-4673-825a-9ce89845d377
              type: EXTERNAL
              createdAt: '2020-05-28 17:38:18'
              firstName: John
              lastName: Doe
              emails:
                - email: me@carlsberg.com
                  default: true
              phones:
                - phone: '238327123'
                  default: true
              roles:
                applicationCode: CADI
                roleName: ADMIN
              customerPositions:
                - salesOrgCode: S001
                  customerCode: '12345'
                  position: SOLDTO
                - salesOrgCode: S002
                  customerCode: '54321'
                  position: SOLDTO
            - eid: ffdc66e5-6b93-4814-8d56-b5dfd8f2aa2c
              type: EXTERNAL
              createdAt: '2020-05-28 17:38:18'
              firstName: John
              lastName: Doe
              emails:
                - email: me@carlsberg.com
                  default: true
              phones:
                - phone: '238327123'
                  default: true
              roles:
                applicationCode: CADI
                roleName: ADMIN
              customerPositions:
                - salesOrgCode: S001
                  customerCode: '12345'
                  position: SOLDTO
                - salesOrgCode: S002
                  customerCode: '54321'
                  position: SOLDTO
        limited:
          type: boolean
          example: true
      title: UserList
    UserPage:
      type: object
      x-stoplight:
        id: c80d2bed239c9
      description: List of users paginated
      properties:
        content:
          type: array
          description: List of users
          items:
            $ref: '#/components/schemas/User'
          example:
            - eid: dfa44075-8999-4673-825a-9ce89845d377
              type: EXTERNAL
              createdAt: '2020-05-28 17:38:18'
              firstName: John
              lastName: Doe
              emails:
                - email: me@carlsberg.com
                  default: true
              phones:
                - phone: '238327123'
                  default: true
              roles:
                applicationCode: CADI
                roleName: ADMIN
              customerPositions:
                - salesOrgCode: S001
                  customerCode: '12345'
                  position: SOLDTO
                - salesOrgCode: S002
                  customerCode: '54321'
                  position: SOLDTO
            - eid: ffdc66e5-6b93-4814-8d56-b5dfd8f2aa2c
              type: EXTERNAL
              createdAt: '2020-05-28 17:38:18'
              firstName: John
              lastName: Doe
              emails:
                - email: me@carlsberg.com
                  default: true
              phones:
                - phone: '238327123'
                  default: true
              roles:
                applicationCode: CADI
                roleName: ADMIN
              customerPositions:
                - salesOrgCode: S001
                  customerCode: '12345'
                  position: SOLDTO
                - salesOrgCode: S002
                  customerCode: '54321'
                  position: SOLDTO
        pageable:
          $ref: '#/components/schemas/Pageable'
        totalElements:
          type: integer
          format: int64
          example: 1
          description: Total number of elements
        totalPages:
          type: integer
          format: int32
          example: 1
          description: Total number of pages
        last:
          type: boolean
          example: true
        size:
          type: integer
          format: int32
          example: 1
          description: Page size value
        number:
          type: integer
          format: int32
          example: 1
          description: Page number
        sort:
          $ref: '#/components/schemas/Sort'
        numberOfElements:
          type: integer
          format: int32
          example: 1
          description: Number of elements
        first:
          type: boolean
          example: true
        empty:
          type: boolean
          example: true
      title: UserPage
    User:
      title: User
      x-stoplight:
        id: jwtozxubur096
      type: object
      description: Represents a User in the CX Universe. Could either be an internal user (Carlsberg employee) or an external user (e.g. someone at an outlet)
      x-examples: {}
      properties:
        eid:
          type: string
          description: Unique identifier for the user
          example: dfa44075-8999-4673-825a-9ce89845d377
        type:
          type: string
          enum:
            - EXTERNAL
            - INTERNAL
          example: INTERNAL
          description: 'Type of the user: INTERNAL or EXTERNAL'
        createdAt:
          type: string
          format: date-time
          description: Date of the creation of the user
          example: '2020-05-28 17:38:18'
        firstName:
          type: string
          description: User first name
          example: John
          minLength: 1
          maxLength: 50
        lastName:
          type: string
          description: User last name
          example: Doe
          minLength: 1
          maxLength: 50
        emails:
          description: List of user active email addresses
          example:
            - email: me@carlsberg.com
              default: true
          type: array
          items:
            $ref: '#/components/schemas/Email'
        phones:
          description: List of user active phone numbers
          example:
            - phone: '238327123'
              default: true
          type: array
          items:
            $ref: '#/components/schemas/Phone'
        roles:
          $ref: '#/components/schemas/Roles'
        customerPositions:
          type: array
          description: The customer positions of the user
          example:
            - salesOrgCode: S001
              customerCode: '12345'
              position: SOLDTO
            - salesOrgCode: S002
              customerCode: '54321'
              position: SOLDTO
          items:
            $ref: '#/components/schemas/CustomerPosition'
      required:
        - eid
        - type
        - createdAt
        - firstName
        - lastName
        - emails
        - phones
        - roles
        - customerPositions
    Phone:
      type: object
      x-stoplight:
        id: a7090901c7a82
      title: User Phone
      description: Represents a phone number
      properties:
        phoneNumber:
          type: string
          description: User phone number
          pattern: ^\+?[1-9]\d{1,14}$
          minLength: 1
          format: regex
          example: '12345678901234'
        default:
          type: boolean
          example: true
          description: Specifies whether it is the default user's phone.
    Email:
      x-stoplight:
        id: e82338a0a4c72
      type: object
      title: User Email
      description: Represents an user email
      x-examples:
        Example 1:
          address: me@carlsberg.com
          default: true
      properties:
        address:
          type: string
          example: me@carlsberg.com
          description: User email
        default:
          type: boolean
          example: true
          description: Specifies whether it is the default user's email.
      required:
        - email
    CustomerPosition:
      title: CustomerPosition
      x-stoplight:
        id: mnxtz1qco8flq
      type: object
      description: Model of a customer relation with a user
      properties:
        salesOrgCode:
          type: string
          x-stoplight:
            id: f44iqsgt2dc8g
          description: The sales organization code
          example: S001
        customerCode:
          type: string
          x-stoplight:
            id: cr12o0zht2puo
          description: Customer code (aka customer id)
          example: '4123412'
        position:
          type: string
          x-stoplight:
            id: n8hjrkgdrv1lu
          description: Customer position
          example: SOLDTO
    Role:
      title: Role
      type: object
      description: Represents a role in the scope of an application
      x-examples:
        Example 1:
          applicationCode: CADI
          roleName: ADMIN
      properties:
        applicationCode:
          type: string
          description: Code of the application for the specified role
          example: CADI
        roleName:
          type: string
          description: The role name
          example: ADMIN
      required:
        - applicationCode
        - roleName
    UserRole:
      title: UserRole
      x-stoplight:
        id: qnym5mkccd66n
      type: object
      properties:
        role:
          $ref: '#/components/schemas/Role'
      description: Represents the application roles available to a user.
      x-examples:
        Example 1:
          role:
            applicationCode: CADI
            roleName: ADMIN
    UserSalesOrgRole:
      title: UserSalesOrgRole
      x-stoplight:
        id: l9dxn00xna96c
      type: object
      description: Represents the roles available to a user within a sales organization.
      properties:
        role:
          $ref: '#/components/schemas/Role'
        salesOrgCode:
          type: string
          x-stoplight:
            id: 7ftv9xb5xnlov
          description: Sales organization code
          example: '12345'
      x-examples:
        Example 1:
          role:
            applicationCode: CADI
            roleName: ADMIN
          salesOrgCode: '12345'
    UserSalesOrgCustomerRole:
      title: UserSalesOrgCustomerRole
      x-stoplight:
        id: 35qiodmkqrc8l
      type: object
      description: Represents the roles available to a user within a sales organization and for a customer code
      properties:
        role:
          $ref: '#/components/schemas/Role'
        salesOrgCode:
          type: string
          x-stoplight:
            id: igpqbd4pu7avf
          description: Sales organization code
          example: S001
        customerCode:
          type: string
          x-stoplight:
            id: qgo3al9qy9fww
          description: Customer code (aka customer id)
          example: '12345'
      x-examples:
        Example 1:
          role:
            applicationCode: CADI
            roleName: ADMIN
          salesOrgCode: S001
          customerCode: '12345'
    Roles:
      title: Roles
      x-stoplight:
        id: 1bfgt53b1bhj1
      type: object
      description: Represents the roles available to a user
      properties:
        userRoles:
          type: array
          x-stoplight:
            id: 23f4hjuuub1b1
          items:
            $ref: '#/components/schemas/UserRole'
          example:
            - role:
                applicationCode: CADI
                roleName: ADMIN
            - role:
                applicationCode: LSU
                roleName: ADMIN
        userSalesOrgRoles:
          type: array
          x-stoplight:
            id: 23f4hjuuub1b2
          items:
            $ref: '#/components/schemas/UserSalesOrgRole'
          example:
            - role:
                applicationCode: CADI
                roleName: ADMIN
            - role:
                applicationCode: LSU
                roleName: ADMIN
              salesOrgCode: '12345'
        userSalesOrgCustomerRoles:
          type: array
          x-stoplight:
            id: 23f4hjuuub1b3
          items:
            $ref: '#/components/schemas/UserSalesOrgCustomerRole'
          example:
            - role:
                applicationCode: CADI
                roleName: ADMIN
            - role:
                applicationCode: LSU
                roleName: ADMIN
              salesOrgCode: S001
              customerCode: '12345'
      x-examples:
        Example 1:
          userRoles:
            - role:
                applicationCode: CADI
                roleName: ADMIN
            - role:
                applicationCode: LSU
                roleName: ADMIN
          userSalesOrgRoles:
            - role:
                applicationCode: CADI
                roleName: ADMIN
            - role:
                applicationCode: LSU
                roleName: ADMIN
              salesOrgCode: '12345'
          userSalesOrgCustomerRoles:
            - role:
                applicationCode: CADI
                roleName: ADMIN
            - role:
                applicationCode: LSU
                roleName: ADMIN
              salesOrgCode: S001
              customerCode: '12345'
    BadRequest:
      title: BadRequest
      x-stoplight:
        id: qrvxod9te1ghu
      type: object
      properties:
        type:
          type: string
          x-stoplight:
            id: 2nj0ldm0spdmd
          example: https://zalando.github.io/problem/constraint-violation
        status:
          type: string
          x-stoplight:
            id: inxabrdaqodk6
          example: '400'
        violations:
          x-stoplight:
            id: svlilbm7emuyq
          type: array
          items:
            x-stoplight:
              id: 7dn9dwing4le1
            type: object
            properties:
              field:
                type: string
                x-stoplight:
                  id: cu4l5b36ro03c
                example: password
              message:
                type: string
                x-stoplight:
                  id: kvrdfbuz2y4uo
                example: must not be blank
          example:
            - field: password
              message: must not be blank
            - field: user
              message: must not be null
        title:
          type: string
          x-stoplight:
            id: 4w8mpusg8stxw
          example: Constrain Violation
      x-examples:
        Example 1:
          type: https://zalando.github.io/problem/constraint-violation
          status: '400'
          violations:
            - field: password
              message: must not be blank
            - field: user
              message: must not be null
          title: Constrain Violation
      description: Represents a format for describing errors in an API using Zalando
  parameters:
    appCode:
      name: appCode
      in: path
      schema:
        type: string
        example: APP
      description: The application code
      required: true
      example: CADI
    roleName:
      name: roleName
      in: query
      required: false
      schema:
        type: string
        example: User
      description: Role name to filter SalesOrg relations with Applications
      example: ADMIN
    type:
      name: type
      in: query
      required: false
      schema:
        type: string
        example: Internal
      description: The user's type
      example: EXTERNAL
    searchExpressions:
      name: searchExpressions
      in: query
      required: false
      schema:
        type: array
        items:
          type: string
        example:
          - Carlsberg
          - Customer
      description: List of search expressions
    page:
      name: page
      in: query
      required: false
      schema:
        type: integer
        example: 1
        minimum: 0
      description: Page number
    size:
      name: size
      in: query
      required: false
      schema:
        type: integer
        example: 10
        minimum: 1
      description: 'Page size number '
    customerCodes:
      name: customerCodes
      in: query
      required: false
      schema:
        type: array
        items:
          type: string
        example:
          - '12345'
          - abc123
      description: List of customer codes
    applicationCode:
      name: applicationCode
      in: query
      required: false
      schema:
        type: string
        example: APP
      description: The Application code to filter SalesOrg relations
    userEid:
      name: userEid
      in: path
      required: true
      schema:
        type: string
        example: '12345'
      description: The user's unique identifier
    email:
      name: email
      in: query
      required: true
      schema:
        type: string
        example: brewery@email.email
        format: email
      description: User's email
    phone:
      name: phone
      in: query
      required: true
      schema:
        type: string
        example: '123456789'
      description: User's phone
    queryEid:
      name: eid
      in: query
      required: false
      schema:
        type: array
        items:
          type: string
        example:
          - '12345'
          - abc123
      description: List of eids to search for
    grantor:
      name: grantor
      in: query
      required: true
      schema:
        type: string
        example: '12345'
      description: The Grantor EID
    salesOrgCode:
      name: salesOrgCode
      in: path
      required: true
      schema:
        type: string
        example: S001
      description: Sales organization code
    operation:
      name: operation
      in: query
      required: true
      schema:
        type: string
        enum:
          - ENABLE
          - DISABLE
        example: ENABLE
      description: The operation to do
    rolePlacement:
      name: rolePlacement
      in: query
      required: true
      schema:
        type: string
        example: user
      description: Type of role to be updated
    azureId:
      name: azureId
      in: path
      required: true
      schema:
        type: string
        example: '12345'
      description: User's azure id
    newStatus:
      name: newStatus
      in: query
      required: true
      schema:
        type: string
        enum:
          - ENABLE
          - DISABLE
        example: ENABLE
      description: The new status for the user
  responses:
    UserPage:
      description: Pages of Users
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/UserPage'
    SuccessfulAuthentication:
      description: Successful authentication response
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/SuccessfulAuthentication'
    User:
      description: User data response
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/User'
    UserList:
      description: User list response
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/UserList'
    AzureAdConfig:
      description: Azure Ad Config response
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/AzureAdConfig'
    UserOtp:
      description: User Otp response
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/UserOtp'
    UserAzureFederation:
      description: User azure federation response
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/UserAzureFederation'
    Roles:
      description: List of user roles response
      content:
        application/json:
          schema:
            type: object
            properties:
              userRoles:
                type: array
                x-stoplight:
                  id: pdxozmnqe2n04
                items:
                  $ref: '#/components/schemas/UserRole'
              userSalesOrgRoles:
                type: array
                x-stoplight:
                  id: x4pvs5kw3tdwo
                items:
                  $ref: '#/components/schemas/UserSalesOrgRole'
              userSalesOrgCustomerRoles:
                type: array
                x-stoplight:
                  id: 4cramffo6m30q
                items:
                  $ref: '#/components/schemas/UserSalesOrgCustomerRole'
    BadRequest:
      description: |-
        Bad request response.
        Can return:
            
            Invalid applicationCode
            Invalid roleName for the selected applicationCode
            Invalid salesOrgCode
            Users eids are limited up to 20 eids
            One and only one of the parameters must be present: 'email', 'phone', 'searchExpression'
            SearchExpressions are limited up to 5
            Invalid combination of parameters: 'type', 'email'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/BadRequest'
        application/xml:
          schema:
            type: object
            properties: {}
  requestBodies:
    UserEmail:
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/UserEmail'
      description: User email data body
    UserPhone:
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/UserPhone'
      description: User phone data body
    UserRole:
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/UserRole'
    UserSalesOrgRole:
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/UserSalesOrgRole'
      description: 'User Sales Org Role body '
    UserSalesOrgCustomerRole:
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/UserSalesOrgCustomerRole'
      description: User sales org customer role body
    EidAndPassword:
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/EidAndPassword'
    EmailAndPassword:
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/EmailAndPassword'
    PhoneAndPassword:
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/PhoneAndPassword'
    NewUser:
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/NewUser'
    CustomerPosition:
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/CustomerPosition'
    UserFullName:
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/UserFullName'
    NewPassword:
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/NewPassword'
    OtpDetails:
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/OtpDetails'
    OtpAuth:
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/OtpAuth'
x-stoplight:
  id: 26f7fe79a4edb
