FusionAuth Ruby Client

Ruby Client Library

The Ruby client library allows you to integrate FusionAuth with your Ruby application.

Source Code:

Gem:

To install the FusionAuth Ruby Gem package run:

$ gem install fusionauth_client

The following code assumes FusionAuth is running on http://localhost:9011 and uses an API key 6b87a398-39f2-4692-927b-13188a81a9a3, you will need to supply your own API key, and if you are not running FusionAuth locally, your host parameter may be different.

Here is an example of using the register and the login methods to create a new User and Registration and then login the user.

# Construct the FusionAuth Client with the following values:
#  - API Key: 6b87a398-39f2-4692-927b-13188a81a9a3
#  - Host: http://localhost:9011
client = FusionAuth::FusionAuthClient.new('6b87a398-39f2-4692-927b-13188a81a9a3', 'http://localhost:9011',
  ->(cr) { cr.success_response },
  ->(cr) { raise "Status = #{cr.status} error body = #{cr.error_response}" })

# Create a user + registration
id = SecureRandom.uuid
client.register!(id, {
    :user => {
        :firstName => 'Ruby',
        :lastName => 'Client',
        :email => 'ruby.client.test@fusionauth.io',
        :password => 'password'
    },
    :registration => {
        :applicationId => application_id,
        :data => {
            :foo => 'bar'
        },
        :preferredLanguages => %w(en fr),
        :roles => %w(user)
    }
})

# Authenticate the user
response = client.login!({
    :loginId => 'ruby.client.test@fusionauth.io',
    :password => 'password',
    :applicationId => application_id
})
user = response.user