Ruby
Authenticate requests and manage Passage users with Ruby.
To use the Passage Ruby SDK, you'll need your Passage App ID. You can create a new Passage App in the console.
To see a full example Rails application using the Ruby SDK, check out this Github repo.
The Ruby SDK can be installed from the command line: gem install passageidentity
Authenticating a Request
A Ruby on Rails server can easily authenticate an HTTP request using the passageidentity
gem, available via RubyGems. The example below shows a Rails application that uses Passage to authorize requests.
Then routes are protected using a before_action
.
By default, Passage looks for the user JWT from a cookie that is set by the Passage Element ( psg_auth_token
). If your application uses Authorization headers instead, you can pass the following option to Passage.
Note: If you are not building with Rails, you should use the authenticate_jwt
method and extract the JWT from the header yourself in the authorize
function.
Authorizing a User
It is important to remember that Passage.auth.authenticate_request(request)
validates that a request is properly authenticated, but an additional authorization check is often required. You should use the Passage User ID to store role information and make authorization decisions.
App Information
The Passage SDK provides a way to retrieve information about an app.
User Management
In addition to authenticating requests, the Passage SDK also provides a way to securely manage your users. These functions require authentication using a Passage API key. API keys can be managed in the Passage Console.
Passage API Keys are sensitive! You should store them securely along with your other application secrets.
The functionality currently available on a user is:
Get a user's information (including any defined user metadata fields)
Activate or deactivate a user (a deactivated user will not be able to log in)
Update a user's information (email address or phone number)
Delete a user
Create a user
All fields available in a Passage User object are listed below:
Field | Type |
id | string |
string | |
phone | string |
active | boolean |
email_verified | boolean |
created_at | datetime |
last_login_at | datetime |
webauthn | boolean |
user_metadata | map |
webauthn_devices | array of strings (e.g. "Mac OS X") |
recent_events | array of PassageEvents |
User Device Management
The functionality currently available is:
List all devices for a user
Revoke a particular device from a user
Creating Magic Links
The Ruby SDK can be used to generate custom magic links for users, that can be embedded into any content medium. To learn more, see our full guide on Embedded Magic Links.
Last updated