class OmniAuth::Strategies::Nightcrawler

Public Instance Methods

callback_phase() click to toggle source
Calls superclass method
# File lib/omniauth/strategies/nightcrawler.rb, line 16
def callback_phase
  code = request.params["code"]

  res = HTTParty.post(token_url,
    body: token_callback_payload(code),
    headers: {'Content-Type' => 'application/json'}
  )

  if res.response.code == "200"
    issuer_pubkey_str = Base64.decode64 options.issuer_pubkey
    issuer_pubkey = OpenSSL::PKey::RSA.new issuer_pubkey_str

    response = JSON.parse(res.body)
    @raw_token = response["access_token"]

    @decoded = JWT.decode(
      @raw_token,
      issuer_pubkey,
      true, # verify sig
      {algorithm: 'RS256'}
    )[0]["data"]

    (options.required_payload_keys || []).each do |field|
      raise JWTPayloadError.new("Missing required '#{field}' info.") if !@decoded.key?(field.to_s)
    end

    super
  else
    raise JWTResponseError
  end
rescue JWTPayloadError => e
  fail! :claim_invalid, e
rescue JWTResponseError => e
  fail! :response_invalid, e
end
request_phase() click to toggle source
# File lib/omniauth/strategies/nightcrawler.rb, line 12
def request_phase
  redirect request_phase_url
end

Private Instance Methods

authorize_url() click to toggle source
# File lib/omniauth/strategies/nightcrawler.rb, line 85
def authorize_url
  "#{options.auth_url_base}/oauth/authorize"
end
callback_url() click to toggle source
# File lib/omniauth/strategies/nightcrawler.rb, line 97
def callback_url
  "#{host_string}/auth/nightcrawler/callback"
end
host_string() click to toggle source
# File lib/omniauth/strategies/nightcrawler.rb, line 105
def host_string
  "#{request.env['rack.url_scheme']}://#{request.host_with_port}"
end
issuer_pubkey() click to toggle source
# File lib/omniauth/strategies/nightcrawler.rb, line 70
def issuer_pubkey
  issuer_pubkey_str = Base64.decode64(options.issuer_pubkey)
  OpenSSL::PKey::RSA.new(issuer_pubkey_str)
end
refresh_url() click to toggle source
# File lib/omniauth/strategies/nightcrawler.rb, line 93
def refresh_url
  "#{options.auth_url_base}/oauth/refresh"
end
request_phase_url() click to toggle source
# File lib/omniauth/strategies/nightcrawler.rb, line 101
def request_phase_url
  "#{authorize_url}?client_id=#{options.app_id}&response_type=code&redirect_uri=#{CGI.escape(callback_url)}"
end
token_callback_payload(code) click to toggle source
# File lib/omniauth/strategies/nightcrawler.rb, line 75
def token_callback_payload(code)
  {
    client_id: options.app_id,
    client_secret: options.app_secret,
    redirect_uri: callback_url,
    grant_type: "authorization_code",
    code: code
  }.to_json
end
token_url() click to toggle source
# File lib/omniauth/strategies/nightcrawler.rb, line 89
def token_url
  "#{options.auth_url_base}/oauth/token"
end