# Ruby Client Library The FusionAuth Ruby Client library allows you to call FusionAuth from Ruby applications. > For the index of this section of the site, see [llms.txt](https://4002.18-224-161-104.sslip.io/docs/llms.txt) The Ruby client library allows you to integrate FusionAuth with your Ruby application. Source Code: * [https://github.com/FusionAuth/fusionauth-ruby-client](https://github.com/FusionAuth/fusionauth-ruby-client) Gem: * [https://rubygems.org/gems/fusionauth\client](https://rubygems.org/gems/fusionauth_client) To install the FusionAuth Ruby Gem package run: ```bash 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. ```ruby require 'fusionauth/fusionauth_client' require 'securerandom' require 'pp' # Construct the FusionAuth Client client = FusionAuth::FusionAuthClient.new( 'REPLACE_ME', 'http://localhost:9011' ) application_id = '85a03867-dccf-4882-adde-1a79aeec50df' # Create a user + registration id = SecureRandom.uuid response = client.register(id, { user: { firstName: 'Ruby', lastName: 'User', email: 'ruby_user@example.com', password: 'password' }, registration: { applicationId: application_id, data: { foo: 'bar' }, preferredLanguages: %w(en fr), roles: %w(dev) } }) if response.success_response pp response.success_response else if response.exception # if we can't connect print response.exception end print "status: #{response.status}" print response.error_response exit end ``` ## Usage Suggestions FusionAuth client libraries are a thin wrapper around the REST API. Client libraries are typically used in two different ways. First, they can be used to access the FusionAuth [APIs](https://4002.18-224-161-104.sslip.io/docs/apis.md) in a familiar format, leveraging language features like auto-completion. When used for this, they can be helpful to script FusionAuth configuration, automate common tasks, and create copies of existing applications, groups and more. To use the client libraries effectively in this way, it is helpful to review the source code of the client library and the API documentation, which contains the JSON structure. The API documentation is very thorough about the JSON objects it expects as part of the payload as well as what parameters are required when. Second, client libraries can exchange a token to let a user to log in via the Authorization Code Grant. This is a secondary use of these libraries. This process is best done by using a language specific OAuth library, which will work with FusionAuth. Here is a [community curated list of such libraries](https://oauth.net/code/). Client libraries do not currently provide higher level functionality such as token management. Here is an [open issue](https://github.com/FusionAuth/fusionauth-issues/issues/1674) detailing some requested higher level functionality. Please feel free to file an issue or upvote this one if you desire it. You can always directly call the REST API if the client library functionality doesn't work for you. All the client libraries use the [REST API](https://4002.18-224-161-104.sslip.io/docs/apis.md). In general, the request object will either be string parameters or a complex object depending on the type of API call being made. Any request object will be mapped by the library to a JSON object required by the corresponding API method. Examining the API documents for the operations you're trying to call will therefore be useful, especially if you are using language without static typing. The response object will typically contain: * a status corresponding to the HTTP status code returned by the API. It may also be -1 if no HTTP request was successfully made * a JSON success object if the call succeeded. * a JSON error object with an intelligible message if the status code is `4xx` or `5xx`. * an exception object if there was no HTTP request sent or there was no reasonable response from the server. ## Example Apps * [Ebook application](https://github.com/FusionAuth/fusionauth-example-rails-ebook) - Example Rails app which lets you download ebooks * [Lob integration](https://github.com/FusionAuth/fusionauth-example-rails-lob-integration) - Example Rails app which lets send a letter to someone's address to verify they live there * [Migrating from Rails example](https://github.com/FusionAuth/fusionauth-example-migrating-rails) - Example of migrating from Rails-based authentication * [Ruby JWT](https://github.com/FusionAuth/fusionauth-example-ruby-jwt) - JWT creation and decoding examples with the Ruby jwt gem * [Ruby on Rails API quickstart](https://github.com/FusionAuth/fusionauth-quickstart-ruby-on-rails-api) - Ruby on Rails API quickstart tutorial showing how to integrate FusionAuth with a Ruby on Rails API * [Ruby on Rails quickstart](https://github.com/FusionAuth/fusionauth-quickstart-ruby-on-rails-web) - Ruby on Rails quickstart tutorial showing how to integrate FusionAuth with a Ruby on Rails application * [Ruby on Rails with Custom Scopes](https://github.com/FusionAuth/fusionauth-example-ruby-on-rails-custom-scopes) - This example application shows how to implement Custom Scopes with FusionAuth. * [Ruby tenant creation](https://github.com/FusionAuth/fusionauth-example-ruby-tenant-creation) - Creating new tenants in Ruby ## Upgrade Policy Besides the releases made to keep track of the FusionAuth API as mentioned above, SDKs and Client Libraries may periodically receive updates with bug fixes, security patches, tests, code samples, or documentation changes. These releases may also update dependencies, language engines, and operating systems, as we'll follow the deprecation and sunsetting policies of the underlying technologies that the libraries use. This means that after a language, framework, or operating system is deprecated by their own maintainer, our SDKs and Client Libraries that depend on it will also be deprecated by us, and will eventually be updated to use a newer version. For more information about upgrades, see our [Upgrade guide](https://4002.18-224-161-104.sslip.io/docs/operate/deploy/upgrade.md#upgrade-a-client-library). Related [Get Started FusionAuth QuickStart for Ruby on Rails API QuickStart Integration of a Ruby on Rails API with FusionAuth. ruby authentication](https://4002.18-224-161-104.sslip.io/docs/get-started/quickstarts/api/quickstart-ruby-on-rails-api.md) [Lifecycle Migrate From Rails Learn how to migrate your users from Rails-based authentication to FusionAuth. rails](https://4002.18-224-161-104.sslip.io/docs/lifecycle/migrate-users/framework-specific/rails.md) [SDKs Ruby Example Apps Learn about example applications written in Ruby. fusionauth ruby](https://4002.18-224-161-104.sslip.io/docs/sdks/examples/ruby.md) --- ## Other pages in SDKs > For the full index of this section, see [SDKs](https://4002.18-224-161-104.sslip.io/docs/llms-sdks.txt). - [Kotlin SDK for Android](https://4002.18-224-161-104.sslip.io/docs/sdks/android-sdk.md): The FusionAuth Android SDK allows you to add different OAuth2 and OpenID Connect functionalities to your Android application. It's a highly standardized and simplified starting point for developers to easily integrate FusionAuth in their own custom Android mobile apps by taking care of all the dependencies. - [Angular SDK](https://4002.18-224-161-104.sslip.io/docs/sdks/angular-sdk.md): The FusionAuth Angular SDK allows you to add login, logout and registration functionality to your Angular application. - [Example Apps](https://4002.18-224-161-104.sslip.io/docs/sdks/examples.md): Learn about example applications using FusionAuth. - [Go Client Library](https://4002.18-224-161-104.sslip.io/docs/sdks/go.md): The FusionAuth Go Client library allows you to call FusionAuth from Go applications. - [Java Client Library](https://4002.18-224-161-104.sslip.io/docs/sdks/java.md): The FusionAuth Java Client library allows you to call FusionAuth from Java applications. - [.NET Core Client Library](https://4002.18-224-161-104.sslip.io/docs/sdks/netcore.md): The FusionAuth .NET Core Client library allows you to call FusionAuth from a .NET Core application. - [PHP Client Library](https://4002.18-224-161-104.sslip.io/docs/sdks/php.md): The FusionAuth PHP Client library allows you to call FusionAuth from PHP applications. - [Python Client Library](https://4002.18-224-161-104.sslip.io/docs/sdks/python.md): The FusionAuth Python Client library allows you to call FusionAuth from Python applications. - [React SDK](https://4002.18-224-161-104.sslip.io/docs/sdks/react-sdk.md): The FusionAuth React SDK allows you to add login, logout and registration functionality to your React application. - [Swift SDK for iOS](https://4002.18-224-161-104.sslip.io/docs/sdks/swift-sdk.md): Create iOS mobile apps with FusionAuth-based authentication using the Swift SDK. - [TypeScript Client Library](https://4002.18-224-161-104.sslip.io/docs/sdks/typescript.md): The FusionAuth Typescript Client library allows you to call FusionAuth from JavaScript and Typescript applications. - [Vue SDK](https://4002.18-224-161-104.sslip.io/docs/sdks/vue-sdk.md): The FusionAuth Vue SDK allows you to add login, logout and registration functionality to your Vue application.