Sha256: 56836abefb84bd60dbd50610919db135f9e97091387019293e0519fa0c48d6c0

Contents?: true

Size: 1.71 KB

Versions: 25

Compression:

Stored size: 1.71 KB

Contents

# frozen_string_literal: true

require 'net/http'

module WorkOS
  # The Portal module provides resource methods for working with the Admin
  # Portal product
  module Portal
    class << self
      include Client

      GENERATE_LINK_INTENTS = WorkOS::Types::Intent::ALL

      # 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: ["audit_logs", "dsync", "log_streams", "sso",]
      # @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.
      # @param [String] The URL to which WorkOS will redirect users to upon
      #  successfully setting up Single Sign On or Directory Sync.
      def generate_link(intent:, organization:, return_url: nil, success_url: nil)
        validate_intent(intent)

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

        response = execute_request(request: request)

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

      private

      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

25 entries across 25 versions & 1 rubygems

Version Path
workos-5.15.0 lib/workos/portal.rb
workos-5.14.0 lib/workos/portal.rb
workos-5.13.0 lib/workos/portal.rb
workos-5.12.0 lib/workos/portal.rb
workos-5.11.1 lib/workos/portal.rb
workos-5.11.0 lib/workos/portal.rb
workos-5.10.0 lib/workos/portal.rb
workos-5.9.0 lib/workos/portal.rb
workos-5.8.0 lib/workos/portal.rb
workos-5.7.0 lib/workos/portal.rb
workos-5.6.0 lib/workos/portal.rb
workos-5.5.1 lib/workos/portal.rb
workos-5.5.0 lib/workos/portal.rb
workos-5.4.0 lib/workos/portal.rb
workos-5.3.0 lib/workos/portal.rb
workos-5.2.1 lib/workos/portal.rb
workos-5.2.0 lib/workos/portal.rb
workos-5.1.0 lib/workos/portal.rb
workos-5.0.0 lib/workos/portal.rb
workos-4.8.0 lib/workos/portal.rb