A check answers allow_with_step_up when the permission requires the user to verify first. Start a challenge bound to the permission, let the user complete it, then check again with challenge:.
decision = scute.authz.check(user_id: user_id, action: "refund", resource: "invoice:INV-2")if decision.step_up? decision.step_up # { "method" => "email_otp", "authorizes_action" => "invoice:refund" } challenge = scute.authz.start_step_up(user_id: user_id, decision: decision) # send challenge["token"] to the frontend; the user enters the code thereend# after the user completed itdecision = scute.authz.check(user_id: user_id, action: "refund", resource: "invoice:INV-2", challenge: challenge_token)decision.allowed? # true, reason "verified"start_step_up#
start_step_up(user_id:, decision: nil, permission: nil, method: nil) calls POST /v1/auth/:app_id/challenges with purpose: "step_up" and returns the challenge Hash (its token is what you pass to check as challenge:).
Without a permission or a method, start_step_up raises ArgumentError before any call.
The Ruby SDK has no method to submit the user's code. The user completes the challenge from your frontend with a Scute client SDK (see JavaScript SDK) or the Scute API.
In a controller#
Pass the completed challenge to scute_authorize!:
def refund scute_authorize!("refund", "invoice:#{params[:id]}", challenge: params[:challenge]) # ...endWhen no challenge is passed, Scute::Forbidden is raised with e.decision.step_up? true. Answer the frontend with what it needs to start the step-up:
rescue_from Scute::Forbidden do |e| if e.decision.step_up? challenge = scute_client.authz.start_step_up(user_id: scute_user_id, decision: e.decision) render json: { step_up: challenge }, status: :forbidden else render json: { error: e.message }, status: :forbidden endendClient IP#
A step-up is a sign-in your server starts. Pass the user's IP address so Scute checks it against the workspace's IP rules. scute_client in the concerns does this. Elsewhere:
scute.with_client_ip(request.remote_ip).authz.start_step_up(user_id: id, decision: decision, method: "email_otp")