Ruby

Authenticate requests and manage Passage users with Ruby.

Gem version

Prerequisites

Passage App ID and API Key from Passage Console

Install

Install the passageidentity (opens in a new tab) gem.

gem install passageidentity

Initialize

require 'passageidentity'
 
passage = Passage::Client.new(
  app_id: ENV['PASSAGE_APP_ID'],
  api_key: ENV['PASSAGE_API_KEY']
)

Authenticating requests

The Passkey Complete Ruby SDK provides a way to validate JWT-authenticated requests. To learn more, see our full guide on JWTs.

post '/protected-route' do
  # Get Passage JWT from the request's Authorization header
  auth_header = request.env['HTTP_AUTHORIZATION']
  token = auth_header.delete_prefix('Bearer').strip
 
  # Validate JWT using Passage
  begin
    user_id = passage.auth.validate_jwt(jwt: token)
 
    # Token is valid
    user = passage.user.get(user_id: user_id)
 
    puts user
  rescue Exception => e
    # Token is invalid
  end
end

User Management

In addition to authenticating requests, the Passkey Complete Ruby SDK also provides a way to securely manage users. These functions require authentication using a Passage API key. API keys can be managed in the Passage Console.

The functionality currently available on a user is:

  • Get a user's information (including any defined user metadata fields)
  • Activate or deactivate a user (a deactivated user will not be able to log in)
  • Update a user's information (email address or phone number)
  • Revoke a user's refresh tokens
  • Delete a user
  • Create a user

User device management

The functionality currently available is:

  • List all devices for a user
  • Revoke a particular device from a user

Creating Magic Links

The Passkey Complete Ruby SDK can be used to generate custom Magic Links for users, that can be embedded into any content medium. To learn more, see our full guide on Embedded Magic Links.