Class: OmniAuth::Strategies::Nightcrawler

Inherits:
Object
  • Object
show all
Includes:
OmniAuth::Strategy
Defined in:
lib/omniauth/strategies/nightcrawler.rb

Defined Under Namespace

Classes: JWTPayloadError, JWTResponseError

Instance Method Summary collapse

Instance Method Details

#callback_phaseObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# 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_phaseObject



12
13
14
# File 'lib/omniauth/strategies/nightcrawler.rb', line 12

def request_phase
  redirect request_phase_url
end