Class: OmniAuth::Strategies::OpenIDConnect

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

Defined Under Namespace

Classes: CallbackError

Instance Method Summary collapse

Instance Method Details

#addressObject



53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/omniauth/strategies/pixelpin.rb', line 53

def address
  if formatted_address["address"].nil?
    address = JSON.parse('{
      "street_address": "",
      "country": "",
      "region": "",
      "locality": "",
      "postal_code": ""
      }')
  else
    address = ActiveSupport::JSON.decode(formatted_address["address"])
  end
end

#authorization_codeObject



148
149
150
# File 'lib/omniauth/strategies/pixelpin.rb', line 148

def authorization_code
  request.params["code"]
end

#authorize_uriObject



152
153
154
155
156
157
158
159
160
161
162
# File 'lib/omniauth/strategies/pixelpin.rb', line 152

def authorize_uri
  client.redirect_uri = client_options.redirect_uri
  opts = {
      response_type: options.response_type,
      scope: options.scope,
      state: new_state,
      nonce: (new_nonce if options.send_nonce),
      hd: options.hd,
  }
  client.authorization_uri(opts.reject{|k,v| v.nil?})
end

#callback_phaseObject



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/omniauth/strategies/pixelpin.rb', line 123

def callback_phase
  error = request.params['error_reason'] || request.params['error']
  if error
    raise CallbackError.new(request.params['error'], request.params['error_description'] || request.params['error_reason'], request.params['error_uri'])
  elsif request.params['state'].to_s.empty? || request.params['state'] != stored_state
    return Rack::Response.new(['401 Unauthorized'], 401).finish
  elsif !request.params["code"]
    return fail!(:missing_code, OmniAuth::OpenIDConnect::MissingCodeError.new(request.params["error"]))
  else
    options.issuer = issuer if options.issuer.blank?
    discover! if options.discovery
    client.redirect_uri = client_options.redirect_uri
    client.authorization_code = authorization_code
    access_token
    super
  end
rescue CallbackError => e
  fail!(:invalid_credentials, e)
rescue ::Timeout::Error, ::Errno::ETIMEDOUT => e
  fail!(:timeout, e)
rescue ::SocketError => e
  fail!(:failed_to_connect, e)
end

#clientObject



105
106
107
# File 'lib/omniauth/strategies/pixelpin.rb', line 105

def client
  @client ||= ::OpenIDConnect::Client.new(client_options)
end

#configObject



109
110
111
112
113
114
115
# File 'lib/omniauth/strategies/pixelpin.rb', line 109

def config
  cache_options = {
    host:client_options.host,
    port:client_options.port
  }
  @config ||= ::OpenIDConnect::Discovery::Provider::Config.discover!(options.issuer, cache_options = [client_options.host, client_options.port])
end

#formatted_addressObject



49
50
51
# File 'lib/omniauth/strategies/pixelpin.rb', line 49

def formatted_address
  formatted_address = HashWithIndifferentAccess.new(.raw_attributes)
end

#public_keyObject



164
165
166
167
168
169
170
# File 'lib/omniauth/strategies/pixelpin.rb', line 164

def public_key
  if options.discovery
    config.jwks
  else
    key_or_secret
  end
end

#request_phaseObject



117
118
119
120
121
# File 'lib/omniauth/strategies/pixelpin.rb', line 117

def request_phase
  options.issuer = issuer if options.issuer.blank?
  discover! if options.discovery
  redirect authorize_uri
end