Module: WorkOS::Passwordless

Extended by:
Client
Defined in:
lib/workos/passwordless.rb

Overview

The Passwordless module provides convenience methods for working with passwordless sessions including the WorkOS Magic Link. You’ll need a valid API key.

Class Method Summary collapse

Methods included from Client

client, delete_request, execute_request, get_request, handle_error_response, post_request, put_request, user_agent

Class Method Details

.create_session(options) ⇒ Object

Create a Passwordless Session.

Parameters:

  • options (Hash)

    A hash with options for the session

Options Hash (options):

  • email (String)

    The email of the user to authenticate.

  • state (String)

    Optional parameter that the redirect URI received from WorkOS will contain. The state parameter can be used to encode arbitrary information to help restore application state between redirects.

  • connection (String)

    Optional parameter for the ID of a specific connection. This can be used to create a Passwordless Session for a specific connection rather than using the domain from the email to determine the Organization and Connection.

  • type (String)

    The type of Passwordless Session to create. Currently, the only supported value is ‘MagicLink’.

  • redirect_uri (String)

    The URI where users are directed after completing the authentication step. Must match a configured redirect URI on your WorkOS dashboard.

Returns:

  • Hash



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/workos/passwordless.rb', line 34

def create_session(options)
  response = execute_request(
    request: post_request(
      path: '/passwordless/sessions',
      auth: true,
      body: options,
    ),
  )

  hash = JSON.parse(response.body)

  WorkOS::Types::PasswordlessSessionStruct.new(
    id: hash['id'],
    email: hash['email'],
    expires_at: Date.parse(hash['expires_at']),
    link: hash['link'],
  )
end

.send_session(session_id) ⇒ Object

Send a Passwordless Session via email.

Parameters:

  • session_id (String)

    The unique identifier of the Passwordless Session to send an email for.

Returns:

  • Hash



59
60
61
62
63
64
65
66
67
68
# File 'lib/workos/passwordless.rb', line 59

def send_session(session_id)
  response = execute_request(
    request: post_request(
      path: "/passwordless/sessions/#{session_id}/send",
      auth: true,
    ),
  )

  JSON.parse(response.body)
end