简体   繁体   中英

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? I receive this error when I try to run the file.

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

Try calling binding.pry before redirect_to

  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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM