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')
# 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
Related Posts
Example apps
- Import scripts - Example import scripts to ease migration.
- Rails app - Application consuming a Rails API, providing a JWT to that API
- Rails apis - Protecting a Rails API with a JWT
- Rails with oauth - Using OAuth/OIDC with a Ruby on Rails app
- Ruby jwt - JWT creation and decoding examples with the Ruby jwt gem
- Ruby tenant creation - Creating new tenants in Ruby