class OmniAuth::Strategies::OpenIDConnect
Public Instance Methods
address()
click to toggle source
# 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
callback_phase()
click to toggle source
Calls superclass method
# 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
client()
click to toggle source
# File lib/omniauth/strategies/pixelpin.rb, line 105 def client @client ||= ::OpenIDConnect::Client.new(client_options) end
config()
click to toggle source
# 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_address()
click to toggle source
# File lib/omniauth/strategies/pixelpin.rb, line 49 def formatted_address formatted_address = HashWithIndifferentAccess.new(user_info.raw_attributes) end
public_key()
click to toggle source
# File lib/omniauth/strategies/pixelpin.rb, line 164 def public_key if options.discovery config.jwks else key_or_secret end end
request_phase()
click to toggle source
# 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
user_info()
click to toggle source
# File lib/omniauth/strategies/pixelpin.rb, line 86 def user_info address = JSON.parse(user_info.address) end
Private Instance Methods
access_token()
click to toggle source
# File lib/omniauth/strategies/pixelpin.rb, line 190 def access_token @access_token ||= lambda { _access_token = client.access_token!( scope: (options.scope if options.send_scope_to_token_endpoint), client_auth_method: options.client_auth_method ) _id_token = decode_id_token _access_token.id_token _id_token.verify!( issuer: options.issuer, client_id: client_options.identifier, nonce: stored_nonce ) _access_token }.call() end
client_options()
click to toggle source
# File lib/omniauth/strategies/pixelpin.rb, line 211 def client_options options.client_options end
decode(str)
click to toggle source
# File lib/omniauth/strategies/pixelpin.rb, line 263 def decode(str) UrlSafeBase64.decode64(str).unpack('B*').first.to_i(2).to_s end
decode_id_token(id_token)
click to toggle source
# File lib/omniauth/strategies/pixelpin.rb, line 206 def decode_id_token(id_token) ::OpenIDConnect::ResponseObject::IdToken.decode(id_token, public_key) end
discover!()
click to toggle source
# File lib/omniauth/strategies/pixelpin.rb, line 179 def discover! client_options.authorization_endpoint = config.authorization_endpoint client_options.token_endpoint = config.token_endpoint client_options.userinfo_endpoint = config.userinfo_endpoint client_options.jwks_uri = config.jwks_uri end
issuer()
click to toggle source
# File lib/omniauth/strategies/pixelpin.rb, line 174 def issuer resource = "#{client_options.scheme}://#{client_options.host}" + ((client_options.port) ? ":#{client_options.port.to_s}" : '') ::OpenIDConnect::Discovery::Provider.discover!(resource).issuer end
key_or_secret()
click to toggle source
# File lib/omniauth/strategies/pixelpin.rb, line 236 def key_or_secret case options.client_signing_alg when :HS256, :HS384, :HS512 return client_options.secret when :RS256, :RS384, :RS512 if options.client_jwk_signing_key return parse_jwk_key(options.client_jwk_signing_key) elsif options.client_x509_signing_key return parse_x509_key(options.client_x509_signing_key) end else end end
new_nonce()
click to toggle source
# File lib/omniauth/strategies/pixelpin.rb, line 224 def new_nonce session['omniauth.nonce'] = SecureRandom.hex(16) end
new_state()
click to toggle source
# File lib/omniauth/strategies/pixelpin.rb, line 215 def new_state state = options.state.call if options.state.respond_to? :call session['omniauth.state'] = state || SecureRandom.hex(16) end
parse_jwk_key(key)
click to toggle source
# File lib/omniauth/strategies/pixelpin.rb, line 254 def parse_jwk_key(key) json = JSON.parse(key) if json.has_key?('keys') JSON::JWK::Set.new json['keys'] else JSON::JWK.new json end end
parse_x509_key(key)
click to toggle source
# File lib/omniauth/strategies/pixelpin.rb, line 250 def parse_x509_key(key) OpenSSL::X509::Certificate.new(key).public_key end
session()
click to toggle source
Calls superclass method
# File lib/omniauth/strategies/pixelpin.rb, line 232 def session @env.nil? ? {} : super end
stored_nonce()
click to toggle source
# File lib/omniauth/strategies/pixelpin.rb, line 228 def stored_nonce session.delete('omniauth.nonce') end
stored_state()
click to toggle source
# File lib/omniauth/strategies/pixelpin.rb, line 220 def stored_state session.delete('omniauth.state') end