[英]Debugging a Standalone Rails Controller
I have a controller called 'Zendesk_session_controller.rb', as the first step in a process of using a JWT. However, I would like to know how to debug this with binding.pry?我有一个名为“Zendesk_session_controller.rb”的 controller,作为使用 JWT 过程的第一步。但是,我想知道如何使用 binding.pry 调试它? I receive this error when I try to run the file.
我在尝试运行该文件时收到此错误。
Process finished with exit code 0
zendesk_session_controller.rb 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
Try calling binding.pry
before redirect_to
尝试在
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.