Class: OmniAuth::Strategies::BrowserID

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

Instance Method Summary collapse

Instance Method Details

#connectionObject



78
79
80
# File 'lib/omniauth/strategies/browser_id.rb', line 78

def connection
  resp = Faraday.new(:url => options[:verify_url])
end

#failure_pathObject



23
24
25
# File 'lib/omniauth/strategies/browser_id.rb', line 23

def failure_path
  options[:failure_path] || "#{path_prefix}/failure"
end

#other_phaseObject



15
16
17
18
19
20
21
# File 'lib/omniauth/strategies/browser_id.rb', line 15

def other_phase
  if on_path?(failure_path)
    fail!('invalid_credentials')
  else
    call_app!
  end
end

#raw_infoObject



69
70
71
72
73
74
75
76
# File 'lib/omniauth/strategies/browser_id.rb', line 69

def raw_info
  response = connection.post('', 
    :assertion => request.params['assertion'],
    :audience => full_host
  )

  MultiJson.decode(response.body)
end

#request_phaseObject



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
53
54
55
56
57
# File 'lib/omniauth/strategies/browser_id.rb', line 27

def request_phase
  OmniAuth::Form.build(
    :title => "BrowserID Login",
    :url => callback_path,
    :header_info => <<-HTML
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
      <script src="https://browserid.org/include.js" type="text/javascript"></script>
      <script type='text/javascript'>
        function loginViaEmail() {
          navigator.id.getVerifiedEmail(function(assertion) {
            if (assertion) {
              $('input[name=assertion]').val(assertion);
              $('form').submit();
            } else {
              window.location = "#{failure_path}"
            }
          });  
        }

        $(function() {
          $('button').click(function() {
            loginViaEmail();
            return false;
          });
        });
      </script>
    HTML
  ) do |f|
    f.html "<input type='hidden' name='assertion'/><p>Click 'Connect' to sign in with BrowserID.</p>"
  end.to_response
end