Class: Omniauth::Strategies::Gov

Inherits:
OmniAuth::Strategies::OAuth2
  • Object
show all
Defined in:
lib/omniauth/strategies/gov.rb

Instance Method Summary collapse

Instance Method Details

#authorize_paramsObject

rubocop:disable Metrics/AbcSize, Metrics/MethodLength



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/omniauth/strategies/gov.rb', line 59

def authorize_params # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
  options.authorize_params[:state] = SecureRandom.hex(24)
  options.authorize_params[:client_id] = options[:client_id]
  options.authorize_params[:scope] = options[:scope]
  options.authorize_params[:response_type] = 'code'
  options.authorize_params[:nonce] = SecureRandom.hex[0..11]
  params = options.authorize_params
    .merge(options_for("authorize"))
    .merge(pkce_authorize_params)

  session["omniauth.pkce.verifier"] = options.pkce_verifier if options.pkce
  session["omniauth.state"] = params[:state]

  params
end

#build_access_tokenObject



75
76
77
78
79
80
81
82
83
# File 'lib/omniauth/strategies/gov.rb', line 75

def build_access_token
  verifier = request.params["code"]
  
  atoken = client.auth_code.get_token(
    verifier, 
    {"grant_type": "authorization_code", "code": verifier, "redirect_uri": OmniAuth.config.full_host+options.callback_path, "code_verifier": session["omniauth.pkce.verifier"]}, 
    {"Content-Type"  => "application/x-www-form-urlencoded", "Authorization" => "Basic #{Base64.strict_encode64(options.client_id+":"+options.client_secret)}" })
  atoken
end

#clientObject



39
40
41
42
# File 'lib/omniauth/strategies/gov.rb', line 39

def client
  options.client_options.merge!({connection_opts: {request: {params_encoder: GovBr::ParamsEncoder}}})
  ::OAuth2::Client.new(options.client_id, options.client_secret, deep_symbolize(options.client_options))
end

#prune!(hash) ⇒ Object



52
53
54
55
56
57
# File 'lib/omniauth/strategies/gov.rb', line 52

def prune!(hash)
  hash.delete_if do |_, value|
    prune!(value) if value.is_a?(Hash)
    value.nil? || (value.respond_to?(:empty?) && value.empty?)
  end
end

#raw_infoObject



48
49
50
# File 'lib/omniauth/strategies/gov.rb', line 48

def raw_info
  @raw_info ||= JWT.decode(credentials["id_token"], nil, false)[0]
end

#request_phaseObject



44
45
46
# File 'lib/omniauth/strategies/gov.rb', line 44

def request_phase
  redirect client.auth_code.authorize_url({:redirect_uri => callback_url}.merge(authorize_params))
end