Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/authsignal/authsignal-ruby
The Authsignal Ruby Client
https://github.com/authsignal/authsignal-ruby
fido2 mfa passkeys ruby webauthn
Last synced: about 1 month ago
JSON representation
The Authsignal Ruby Client
- Host: GitHub
- URL: https://github.com/authsignal/authsignal-ruby
- Owner: authsignal
- License: mit
- Created: 2022-07-13T22:17:30.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-11-05T22:00:11.000Z (about 2 months ago)
- Last Synced: 2024-11-05T22:21:21.066Z (about 2 months ago)
- Topics: fido2, mfa, passkeys, ruby, webauthn
- Language: Ruby
- Homepage: https://www.authsignal.com
- Size: 96.7 KB
- Stars: 2
- Watchers: 2
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Authsignal Server Ruby SDK
Check out our [official Ruby SDK documentation](https://docs.authsignal.com/sdks/server/ruby), and [Ruby on Rails Quickstart Guide](https://docs.authsignal.com/quickstarts/ruby-on-rails).
## Installation
Add this line to your application's Gemfile:
```ruby
gem "authsignal-ruby"
```And then execute:
$ bundle install
Or install it yourself as:
$ gem install authsignal-ruby
## Initialization
Initialize the Authsignal Ruby SDK, ensuring you do not hard code the Authsignal Secret Key, always keep this safe.
In Ruby on Rails, you would typically place this code block in a file like `config/initializers/authsignal.rb`
```ruby
Authsignal.setup do |config|
config.api_secret_key = ENV["AUTHSIGNAL_SECRET_KEY"]
end
```You can find your `api_secret_key` in the [Authsignal Portal](https://portal.authsignal.com/organisations/tenants/api).
You must specify the correct `baseUrl` for your tenant's region.
| Region | Base URL |
| ----------- | ----------------------------------- |
| US (Oregon) | https://signal.authsignal.com/v1 |
| AU (Sydney) | https://au.signal.authsignal.com/v1 |
| EU (Dublin) | https://eu.signal.authsignal.com/v1 |For example, to set the base URL to use our AU region:
```
require 'authsignal'Authsignal.setup do |config|
config.api_secret_key = ENV["AUTHSIGNAL_SECRET_KEY"]
config.base_uri = "https://au.signal.authsignal.com/v1"# If you would like the Authsignal client to retry requests due to network issues
config.retry = true # default value: false# If you would like to inspect raw request/response in development
config.debug = true # default value: false
end
```## Usage
Authsignal's server side signal API has four main api calls `track`, `get_action`, `get_user`, `enroll_verified_authenticator`.
For more details on these api calls, refer to our [official Ruby SDK docs](https://docs.authsignal.com/sdks/server/ruby#track).
Example:
```ruby
Authsignal.track user_id: 'AS_001', action: 'withdraw', idempotency_key: 'a_random_hash'# returns:
# {
# success?: true,
# state: 'ALLOW',
# idempotency_key: 'a_random_hash',
# ... rest of payload ...
# }
```### Response & Error handling
The Authsignal SDK offers two response formats. By default, its methods return the payload in hash format.
Example:
```ruby
Authsignal.enroll_verified_authenticator user_id: 'AS_001',
authenticator: {
oob_channel: 'INVALID', email: '[email protected]'
}# returns:
# {
# success?: false,
# status: 400,
# error: 'invalid_request',
# error_description: '/body/oobChannel must be equal to one of the allowed values'
# }
```All methods have a bang (!) counterpart that raises an Authsignal::ApiError if the request fails.
Example:
```ruby
Authsignal.enroll_verified_authenticator! user_id: 'AS_001',
authenticator: {
oob_channel: 'INVALID', email: '[email protected]'
}# raise:
#