Class: OmniAuth::Strategies::Trezor

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

Instance Method Summary collapse

Instance Method Details

#callback_phaseObject



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

def callback_phase
  verified = verify_signature(
      extra[:public_key],
      extra[:signature],
      extra[:hidden_challenge],
      extra[:visual_challenge]
  )
  if verified
    super
  else
    fail!(:invalid_credentials)
  end
end

#request_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
51
52
# File 'lib/omniauth/strategies/trezor.rb', line 16

def request_phase
  session['omniauth.trezor_visual_challenge'] = options[:visual_challenge]
  session['omniauth.trezor_hidden_challenge'] = options[:hidden_challenge]

  OmniAuth::Form.build(
    title: "Trezor Login",
    url: callback_path,
    header_info: <<-HTML
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js" type="text/javascript"></script>
      <script src="https://trezor.github.io/connect/login.js"></script>
      <script type='text/javascript'>
        function trezorLogin() {
          TrezorConnect.requestLogin('#{options[:hosticon]}', '#{options[:hidden_challenge]}', '#{options[:visual_challenge]}', function (result) {
              if (result.success) {
                  $('input[name=public_key]').val(result.public_key);
                  $('input[name=signature]').val(result.signature);
                  $('form').submit();
              } else {
                  console.log('Error:', result.error);
              }
          });

        }
        $(function() {
          $('button').click(function() {
            trezorLogin();
            return false;
          });
        });
      </script>
    HTML
  ) do |f|
    f.input_field('hidden', 'public_key')
    f.input_field('hidden', 'signature')
    f.html "<p>Logging in at: #{options[:visual_challenge]}</p>"
  end.to_response
end

#skip_info?Boolean

Returns:

  • (Boolean)


81
82
83
# File 'lib/omniauth/strategies/trezor.rb', line 81

def skip_info?
  true
end