Class: WorkOS::Widgets

Inherits:
Object
  • Object
show all
Defined in:
lib/workos/widgets.rb

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Widgets

Returns a new instance of Widgets.



9
10
11
# File 'lib/workos/widgets.rb', line 9

def initialize(client)
  @client = client
end

Instance Method Details

#create_token(organization_id:, user_id: nil, scopes: nil, request_options: {}) ⇒ WorkOS::WidgetSessionTokenResponse

Generate a widget token

Parameters:

  • organization_id (String)

    The ID of the organization to scope the widget session to.

  • user_id (String, nil) (defaults to: nil)

    The ID of the user to issue the widget session token for.

  • scopes (Array<WorkOS::Types::WidgetSessionTokenScopes>, nil) (defaults to: nil)

    The scopes to grant the widget session.

  • request_options (Hash) (defaults to: {})

    (see WorkOS::Types::RequestOptions)

Returns:



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/workos/widgets.rb', line 19

def create_token(
  organization_id:,
  user_id: nil,
  scopes: nil,
  request_options: {}
)
  body = {
    "organization_id" => organization_id,
    "user_id" => user_id,
    "scopes" => scopes
  }.compact
  response = @client.request(
    method: :post,
    path: "/widgets/token",
    auth: true,
    body: body,
    request_options: request_options
  )
  result = WorkOS::WidgetSessionTokenResponse.new(response.body)
  result.last_response = WorkOS::Types::ApiResponse.new(http_status: response.code.to_i, http_headers: response.each_header.to_h, request_id: response["x-request-id"])
  result
end