omniauth-droom 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +8 -0
- data/Gemfile +2 -0
- data/README.md +14 -0
- data/Rakefile +8 -0
- data/example/Gemfile +4 -0
- data/example/Gemfile.lock +45 -0
- data/example/config.ru +115 -0
- data/lib/omniauth-droom.rb +1 -0
- data/lib/omniauth/droom.rb +2 -0
- data/lib/omniauth/droom/version.rb +5 -0
- data/lib/omniauth/strategies/droom.rb +44 -0
- data/omniauth-droom.gemspec +25 -0
- metadata +123 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# OmniAuth Droom
|
2
|
+
|
3
|
+
OAuth2 Strategy for OmniAuth 1.0 and the data room
|
4
|
+
|
5
|
+
|
6
|
+
## License
|
7
|
+
|
8
|
+
Copyright (c) 2013 by William Ross for Spanner Ltd
|
9
|
+
|
10
|
+
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:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
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
data/example/Gemfile
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
PATH
|
2
|
+
remote: ../
|
3
|
+
specs:
|
4
|
+
omniauth-facebook (1.4.1)
|
5
|
+
omniauth-oauth2 (~> 1.1.0)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: http://rubygems.org/
|
9
|
+
specs:
|
10
|
+
faraday (0.8.1)
|
11
|
+
multipart-post (~> 1.1)
|
12
|
+
hashie (1.2.0)
|
13
|
+
httpauth (0.1)
|
14
|
+
json (1.7.3)
|
15
|
+
jwt (0.1.4)
|
16
|
+
json (>= 1.2.4)
|
17
|
+
multi_json (1.3.6)
|
18
|
+
multipart-post (1.1.5)
|
19
|
+
oauth2 (0.8.0)
|
20
|
+
faraday (~> 0.8)
|
21
|
+
httpauth (~> 0.1)
|
22
|
+
jwt (~> 0.1.4)
|
23
|
+
multi_json (~> 1.0)
|
24
|
+
rack (~> 1.2)
|
25
|
+
omniauth (1.1.0)
|
26
|
+
hashie (~> 1.2)
|
27
|
+
rack
|
28
|
+
omniauth-oauth2 (1.1.0)
|
29
|
+
oauth2 (~> 0.8.0)
|
30
|
+
omniauth (~> 1.0)
|
31
|
+
rack (1.4.1)
|
32
|
+
rack-protection (1.2.0)
|
33
|
+
rack
|
34
|
+
sinatra (1.3.2)
|
35
|
+
rack (~> 1.3, >= 1.3.6)
|
36
|
+
rack-protection (~> 1.2)
|
37
|
+
tilt (~> 1.3, >= 1.3.3)
|
38
|
+
tilt (1.3.3)
|
39
|
+
|
40
|
+
PLATFORMS
|
41
|
+
ruby
|
42
|
+
|
43
|
+
DEPENDENCIES
|
44
|
+
omniauth-facebook!
|
45
|
+
sinatra
|
data/example/config.ru
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
require 'sinatra/base'
|
3
|
+
require 'omniauth-facebook'
|
4
|
+
|
5
|
+
SCOPE = 'email,read_stream'
|
6
|
+
|
7
|
+
class App < Sinatra::Base
|
8
|
+
# turn off sinatra default X-Frame-Options for FB canvas
|
9
|
+
set :protection, :except => :frame_options
|
10
|
+
|
11
|
+
# server-side flow
|
12
|
+
get '/' do
|
13
|
+
# NOTE: you would just hit this endpoint directly from the browser
|
14
|
+
# in a real app. the redirect is just here to setup the root
|
15
|
+
# path in this example sinatra app.
|
16
|
+
redirect '/auth/facebook'
|
17
|
+
end
|
18
|
+
|
19
|
+
# client-side flow
|
20
|
+
get '/client-side' do
|
21
|
+
content_type 'text/html'
|
22
|
+
# NOTE: when you enable cookie below in the FB.init call
|
23
|
+
# the GET request in the FB.login callback will send
|
24
|
+
# a signed request in a cookie back the OmniAuth callback
|
25
|
+
# which will parse out the authorization code and obtain
|
26
|
+
# the access_token. This will be the exact same access_token
|
27
|
+
# returned to the client in response.authResponse.accessToken.
|
28
|
+
<<-END
|
29
|
+
<html>
|
30
|
+
<head>
|
31
|
+
<title>Client-side Flow Example</title>
|
32
|
+
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js" type="text/javascript"></script>
|
33
|
+
</head>
|
34
|
+
<body>
|
35
|
+
<div id="fb-root"></div>
|
36
|
+
|
37
|
+
<script type="text/javascript">
|
38
|
+
window.fbAsyncInit = function() {
|
39
|
+
FB.init({
|
40
|
+
appId : '#{ENV['APP_ID']}',
|
41
|
+
status : true, // check login status
|
42
|
+
cookie : true, // enable cookies to allow the server to access the session
|
43
|
+
xfbml : true // parse XFBML
|
44
|
+
});
|
45
|
+
};
|
46
|
+
|
47
|
+
(function(d) {
|
48
|
+
var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
|
49
|
+
js = d.createElement('script'); js.id = id; js.async = true;
|
50
|
+
js.src = "//connect.facebook.net/en_US/all.js";
|
51
|
+
d.getElementsByTagName('head')[0].appendChild(js);
|
52
|
+
}(document));
|
53
|
+
|
54
|
+
$(function() {
|
55
|
+
$('a').click(function(e) {
|
56
|
+
e.preventDefault();
|
57
|
+
|
58
|
+
FB.login(function(response) {
|
59
|
+
if (response.authResponse) {
|
60
|
+
$('#connect').html('Connected! Hitting OmniAuth callback (GET /auth/facebook/callback)...');
|
61
|
+
|
62
|
+
// since we have cookies enabled, this request will allow omniauth to parse
|
63
|
+
// out the auth code from the signed request in the fbsr_XXX cookie
|
64
|
+
$.getJSON('/auth/facebook/callback', function(json) {
|
65
|
+
$('#connect').html('Connected! Callback complete.');
|
66
|
+
$('#results').html(JSON.stringify(json));
|
67
|
+
});
|
68
|
+
}
|
69
|
+
}, { scope: '#{SCOPE}' });
|
70
|
+
});
|
71
|
+
});
|
72
|
+
</script>
|
73
|
+
|
74
|
+
<p id="connect">
|
75
|
+
<a href="#">Connect to FB</a>
|
76
|
+
</p>
|
77
|
+
|
78
|
+
<p id="results" />
|
79
|
+
</body>
|
80
|
+
</html>
|
81
|
+
END
|
82
|
+
end
|
83
|
+
|
84
|
+
# auth via FB canvas and signed request param
|
85
|
+
post '/canvas/' do
|
86
|
+
# we just redirect to /auth/facebook here which will parse the
|
87
|
+
# signed_request FB sends us, asking for auth if the user has
|
88
|
+
# not already granted access, or simply moving straight to the
|
89
|
+
# callback where they have already granted access.
|
90
|
+
#
|
91
|
+
# we pass the state parameter which we can detect in our callback
|
92
|
+
# to do custom rendering/redirection for the canvas app page
|
93
|
+
redirect "/auth/facebook?signed_request=#{request.params['signed_request']}&state=canvas"
|
94
|
+
end
|
95
|
+
|
96
|
+
get '/auth/:provider/callback' do
|
97
|
+
# we can do something special here is +state+ param is canvas
|
98
|
+
# (see notes above in /canvas/ method for more details)
|
99
|
+
content_type 'application/json'
|
100
|
+
MultiJson.encode(request.env)
|
101
|
+
end
|
102
|
+
|
103
|
+
get '/auth/failure' do
|
104
|
+
content_type 'application/json'
|
105
|
+
MultiJson.encode(request.env)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
use Rack::Session::Cookie
|
110
|
+
|
111
|
+
use OmniAuth::Builder do
|
112
|
+
provider :facebook, ENV['APP_ID'], ENV['APP_SECRET'], :scope => SCOPE
|
113
|
+
end
|
114
|
+
|
115
|
+
run App.new
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'omniauth/droom'
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'omniauth-oauth2'
|
2
|
+
require 'multi_json'
|
3
|
+
|
4
|
+
module OmniAuth
|
5
|
+
module Strategies
|
6
|
+
class Droom < OmniAuth::Strategies::OAuth2
|
7
|
+
class NoAuthorizationCodeError < StandardError; end
|
8
|
+
|
9
|
+
option :name, :droom
|
10
|
+
option :provider_ignores_state, true
|
11
|
+
option :fields, [:name, :forename, :email, :phone, :admin, :image]
|
12
|
+
option :client_options, {
|
13
|
+
:site => ENV['droom_host'],
|
14
|
+
:authorize_url => "/oauth/authorize"
|
15
|
+
}
|
16
|
+
|
17
|
+
uid do
|
18
|
+
raw_info["id"]
|
19
|
+
end
|
20
|
+
|
21
|
+
info do
|
22
|
+
{
|
23
|
+
:email => raw_info["email"],
|
24
|
+
:name => raw_info["name"],
|
25
|
+
:admin => raw_info["admin"],
|
26
|
+
:forename => raw_info["forename"],
|
27
|
+
:image => raw_info["image"]
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
31
|
+
extra do
|
32
|
+
{
|
33
|
+
:raw_info => raw_info
|
34
|
+
# here we will eventually receive activity permissions
|
35
|
+
}
|
36
|
+
end
|
37
|
+
|
38
|
+
def raw_info
|
39
|
+
@raw_info ||= access_token.get('/api/me.json').parsed
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path('../lib', __FILE__)
|
3
|
+
require 'omniauth/droom/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = 'omniauth-droom'
|
7
|
+
s.version = OmniAuth::Droom::VERSION
|
8
|
+
s.authors = ['William ROss']
|
9
|
+
s.email = ['will@spanner.org']
|
10
|
+
s.summary = 'Droom strategy for OmniAuth'
|
11
|
+
s.description = 'Makes it easy for another application to use the oauth provider built into the data room.'
|
12
|
+
s.homepage = 'https://github.com/spanner/omniauth-droom'
|
13
|
+
s.license = 'MIT'
|
14
|
+
|
15
|
+
s.files = `git ls-files`.split("\n")
|
16
|
+
s.test_files = `git ls-files -- {spec,features}/*`.split("\n")
|
17
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
18
|
+
s.require_paths = ['lib']
|
19
|
+
|
20
|
+
s.add_runtime_dependency 'omniauth-oauth2', '~> 1.1'
|
21
|
+
|
22
|
+
s.add_development_dependency 'minitest'
|
23
|
+
s.add_development_dependency 'mocha'
|
24
|
+
s.add_development_dependency 'rake'
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: omniauth-droom
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- William ROss
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-04-22 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: omniauth-oauth2
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.1'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.1'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: minitest
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: mocha
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rake
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
description: Makes it easy for another application to use the oauth provider built
|
79
|
+
into the data room.
|
80
|
+
email:
|
81
|
+
- will@spanner.org
|
82
|
+
executables: []
|
83
|
+
extensions: []
|
84
|
+
extra_rdoc_files: []
|
85
|
+
files:
|
86
|
+
- .gitignore
|
87
|
+
- Gemfile
|
88
|
+
- README.md
|
89
|
+
- Rakefile
|
90
|
+
- example/Gemfile
|
91
|
+
- example/Gemfile.lock
|
92
|
+
- example/config.ru
|
93
|
+
- lib/omniauth-droom.rb
|
94
|
+
- lib/omniauth/droom.rb
|
95
|
+
- lib/omniauth/droom/version.rb
|
96
|
+
- lib/omniauth/strategies/droom.rb
|
97
|
+
- omniauth-droom.gemspec
|
98
|
+
homepage: https://github.com/spanner/omniauth-droom
|
99
|
+
licenses:
|
100
|
+
- MIT
|
101
|
+
post_install_message:
|
102
|
+
rdoc_options: []
|
103
|
+
require_paths:
|
104
|
+
- lib
|
105
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
106
|
+
none: false
|
107
|
+
requirements:
|
108
|
+
- - ! '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
|
+
none: false
|
113
|
+
requirements:
|
114
|
+
- - ! '>='
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
requirements: []
|
118
|
+
rubyforge_project:
|
119
|
+
rubygems_version: 1.8.24
|
120
|
+
signing_key:
|
121
|
+
specification_version: 3
|
122
|
+
summary: Droom strategy for OmniAuth
|
123
|
+
test_files: []
|