Your frontend signs people in with a Scute SDK and sends the access token to your Rails app. The app verifies the token locally and asks Scute's engine before sensitive actions.
Add the gem
Gemfilerubygem "scute", git: "https://github.com/scuteai/scute-ruby", branch: "main"Run bundle install.
Set the credentials
.envbashSCUTE_APP_ID=app_xxxSCUTE_SECRET=your_app_secretToken verification needs only SCUTE_APP_ID. Authorization checks and user management also need SCUTE_SECRET.
Require a session
app/controllers/application_controller.rbrubyclass ApplicationController < ActionController::Base include Scute::Authentication include Scute::Authorization before_action :scute_authenticate! rescue_from Scute::Unauthenticated, with: -> { head :unauthorized }endscute_authenticate! reads the token from X-Authorization, then Authorization: Bearer, then the browser SDK's cookie sc-access-token__<app id>. A missing or invalid token raises Scute::Unauthenticated.
Read the user
app/controllers/me_controller.rbrubyclass MeController < ApplicationController def show render json: { user_id: scute_user_id, impersonated: scute_session.impersonated? } endendscute_user_id is the Scute app user id. scute_session is the verified Scute::Session.
Check a permission
app/controllers/invoices_controller.rbrubyclass InvoicesController < ApplicationController rescue_from Scute::Forbidden do |e| render json: { error: e.message, decision: e.decision.decision }, status: :forbidden end def refund scute_authorize!("refund", "invoice:#{params[:id]}", challenge: params[:challenge]) # refund the invoice head :no_content endendscute_authorize! asks Scute as the signed-in user and raises Scute::Forbidden unless the answer is a plain allow. e.decision tells you why: step_up?, needs_approval? or denied?.
Next#
- Handle step_up? with Step-up and needs_approval? with Access requests.
- Pass the person's IP address to Scute on every request with Scute::ClientIP::Middleware.
- All helpers the concerns add are on Rails integration.