Sha256: 6bc802ed7a50f06f5715c8632e1d91e8c11f8b490f815f0ab5ec039339fdb370

Contents?: true

Size: 1.8 KB

Versions: 17

Compression:

Stored size: 1.8 KB

Contents

# frozen_string_literal: true
# typed: true

require 'net/http'

module WorkOS
  # The Portal module provides resource methods for working with the Admin
  # Portal product
  module Portal
    class << self
      extend T::Sig
      include Base
      include Client

      GENERATE_LINK_INTENTS = WorkOS::Types::Intent.values.map(&:serialize).
                              freeze

      # Generate a link to grant access to an organization's Admin Portal
      #
      # @param [String] intent The access scope for the generated Admin Portal
      #  link. Valid values are: ["sso", "dsync"]
      # @param [String] organization The ID of the organization the Admin
      #  Portal link will be generated for.
      # @param [String] The URL that the end user will be redirected to upon
      #  exiting the generated Admin Portal. If none is provided, the default
      #  redirect link set in your WorkOS Dashboard will be used.
      sig do
        params(
          intent: String,
          organization: String,
          return_url: T.nilable(String),
        ).returns(String)
      end
      def generate_link(intent:, organization:, return_url: nil)
        validate_intent(intent)

        request = post_request(
          auth: true,
          body: {
            intent: intent,
            organization: organization,
            return_url: return_url,
          },
          path: '/portal/generate_link',
        )

        response = execute_request(request: request)

        JSON.parse(response.body)['link']
      end

      private

      sig { params(intent: String).void }
      def validate_intent(intent)
        return if GENERATE_LINK_INTENTS.include?(intent)

        raise ArgumentError, "#{intent} is not a valid value." \
        " `intent` must be in #{GENERATE_LINK_INTENTS}"
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
workos-2.4.0 lib/workos/portal.rb
workos-2.3.0 lib/workos/portal.rb
workos-2.2.1 lib/workos/portal.rb
workos-2.2.0 lib/workos/portal.rb
workos-2.1.1 lib/workos/portal.rb
workos-2.1.0 lib/workos/portal.rb
workos-2.0.0 lib/workos/portal.rb
workos-1.6.1 lib/workos/portal.rb
workos-1.6.0 lib/workos/portal.rb
workos-1.5.1 lib/workos/portal.rb
workos-1.5.0 lib/workos/portal.rb
workos-1.4.0 lib/workos/portal.rb
workos-1.3.0 lib/workos/portal.rb
workos-1.2.1 lib/workos/portal.rb
workos-1.2.0 lib/workos/portal.rb
workos-1.1.0 lib/workos/portal.rb
workos-1.0.0 lib/workos/portal.rb