omniauth-browserid 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ examples/**/tmp
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --colour
data/Gemfile ADDED
@@ -0,0 +1,21 @@
1
+ source 'http://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in omniauth-browserid.gemspec
4
+ gemspec
5
+
6
+ group :development, :test do
7
+ gem 'rspec'
8
+ gem 'rack-test', require: 'rack/test'
9
+
10
+ gem 'guard'
11
+ gem 'guard-rspec'
12
+ gem 'guard-bundler'
13
+ gem 'pry'
14
+
15
+ gem 'rb-fsevent'
16
+ gem 'growl'
17
+ end
18
+
19
+ group :example do
20
+ gem 'sinatra'
21
+ end
@@ -0,0 +1,10 @@
1
+ guard 'rspec', :version => 2 do
2
+ watch(%r{^spec/.+_spec\.rb$})
3
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
4
+ watch('spec/spec_helper.rb') { "spec" }
5
+ end
6
+
7
+ guard 'bundler' do
8
+ watch('Gemfile')
9
+ watch(/^.+\.gemspec/)
10
+ end
@@ -0,0 +1,81 @@
1
+ # OmniAuth BrowserID
2
+
3
+ Mozilla's [BrowserID](https://browserid.org/) is a great implementation of verified email that lets you quickly and easily login to websites. This is an OmniAuth strategy that allows you to use BrowserID in your application!
4
+
5
+ ## Installation
6
+
7
+ gem install omniauth-browserid
8
+
9
+ ## Usage
10
+
11
+ BrowserID works using a Javascript-driven popup window. As such, there is a little more work than usual to integrate BrowserID seamlessly into your app. That being said, a default implementation of BrowserID will work as outlined below.
12
+
13
+ ### Basic Case
14
+
15
+ To use the built-in form in order to authenticate with BrowserID, you simply need to add the strategy to your application:
16
+
17
+ ```ruby
18
+ use OmniAuth::Builder do
19
+ provider :browser_id
20
+ end
21
+ ```
22
+
23
+ Now all you need to do is redirect your users to `/auth/browser_id` and you're all set!
24
+
25
+ ### Better Integration
26
+
27
+ To better integrate BrowserID with your application, you will want to use the BrowserID javascript directly in your app. Assuming you included the middleware as described above, here is a way you could structure your HTML:
28
+
29
+ ```html
30
+ <html>
31
+ <head>
32
+ <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
33
+ <script src="https://browserid.org/include.js" type="text/javascript"></script>
34
+ <script type='text/javascript'>
35
+ function loginViaEmail() {
36
+ navigator.id.getVerifiedEmail(function(assertion) {
37
+ if (assertion) {
38
+ $('input[name=assertion]').val(assertion);
39
+ $('#browser_id_form').submit();
40
+ } else {
41
+ window.location = "#{failure_path}"
42
+ }
43
+ });
44
+ }
45
+
46
+ $(function() {
47
+ $('#browser_id_form button').click(function() {
48
+ loginViaEmail();
49
+ return false;
50
+ });
51
+ });
52
+ </script>
53
+ </head>
54
+ <body>
55
+ <form id='browser_id_form' action='/auth/browser_id/callback'>
56
+ <input type='hidden' name='assertion'/>
57
+ <button type='submit'>Login with BrowserID</button>
58
+ </form>
59
+ </body>
60
+ </html>
61
+ ```
62
+
63
+ What this does is sets up a form with a "Login with BrowserID" button. When the button of the form is clicked, it is intercepted by jQuery and the BrowserID flow is started. BrowserID returns an `assertion` that is then used to verify an email. In this example, the form points to `/auth/browser_id/callback` which will automatically perform verification as well as return a standard OmniAuth hash.
64
+
65
+ ## Options
66
+
67
+ These are the options you can specify that are relevant to Omniauth BrowserID:
68
+
69
+ * `:verify_url` - The verifier URL (defaults to `https://browserid.org/verify`)
70
+ * `:name` - The URL at which the strategy will be available (defaults to `browser_id`)
71
+ * `:audience_url` - The host of your site. Defaults to the `full_host` of OmniAuth (either automatically determined or determined by the `OmniAuth.config.full_host` option)
72
+
73
+ ## License
74
+
75
+ Copyright (c) 2011 Michael Bleigh and Intridea, Inc.
76
+
77
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
78
+
79
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
80
+
81
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require "rspec/core/rake_task"
4
+
5
+ desc "Run the rake tasks."
6
+ RSpec::Core::RakeTask.new
7
+
8
+ task :default => :spec
@@ -0,0 +1,21 @@
1
+ $:.push File.dirname(__FILE__) + '/../lib'
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ Bundler.setup :default, :development, :example, ENV['RACK_ENV']
6
+
7
+ require 'sinatra'
8
+ require 'omniauth-browserid'
9
+ require 'pry'
10
+
11
+ use Rack::Session::Cookie
12
+ use OmniAuth::Strategies::BrowserID
13
+
14
+ get '/' do
15
+ "<a href='/auth/browser_id'>Auth with BrowserID</a>"
16
+ end
17
+
18
+ post '/auth/browser_id/callback' do
19
+ content_type 'text/plain'
20
+ request.env['omniauth.auth'].to_hash.inspect
21
+ end
@@ -0,0 +1,3 @@
1
+ require './application'
2
+
3
+ run Sinatra::Application
@@ -0,0 +1,4 @@
1
+ require "omniauth/browser_id/version"
2
+ require "omniauth/strategies/browser_id"
3
+
4
+ OmniAuth.config.add_camelization('browser_id', 'BrowserID')
@@ -0,0 +1,5 @@
1
+ module OmniAuth
2
+ module BrowserID
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,83 @@
1
+ require 'omniauth'
2
+ require 'omniauth-browserid'
3
+ require 'faraday'
4
+ require 'multi_json'
5
+
6
+ module OmniAuth
7
+ module Strategies
8
+ class BrowserID
9
+ include OmniAuth::Strategy
10
+
11
+ option :verify_url, 'https://browserid.org/verify'
12
+ option :name, 'browser_id'
13
+ option :audience_url, nil
14
+
15
+ def other_phase
16
+ if on_path?(failure_path)
17
+ fail!('invalid_credentials')
18
+ else
19
+ call_app!
20
+ end
21
+ end
22
+
23
+ def failure_path
24
+ options[:failure_path] || "#{path_prefix}/failure"
25
+ end
26
+
27
+ def request_phase
28
+ OmniAuth::Form.build(
29
+ :title => "BrowserID Login",
30
+ :url => callback_path,
31
+ :header_info => <<-HTML
32
+ <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
33
+ <script src="https://browserid.org/include.js" type="text/javascript"></script>
34
+ <script type='text/javascript'>
35
+ function loginViaEmail() {
36
+ navigator.id.getVerifiedEmail(function(assertion) {
37
+ if (assertion) {
38
+ $('input[name=assertion]').val(assertion);
39
+ $('form').submit();
40
+ } else {
41
+ window.location = "#{failure_path}"
42
+ }
43
+ });
44
+ }
45
+
46
+ $(function() {
47
+ $('button').click(function() {
48
+ loginViaEmail();
49
+ return false;
50
+ });
51
+ });
52
+ </script>
53
+ HTML
54
+ ) do |f|
55
+ f.html "<input type='hidden' name='assertion'/><p>Click 'Connect' to sign in with BrowserID.</p>"
56
+ end.to_response
57
+ end
58
+
59
+ uid{ raw_info['email'] }
60
+ extra{ {:raw_info => raw_info} }
61
+
62
+ info do
63
+ {
64
+ :name => raw_info['email'],
65
+ :email => raw_info['email']
66
+ }
67
+ end
68
+
69
+ def raw_info
70
+ response = connection.post('',
71
+ :assertion => request.params['assertion'],
72
+ :audience => full_host
73
+ )
74
+
75
+ MultiJson.decode(response.body)
76
+ end
77
+
78
+ def connection
79
+ resp = Faraday.new(:url => options[:verify_url])
80
+ end
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/omniauth/browser_id/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Michael Bleigh"]
6
+ gem.email = ["michael@intridea.com"]
7
+ gem.description = %q{An OmniAuth strategy for implementing BrowserID}
8
+ gem.summary = %q{An OmniAuth strategy for implementing BrowserID}
9
+ gem.homepage = "https://github.com/intridea/omniauth-browserid"
10
+
11
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
12
+ gem.files = `git ls-files`.split("\n")
13
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
+ gem.name = "omniauth-browserid"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = OmniAuth::BrowserID::VERSION
17
+
18
+ gem.add_dependency "omniauth", "~> 1.0"
19
+ gem.add_dependency "faraday"
20
+ gem.add_dependency "multi_json"
21
+
22
+ gem.add_development_dependency "rake"
23
+ gem.add_development_dependency "rspec", "~> 2.7"
24
+ gem.add_development_dependency "rack-test"
25
+ end
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+
3
+ describe OmniAuth::Strategies::BrowserID do
4
+
5
+ end
@@ -0,0 +1,12 @@
1
+ $:.unshift(__FILE__ + '/../lib')
2
+
3
+ require 'bundler'
4
+ Bundler.setup :default, :test
5
+
6
+ require 'rspec'
7
+ require 'rack/test'
8
+ require 'omniauth-browserid'
9
+
10
+ RSpec.configure do |config|
11
+ config.include Rack::Test::Methods
12
+ end
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-browserid
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Michael Bleigh
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-12-19 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: omniauth
16
+ requirement: &70298575772080 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70298575772080
25
+ - !ruby/object:Gem::Dependency
26
+ name: faraday
27
+ requirement: &70298575771120 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70298575771120
36
+ - !ruby/object:Gem::Dependency
37
+ name: multi_json
38
+ requirement: &70298575770660 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *70298575770660
47
+ - !ruby/object:Gem::Dependency
48
+ name: rake
49
+ requirement: &70298575770240 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70298575770240
58
+ - !ruby/object:Gem::Dependency
59
+ name: rspec
60
+ requirement: &70298575769640 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ~>
64
+ - !ruby/object:Gem::Version
65
+ version: '2.7'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *70298575769640
69
+ - !ruby/object:Gem::Dependency
70
+ name: rack-test
71
+ requirement: &70298575769160 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *70298575769160
80
+ description: An OmniAuth strategy for implementing BrowserID
81
+ email:
82
+ - michael@intridea.com
83
+ executables: []
84
+ extensions: []
85
+ extra_rdoc_files: []
86
+ files:
87
+ - .gitignore
88
+ - .rspec
89
+ - Gemfile
90
+ - Guardfile
91
+ - README.md
92
+ - Rakefile
93
+ - examples/sinatra/application.rb
94
+ - examples/sinatra/config.ru
95
+ - lib/omniauth-browserid.rb
96
+ - lib/omniauth/browser_id/version.rb
97
+ - lib/omniauth/strategies/browser_id.rb
98
+ - omniauth-browserid.gemspec
99
+ - spec/omniauth/strategies/browser_id_spec.rb
100
+ - spec/spec_helper.rb
101
+ homepage: https://github.com/intridea/omniauth-browserid
102
+ licenses: []
103
+ post_install_message:
104
+ rdoc_options: []
105
+ require_paths:
106
+ - lib
107
+ required_ruby_version: !ruby/object:Gem::Requirement
108
+ none: false
109
+ requirements:
110
+ - - ! '>='
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ none: false
115
+ requirements:
116
+ - - ! '>='
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ requirements: []
120
+ rubyforge_project:
121
+ rubygems_version: 1.8.10
122
+ signing_key:
123
+ specification_version: 3
124
+ summary: An OmniAuth strategy for implementing BrowserID
125
+ test_files:
126
+ - spec/omniauth/strategies/browser_id_spec.rb
127
+ - spec/spec_helper.rb