Class: WorkOS::Passwordless
- Inherits:
-
Object
- Object
- WorkOS::Passwordless
- Defined in:
- lib/workos/passwordless.rb
Overview
Passwordless authentication sessions (magic-link).
session = client.passwordless.create_session(email: "user@example.com")
client.passwordless.send_session(session.id)
Defined Under Namespace
Classes: PasswordlessSession
Instance Method Summary collapse
-
#create_session(email:, type: "MagicLink", redirect_uri: nil, state: nil, connection: nil, expires_in: nil, request_options: {}) ⇒ PasswordlessSession
Create a passwordless session.
-
#initialize(client) ⇒ Passwordless
constructor
A new instance of Passwordless.
-
#send_session(session_id, request_options: {}) ⇒ Hash
Send the magic-link email for an existing passwordless session.
Constructor Details
#initialize(client) ⇒ Passwordless
Returns a new instance of Passwordless.
31 32 33 |
# File 'lib/workos/passwordless.rb', line 31 def initialize(client) @client = client end |
Instance Method Details
#create_session(email:, type: "MagicLink", redirect_uri: nil, state: nil, connection: nil, expires_in: nil, request_options: {}) ⇒ PasswordlessSession
Create a passwordless session.
45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/workos/passwordless.rb', line 45 def create_session(email:, type: "MagicLink", redirect_uri: nil, state: nil, connection: nil, expires_in: nil, request_options: {}) body = { "email" => email, "type" => type, "redirect_uri" => redirect_uri, "state" => state, "connection" => connection, "expires_in" => expires_in }.compact response = @client.request(method: :post, path: "/passwordless/sessions", auth: true, body: body, request_options: ) PasswordlessSession.from_hash(JSON.parse(response.body)) end |
#send_session(session_id, request_options: {}) ⇒ Hash
Send the magic-link email for an existing passwordless session.
63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/workos/passwordless.rb', line 63 def send_session(session_id, request_options: {}) response = @client.request( method: :post, path: "/passwordless/sessions/#{WorkOS::Util.encode_path(session_id)}/send", auth: true, body: {}, request_options: ) JSON.parse(response.body || "{}") rescue JSON::ParserError {} end |