[英]Debugging a Standalone Rails Controller
我有一個名為“Zendesk_session_controller.rb”的 controller,作為使用 JWT 過程的第一步。但是,我想知道如何使用 binding.pry 調試它? 我在嘗試運行該文件時收到此錯誤。
Process finished with exit code 0
zendesk_session_controller.rb
require 'securerandom' unless defined?(SecureRandom)
class ZendeskSessionController
# Configuration
ZENDESK_SHARED_SECRET = ENV['ZENDESK_SHARED_SECRET']
ZENDESK_SUBDOMAIN = ENV['ZENDESK_SUBDOMAIN']
def create
if user = User.authenticate(params[:login], params[:password])
# If the submitted credentials pass, then log user into Zendesk
sign_into_zendesk(user)
else
render :new, notice: 'Cannot find user with that username or passowrd.'
end
end
private
def sign_into_zendesk(user)
iat = Time.now.to_i
jti = "#{iat}/#{SecureRandom.hex(18)}"
payload = JWT.encode({
iat: iat, # Seconds since epoch, determine when this token is stale
jti: jti, # Unique token id, helps prevent replay attacks
name: user.name,
email: user.email
}, ZENDESK_SHARED_SECRET)
redirect_to zendesk_sso_url(payload)
end
def zendesk_sso_url(payload)
url = "https://#{ZENDESK_SUBDOMAIN}.zendesk.com/access/jwt?jwt=#{payload}"
url += '&' + { return_to: params['return_to'] }.to_query if params['return_to'].present?
url
binding.pry
end
end
嘗試在redirect_to
之前調用binding.pry
def sign_into_zendesk(user)
iat = Time.now.to_i
jti = "#{iat}/#{SecureRandom.hex(18)}"
payload = JWT.encode({
iat: iat, # Seconds since epoch, determine when this token is stale
jti: jti, # Unique token id, helps prevent replay attacks
name: user.name,
email: user.email
}, ZENDESK_SHARED_SECRET)
binding.pry
redirect_to zendesk_sso_url(payload)
end
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.