warden-browserid 0.7.7
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +39 -0
- data/Rakefile +2 -0
- data/lib/warden-browserid/config.rb +5 -0
- data/lib/warden-browserid/strategy.rb +41 -0
- data/lib/warden-browserid/version.rb +5 -0
- data/lib/warden-browserid.rb +5 -0
- data/warden-browserid.gemspec +19 -0
- metadata +66 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Runar Ingebrigtsen
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# Warden::BrowserId
|
2
|
+
|
3
|
+
Authenticate your Warden-enabled app using BrowserID from Mozilla
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'warden-browserid'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install warden-browserid
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
I use the warden-browserid strategy with Devise, configured like this in
|
22
|
+
config/initializers/devise.rb in Rails:
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
config.warden do |manager|
|
26
|
+
manager.default_strategies(:scope => :user).unshift :browserid
|
27
|
+
manager.browserid_url = "dev.diresworb.org"
|
28
|
+
end
|
29
|
+
```
|
30
|
+
|
31
|
+
See the devise-browserid gem for client side action.
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
1. Fork it
|
36
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
37
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
38
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
39
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'net/https'
|
2
|
+
|
3
|
+
module Warden
|
4
|
+
module BrowserId
|
5
|
+
#
|
6
|
+
# A Warden Strategy to authenticate with BrowserId from Mozilla
|
7
|
+
#
|
8
|
+
class Strategy < Warden::Strategies::Base
|
9
|
+
def valid?
|
10
|
+
# Not valid when the assertion parameter is missing
|
11
|
+
return false unless params[:assertion]
|
12
|
+
|
13
|
+
# Prepare the HTTP request
|
14
|
+
http = Net::HTTP.new(browserid_url, 443)
|
15
|
+
http.use_ssl = true
|
16
|
+
req = Net::HTTP::Post.new("/verify")
|
17
|
+
req.set_form_data( { assertion: params[:assertion], audience: request.host_with_port } )
|
18
|
+
|
19
|
+
# POST args to verifier and get response
|
20
|
+
response = http.request(req)
|
21
|
+
|
22
|
+
json = JSON.parse response.body
|
23
|
+
@asserted = json
|
24
|
+
|
25
|
+
# Return true if asserted email and audience is right
|
26
|
+
json["status"] == "okay" and json["audience"] == request.host_with_port
|
27
|
+
end
|
28
|
+
|
29
|
+
# Authenticate user if email was verified
|
30
|
+
def authenticate!
|
31
|
+
u = User.find_by_email(@asserted["email"])
|
32
|
+
u.nil? ? fail!("The given email is not registered for this system.") : success!(u)
|
33
|
+
end
|
34
|
+
|
35
|
+
# Select BrowserID verifier instance from options
|
36
|
+
def self.browserid_url
|
37
|
+
request.env['warden'].config.browserid_url || "dev.diresworb.org"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/warden-browserid/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["ringe"]
|
6
|
+
gem.email = ["runar@rin.no"]
|
7
|
+
gem.description = %q{Warden BrowserID strategy}
|
8
|
+
gem.summary = %q{Authenticate your Warden-enabled app using BrowserID from Mozilla}
|
9
|
+
gem.homepage = "http://rin.no"
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "warden-browserid"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Warden::BrowserId::VERSION
|
17
|
+
|
18
|
+
gem.add_dependency "warden"
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: warden-browserid
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.7.7
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- ringe
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-04-13 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: warden
|
16
|
+
requirement: &25390440 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *25390440
|
25
|
+
description: Warden BrowserID strategy
|
26
|
+
email:
|
27
|
+
- runar@rin.no
|
28
|
+
executables: []
|
29
|
+
extensions: []
|
30
|
+
extra_rdoc_files: []
|
31
|
+
files:
|
32
|
+
- .gitignore
|
33
|
+
- Gemfile
|
34
|
+
- LICENSE
|
35
|
+
- README.md
|
36
|
+
- Rakefile
|
37
|
+
- lib/warden-browserid.rb
|
38
|
+
- lib/warden-browserid/config.rb
|
39
|
+
- lib/warden-browserid/strategy.rb
|
40
|
+
- lib/warden-browserid/version.rb
|
41
|
+
- warden-browserid.gemspec
|
42
|
+
homepage: http://rin.no
|
43
|
+
licenses: []
|
44
|
+
post_install_message:
|
45
|
+
rdoc_options: []
|
46
|
+
require_paths:
|
47
|
+
- lib
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ! '>='
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0'
|
60
|
+
requirements: []
|
61
|
+
rubyforge_project:
|
62
|
+
rubygems_version: 1.8.15
|
63
|
+
signing_key:
|
64
|
+
specification_version: 3
|
65
|
+
summary: Authenticate your Warden-enabled app using BrowserID from Mozilla
|
66
|
+
test_files: []
|