Sha256: 121d2523a6595c493adbf5b766ff34ebf02da59d9a25d8a845b8eacc4256a908
Contents?: true
Size: 1.22 KB
Versions: 8
Compression:
Stored size: 1.22 KB
Contents
# frozen_string_literal: true require 'net/http' module WorkOS # The Widgets module provides resource methods for working with the Widgets APIs module Widgets class << self include Client WIDGET_SCOPES = WorkOS::Types::WidgetScope::ALL # Generate a widget token. # # @param [String] organization_id The ID of the organization to generate the token for. # @param [String] user_id The ID of the user to generate the token for. # @param [WidgetScope[]] The scopes to generate the token for. def get_token(organization_id:, user_id:, scopes:) validate_scopes(scopes) request = post_request( auth: true, body: { organization_id: organization_id, user_id: user_id, scopes: scopes, }, path: '/widgets/token', ) response = execute_request(request: request) JSON.parse(response.body)['token'] end private def validate_scopes(scopes) return if scopes.all? { |scope| WIDGET_SCOPES.include?(scope) } raise ArgumentError, 'scopes contains an invalid value.' \ " Every item in `scopes` must be in #{WIDGET_SCOPES}" end end end end
Version data entries
8 entries across 8 versions & 1 rubygems