Stytch Ruby Gem


Keywords
authentication, ruby, sdk, stytch
License
MIT
Install
gem install stytch -v 9.7.0

Documentation

Stytch Ruby Gem

The Stytch Ruby gem makes it easy to use the Stytch user infrastructure API in Ruby applications.

It pairs well with the Stytch Web SDK or your own custom authentication flow.

Install

Add this line to your application's Gemfile:

gem 'stytch'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install stytch

Usage

You can find your API credentials in the Stytch Dashboard.

This client library supports all Stytch's live products:

B2C

B2B

Example B2C usage

Create an API client:

client = Stytch::Client.new(
    env: :test, # available environments are :test and :live
    project_id: "***",
    secret: "***"
)

Send a magic link by email:

client.magic_links.email.login_or_create(
    email: "sandbox@stytch.com"
)

Authenticate the token from the magic link:

client.magic_links.authenticate(
    token: "SeiGwdj5lKkrEVgcEY3QNJXt6srxS3IK2Nwkar6mXD4="
)

Example B2B usage

Create an API client:

require 'stytch'

client = StytchB2B::Client.new(
  project_id: "project-test-uuid",
  secret: "secret-test-uuid"
)

Create an organization

resp = client.organizations.create(
  organization_name: 'Example Org Inc.',
  organization_slug: 'example-org'
)

puts resp

Log the first user into the organization

resp = client.magic_links.email.login_or_signup(
  organization_id: 'organization-test-07971b06-ac8b-4cdb-9c15-63b17e653931',
  email_address: 'sandbox@stytch.com'
)

puts resp

Handling Errors

When possible the response will contain an error_type and an error_message that can be used to distinguish errors.

Learn more about errors in the docs.

Documentation

See example requests and responses for all the endpoints in the Stytch API Reference.

Follow one of the integration guides or start with one of our example apps.

Support

If you've found a bug, open an issue!

If you have questions or want help troubleshooting, join us in Slack or email support@stytch.com.

If you've found a security vulnerability, please follow our responsible disclosure instructions.

Development

See DEVELOPMENT.md

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the Stytch project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.