omniauth-persona 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -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-persona.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
data/Guardfile ADDED
@@ -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
data/README.md ADDED
@@ -0,0 +1,94 @@
1
+ # OmniAuth Persona
2
+
3
+ This is a fork of https://github.com/intridea/omniauth-browserid, by
4
+ Michael Bleigh
5
+
6
+ Mozilla's [Persona](https://persona.org/) is a great implementation of
7
+ verified email that lets you quickly and easily login to websites. This
8
+ is an OmniAuth strategy that allows you to use Persona in your application!
9
+
10
+ ## Installation
11
+
12
+ gem install omniauth-persona
13
+
14
+ ## Usage
15
+
16
+ Persona works using a Javascript-driven popup window. As such, there is
17
+ a little more work than usual to integrate Persona seamlessly into your
18
+ app. That being said, a default implementation of Persona will work as outlined below.
19
+
20
+ ### Basic Case
21
+
22
+ To use the built-in form in order to authenticate with Persona, you simply need to add the strategy to your application:
23
+
24
+ ```ruby
25
+ use OmniAuth::Builder do
26
+ provider :persona
27
+ end
28
+ ```
29
+
30
+ Now all you need to do is redirect your users to `/auth/persona` and you're all set!
31
+
32
+ ### Better Integration
33
+
34
+ To better integrate Persona with your application, you will want to use
35
+ the Persona javascript directly in your app. Assuming you included the middleware as described above, here is a way you could structure your HTML:
36
+
37
+ ```html
38
+ <html>
39
+ <head>
40
+ <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js" type="text/javascript"></script>
41
+ <script src="https://login.persona.org/include.js" type="text/javascript"></script>
42
+ <script type='text/javascript'>
43
+ function loginViaEmail() {
44
+ navigator.id.get(function(assertion) {
45
+ if (assertion) {
46
+ $('input[name=assertion]').val(assertion);
47
+ $('form').submit();
48
+ } else {
49
+ window.location = "#{failure_path}"
50
+ }
51
+ });
52
+ }
53
+
54
+ $(function() {
55
+ $('button').click(function() {
56
+ loginViaEmail();
57
+ return false;
58
+ });
59
+ });
60
+ </script>
61
+ </head>
62
+ <body>
63
+ <form id='persona_form' action='/auth/persona/callback'>
64
+ <input type='hidden' name='assertion'/>
65
+ <button type='submit'>Login with Persona</button>
66
+ </form>
67
+ </body>
68
+ </html>
69
+ ```
70
+
71
+ What this does is sets up a form with a "Login with Persona" button.
72
+ When the button of the form is clicked, it is intercepted by jQuery and
73
+ the Persona flow is started. Persona returns an `assertion` that is then
74
+ used to verify an email. In this example, the form points to
75
+ `/auth/persona/callback` which will automatically perform verification as well as return a standard OmniAuth hash.
76
+
77
+ ## Options
78
+
79
+ These are the options you can specify that are relevant to Omniauth
80
+ Persona:
81
+
82
+ * `:verify_url` - The verifier URL (defaults to `https://login.persona.org/verify`)
83
+ * `:name` - The URL at which the strategy will be available (defaults to `persona`)
84
+ * `: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)
85
+
86
+ ## License
87
+
88
+ Copyright (c) 2011 Michael Bleigh and Intridea, Inc.
89
+
90
+ 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:
91
+
92
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
93
+
94
+ 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.
data/Rakefile ADDED
@@ -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-persona'
9
+ require 'pry'
10
+
11
+ use Rack::Session::Cookie
12
+ use OmniAuth::Strategies::Persona
13
+
14
+ get '/' do
15
+ "<a href='/auth/persona'>Auth with Persona</a>"
16
+ end
17
+
18
+ post '/auth/persona/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,2 @@
1
+ require "omniauth/persona/version"
2
+ require "omniauth/strategies/persona"
@@ -0,0 +1,5 @@
1
+ module OmniAuth
2
+ module Persona
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,83 @@
1
+ require 'omniauth'
2
+ require 'omniauth-persona'
3
+ require 'faraday'
4
+ require 'multi_json'
5
+
6
+ module OmniAuth
7
+ module Strategies
8
+ class Persona
9
+ include OmniAuth::Strategy
10
+
11
+ option :verify_url, 'https://verifier.login.persona.org/verify'
12
+ option :name, 'persona'
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.8.3/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 loginViaEmail() {
36
+ navigator.id.get(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 Persona.</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
+ 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/persona/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Michael Bleigh", "Patrick Klingemann"]
6
+ gem.email = ["patrick.klingemann@gmail.com"]
7
+ gem.description = %q{An OmniAuth strategy for implementing Persona}
8
+ gem.summary = %q{An OmniAuth strategy for implementing Persona}
9
+ gem.homepage = "https://github.com/pklingem/omniauth-persona"
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-persona"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = OmniAuth::Persona::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::Persona 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-persona'
9
+
10
+ RSpec.configure do |config|
11
+ config.include Rack::Test::Methods
12
+ end
metadata ADDED
@@ -0,0 +1,158 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-persona
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Michael Bleigh
9
+ - Patrick Klingemann
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2013-01-01 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: omniauth
17
+ requirement: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ~>
21
+ - !ruby/object:Gem::Version
22
+ version: '1.0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ~>
29
+ - !ruby/object:Gem::Version
30
+ version: '1.0'
31
+ - !ruby/object:Gem::Dependency
32
+ name: faraday
33
+ requirement: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ! '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ type: :runtime
40
+ prerelease: false
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: multi_json
49
+ requirement: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ - !ruby/object:Gem::Dependency
64
+ name: rake
65
+ requirement: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ type: :development
72
+ prerelease: false
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ - !ruby/object:Gem::Dependency
80
+ name: rspec
81
+ requirement: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ~>
85
+ - !ruby/object:Gem::Version
86
+ version: '2.7'
87
+ type: :development
88
+ prerelease: false
89
+ version_requirements: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ~>
93
+ - !ruby/object:Gem::Version
94
+ version: '2.7'
95
+ - !ruby/object:Gem::Dependency
96
+ name: rack-test
97
+ requirement: !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ! '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ type: :development
104
+ prerelease: false
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: An OmniAuth strategy for implementing Persona
112
+ email:
113
+ - patrick.klingemann@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - .gitignore
119
+ - .rspec
120
+ - Gemfile
121
+ - Guardfile
122
+ - README.md
123
+ - Rakefile
124
+ - examples/sinatra/application.rb
125
+ - examples/sinatra/config.ru
126
+ - lib/omniauth-persona.rb
127
+ - lib/omniauth/persona/version.rb
128
+ - lib/omniauth/strategies/persona.rb
129
+ - omniauth-persona.gemspec
130
+ - spec/omniauth/strategies/persona_spec.rb
131
+ - spec/spec_helper.rb
132
+ homepage: https://github.com/pklingem/omniauth-persona
133
+ licenses: []
134
+ post_install_message:
135
+ rdoc_options: []
136
+ require_paths:
137
+ - lib
138
+ required_ruby_version: !ruby/object:Gem::Requirement
139
+ none: false
140
+ requirements:
141
+ - - ! '>='
142
+ - !ruby/object:Gem::Version
143
+ version: '0'
144
+ required_rubygems_version: !ruby/object:Gem::Requirement
145
+ none: false
146
+ requirements:
147
+ - - ! '>='
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ requirements: []
151
+ rubyforge_project:
152
+ rubygems_version: 1.8.24
153
+ signing_key:
154
+ specification_version: 3
155
+ summary: An OmniAuth strategy for implementing Persona
156
+ test_files:
157
+ - spec/omniauth/strategies/persona_spec.rb
158
+ - spec/spec_helper.rb