├── .gitignore ├── .rspec ├── Gemfile ├── Guardfile ├── README.md ├── Rakefile ├── examples └── sinatra │ ├── application.rb │ └── config.ru ├── lib ├── omniauth-browserid.rb └── omniauth │ ├── browser_id │ └── version.rb │ └── strategies │ └── browser_id.rb ├── omniauth-browserid.gemspec └── spec ├── omniauth └── strategies │ └── browser_id_spec.rb └── spec_helper.rb /.gitignore: -------------------------------------------------------------------------------- 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 -------------------------------------------------------------------------------- /.rspec: -------------------------------------------------------------------------------- 1 | --colour 2 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 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 -------------------------------------------------------------------------------- /Guardfile: -------------------------------------------------------------------------------- 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 11 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # OmniAuth BrowserID 2 | 3 | Mozilla's [BrowserID](https://login.persona.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 | 31 | 32 |
33 | 34 | 35 |
36 | 37 | 38 | 39 | 58 | 59 | 60 | ``` 61 | 62 | 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. 63 | 64 | ## Options 65 | 66 | These are the options you can specify that are relevant to Omniauth BrowserID: 67 | 68 | * `:verify_url` - The verifier URL (defaults to `https://verifier.login.persona.org/verify`) 69 | * `:name` - The URL at which the strategy will be available (defaults to `browser_id`) 70 | * `: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) 71 | * `:client_options` - Any additional options to send to the Faraday connection. 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. 82 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 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 9 | -------------------------------------------------------------------------------- /examples/sinatra/application.rb: -------------------------------------------------------------------------------- 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 | "Auth with BrowserID" 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 -------------------------------------------------------------------------------- /examples/sinatra/config.ru: -------------------------------------------------------------------------------- 1 | require './application' 2 | 3 | run Sinatra::Application -------------------------------------------------------------------------------- /lib/omniauth-browserid.rb: -------------------------------------------------------------------------------- 1 | require "omniauth/browser_id/version" 2 | require "omniauth/strategies/browser_id" 3 | 4 | OmniAuth.config.add_camelization('browser_id', 'BrowserID') -------------------------------------------------------------------------------- /lib/omniauth/browser_id/version.rb: -------------------------------------------------------------------------------- 1 | module OmniAuth 2 | module BrowserID 3 | VERSION = "0.0.1" 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /lib/omniauth/strategies/browser_id.rb: -------------------------------------------------------------------------------- 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://verifier.login.persona.org/verify' 12 | option :name, 'browser_id' 13 | option :audience_url, nil 14 | option :client_options, {} 15 | 16 | def other_phase 17 | if on_path?(failure_path) 18 | fail!('invalid_credentials') 19 | else 20 | call_app! 21 | end 22 | end 23 | 24 | def failure_path 25 | options[:failure_path] || "#{path_prefix}/failure" 26 | end 27 | 28 | def request_phase 29 | OmniAuth::Form.build( 30 | :title => "BrowserID Login", 31 | :url => callback_path, 32 | :header_info => <<-HTML 33 | 34 | 35 | 54 | HTML 55 | ) do |f| 56 | f.html "

Click 'Connect' to sign in with BrowserID.

" 57 | end.to_response 58 | end 59 | 60 | uid{ raw_info['email'] } 61 | extra{ {:raw_info => raw_info} } 62 | 63 | info do 64 | { 65 | :name => raw_info['email'], 66 | :email => raw_info['email'] 67 | } 68 | end 69 | 70 | def raw_info 71 | response = connection.post('', 72 | :assertion => request.params['assertion'], 73 | :audience => full_host 74 | ) 75 | 76 | MultiJson.decode(response.body) 77 | end 78 | 79 | def connection 80 | Faraday.new(options[:client_options]. 81 | update(:url => options[:verify_url])) 82 | end 83 | end 84 | end 85 | end 86 | -------------------------------------------------------------------------------- /omniauth-browserid.gemspec: -------------------------------------------------------------------------------- 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 26 | -------------------------------------------------------------------------------- /spec/omniauth/strategies/browser_id_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe OmniAuth::Strategies::BrowserID do 4 | 5 | end 6 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 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 13 | --------------------------------------------------------------------------------