Ruby SDK

Rails quickstart

Verify the signed-in user on every request and check a permission before an action.

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.

  1. Add the gem

    Gemfileruby
    gem "scute", git: "https://github.com/scuteai/scute-ruby", branch: "main"

    Run bundle install.

  2. Set the credentials

    .envbash
    SCUTE_APP_ID=app_xxxSCUTE_SECRET=your_app_secret

    Token verification needs only SCUTE_APP_ID. Authorization checks and user management also need SCUTE_SECRET.

  3. Require a session

    app/controllers/application_controller.rbruby
    class ApplicationController < ActionController::Base  include Scute::Authentication  include Scute::Authorization  before_action :scute_authenticate!  rescue_from Scute::Unauthenticated, with: -> { head :unauthorized }end

    scute_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.

  4. Read the user

    app/controllers/me_controller.rbruby
    class MeController < ApplicationController  def show    render json: { user_id: scute_user_id, impersonated: scute_session.impersonated? }  endend

    scute_user_id is the Scute app user id. scute_session is the verified Scute::Session.

  5. Check a permission

    app/controllers/invoices_controller.rbruby
    class 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  endend

    scute_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#