Class: OmniAuth::Strategies::Ethereum
- Inherits:
-
Object
- Object
- OmniAuth::Strategies::Ethereum
- Includes:
- OmniAuth::Strategy
- Defined in:
- lib/omniauth-ethereum.rb
Instance Method Summary collapse
Instance Method Details
#callback_phase ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/omniauth-ethereum.rb', line 44 def callback_phase = request.params["eth_message"] unix_time = .scan(/\d+/).last.to_i ten_min = 10 * 60 return fail!(:invalid_time) unless unix_time + ten_min >= now && unix_time - ten_min <= now address = Eth::Address.new request.params["eth_address"] signature = request.params["eth_signature"] signature_pubkey = Eth::Signature.personal_recover , signature signature_address = Eth::Util.public_key_to_address(signature_pubkey) return fail!(:invalid_credentials) unless signature_address.to_s == address.to_s super end |
#request_phase ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/omniauth-ethereum.rb', line 21 def request_phase form = OmniAuth::Form.new :title => "Ethereum Authentication", :url => callback_path form.html("<span class='custom_title'>#{options.custom_title}</span>") .fields.each do |field| # these fields are read-only and will be filled by javascript in the process if field == :eth_message form.html("<input type='hidden' id='eth_message' name='eth_message' value='#{now}' />") else form.html("<input type='hidden' id='#{field.to_s}' name='#{field.to_s}' />") end end # the form button will be heavy on javascript, requesting account, nonce, and signature before submission form. "Sign In" path = File.join(File.dirname(__FILE__), "new_session.js") js = File.read(path) mod = "<script type='module'>\n#{js}\n</script>" form.html(mod) form.to_response end |