omniauth-browserid-discourse 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a192b0f0a84747f2aac9223591cd659e242bdf0c
4
+ data.tar.gz: ac1d1012d8be61a16a134d4dbc500c96a851144d
5
+ SHA512:
6
+ metadata.gz: ed1050e244d25e77eae7b2e61bf7ecee46408b4f618096541fb826ba55890161a9bff45498f854fa08e6130f8789b8ec1e4bd561e12e3d9d1d3395ef2935ea1c
7
+ data.tar.gz: 78aa60dde1c42b1d9a6488a226dca7982d98fa38793f3b5354d4c7a8c3623f640cad050c1447f826850a8343270d9ed51b55a46284f63282b86dae9c77a83024
@@ -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,80 @@
1
+ # OmniAuth BrowserID
2
+
3
+ Mozilla [Persona](https://login.persona.org/), formerly known as BrowserID, 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 Persona in your application!
4
+
5
+ ## Installation
6
+
7
+ gem install omniauth-browserid
8
+
9
+ ## Usage
10
+
11
+ Persona works using a Javascript-driven popup window. As such, there is a little more work than usual to integrate it seamlessly into your app. That being said, a default implementation of Persona will work as outlined below.
12
+
13
+ ### Basic Case
14
+
15
+ To use the built-in form in order to authenticate with Persona, 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 Persona with your application, you will want to use the Persona 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
+ <body>
32
+ <form id='browser_id_form' action='/auth/browser_id/callback'>
33
+ <input type='hidden' name='assertion'/>
34
+ <button type='submit'>Login with Persona</button>
35
+ </form>
36
+
37
+ <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
38
+ <script src="https://login.persona.org/include.js" type="text/javascript"></script>
39
+ <script type='text/javascript'>
40
+ function loginViaEmail() {
41
+ navigator.id.get(function(assertion) {
42
+ if (assertion) {
43
+ $('input[name=assertion]').val(assertion);
44
+ $('#browser_id_form').submit();
45
+ } else {
46
+ window.location = "#{failure_path}"
47
+ }
48
+ });
49
+ }
50
+
51
+ $(function() {
52
+ $('#browser_id_form button').click(function() {
53
+ loginViaEmail();
54
+ return false;
55
+ });
56
+ });
57
+ </script>
58
+ </body>
59
+ </html>
60
+ ```
61
+
62
+ What this does is sets up a form with a "Login with Persona" button. When the button of the form is clicked, it is intercepted by jQuery and the Persona flow is started. Persona 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
+
72
+ ## License
73
+
74
+ Copyright (c) 2011 Michael Bleigh and Intridea, Inc.
75
+
76
+ 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:
77
+
78
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
79
+
80
+ 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.2"
4
+ end
5
+ end
@@ -0,0 +1,94 @@
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
+
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 => "Persona 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://login.persona.org/include.js" type="text/javascript"></script>
34
+ <script type='text/javascript'>
35
+ (function() {
36
+ var onreadyCalled = false;
37
+
38
+ navigator.id.watch({
39
+ onlogin: function(assertion) {
40
+ if (onreadyCalled) {
41
+ if (assertion) {
42
+ $('input[name=assertion]').val(assertion);
43
+ $('form').submit();
44
+ } else {
45
+ window.location = "#{failure_path}"
46
+ }
47
+ }
48
+ },
49
+ onlogout: function() {
50
+ },
51
+ onready: function() {
52
+ onreadyCalled = true;
53
+ }
54
+ });
55
+
56
+ $(function() {
57
+ $('button').click(function() {
58
+ navigator.id.request();
59
+ return false;
60
+ });
61
+ });
62
+ }())
63
+ </script>
64
+ HTML
65
+ ) do |f|
66
+ f.html "<input type='hidden' name='assertion'/><p>Click 'Connect' to sign in with Persona.</p>"
67
+ end.to_response
68
+ end
69
+
70
+ uid{ raw_info['email'] }
71
+ extra{ {:raw_info => raw_info} }
72
+
73
+ info do
74
+ {
75
+ :name => raw_info['email'],
76
+ :email => raw_info['email']
77
+ }
78
+ end
79
+
80
+ def raw_info
81
+ response = connection.post('',
82
+ :assertion => request.params['assertion'],
83
+ :audience => full_host
84
+ )
85
+
86
+ MultiJson.decode(response.body)
87
+ end
88
+
89
+ def connection
90
+ resp = Faraday.new(:url => options[:verify_url])
91
+ end
92
+ end
93
+ end
94
+ 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-discourse"
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,141 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-browserid-discourse
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Michael Bleigh
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-12-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: omniauth
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: multi_json
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: '2.7'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: '2.7'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rack-test
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: An OmniAuth strategy for implementing BrowserID
98
+ email:
99
+ - michael@intridea.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - .gitignore
105
+ - .rspec
106
+ - Gemfile
107
+ - Guardfile
108
+ - README.md
109
+ - Rakefile
110
+ - examples/sinatra/application.rb
111
+ - examples/sinatra/config.ru
112
+ - lib/omniauth-browserid.rb
113
+ - lib/omniauth/browser_id/version.rb
114
+ - lib/omniauth/strategies/browser_id.rb
115
+ - omniauth-browserid.gemspec
116
+ - spec/omniauth/strategies/browser_id_spec.rb
117
+ - spec/spec_helper.rb
118
+ homepage: https://github.com/intridea/omniauth-browserid
119
+ licenses: []
120
+ metadata: {}
121
+ post_install_message:
122
+ rdoc_options: []
123
+ require_paths:
124
+ - lib
125
+ required_ruby_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - '>='
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ required_rubygems_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - '>='
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ requirements: []
136
+ rubyforge_project:
137
+ rubygems_version: 2.0.14
138
+ signing_key:
139
+ specification_version: 4
140
+ summary: An OmniAuth strategy for implementing BrowserID
141
+ test_files: []