Skip to main content
Docs

Ruby Quickstart

You will learn the following:

  • Install clerk-sdk-ruby
  • Configuration
  • Instantiate a Clerk::SDK instance

Before you start

Example repository

Learn how to use Clerk to quickly and easily add secure authentication and user management to your Ruby app. If you would like to use a framework, refer to the integrations.

The Clerk Ruby SDK provides a range of backend utilities to simplify user authentication and management in your application.

  1. Add the following code to your application's Gemfile.
    Gemfile
    gem 'clerk-sdk-ruby', require: "clerk"
  2. Run the following command to install the SDK:
    terminal
    $ bundle install

The configuration object provides a flexible way to configure the SDK. When a configuration value is not explicitly provided, it will fall back to checking the corresponding environment variable. You must provide your Clerk Secret Key, which can be retrieved from the API keys page in the Clerk Dashboard.

The following example shows how to set up your configuration object:

Clerk.configure do |c|
  c.secret_key = `YOUR_SECRET_KEY` # if omitted: ENV["CLERK_SECRET_KEY"] - API calls will fail if unset
  c.logger = Logger.new(STDOUT) # if omitted, no logging
end

For more information, see Faraday's documentation.

Instantiate a Clerk::SDK instance

All available methods are listed in the Ruby HTTP Client documentation. The Ruby HTTP Client is a generated wrapper around the Backend API that provides a more Ruby-friendly interface.

To access available methods, you must instantiate a Clerk::SDK instance.

sdk = Clerk::SDK.new

create_user_request = Clerk::SDK::CreateUserRequest.new(
  first_name: "John",
  last_name: "Doe",
  email_address: ["john.doe@example.com"],
  password: "password"
)

# Create a user
sdk.users.create(create_user_request)

# List all users and ensure the user was created
sdk.users.get_user_list

# Get the first user created in your instance
user = sdk.users.get_user_list(limit: 1).first

# Use the user's ID to lock the user
sdk.users.lock_user(user["id"])

# Then, unlock the user so they can sign in again
sdk.users.unlock_user(user["id"])

Ruby SDK Reference

Learn more about the Ruby SDK.

Deploy to Production

Learn how to deploy your Clerk app to production.

Feedback

What did you think of this content?

Last updated on