Source

services/AuthService.class.js

import ScenidCloudService from './ScenidCloudService.class.js'

/**
 * Admin-level client for the Scenid Auth Service.
 *
 * Obtained via `sdk.asAdmin().Auth()`. Runs requests with a machine-to-machine
 * service token, so it is suited for administrative operations against the auth
 * service that do not require a user context.
 *
 * @extends ScenidCloudService
 *
 * @example
 * const auth = sdk.asAdmin().Auth()
 */
class AuthService extends ScenidCloudService {
  /**
   * @param {string|function(): Promise.<string>} tokenSource
   * @param {string} serviceUrl
   */
  constructor (tokenSource, serviceUrl) {
    super(tokenSource, serviceUrl)

    this.Users = {
      /**
       * Lists all users in the tenant, including their group memberships.
       *
       * @returns {Promise<ServiceResponse>} result is an array of user objects,
       *   each with `uid`, `email`, `displayName`, and `userGroups: [{ name, assignmentMethod }]`.
       */
      list: () => this.get('/api/v1/users')
    }

    this.UserGroups = {
      /**
       * Lists all user groups in the tenant.
       *
       * @returns {Promise<ServiceResponse>} result is an array of group objects,
       *   each with `gid`, `name`, and `assignOnRegister`.
       */
      list: () => this.get('/api/v1/userGroups')
    }
  }
}

export default AuthService