exvo-auth 0.5.2 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README +40 -3
- data/Rakefile +1 -0
- data/VERSION +1 -1
- data/exvo-auth.gemspec +8 -2
- data/lib/exvo-auth.rb +13 -6
- data/lib/exvo_auth/autonomous/cache.rb +21 -0
- data/lib/exvo_auth/autonomous/consumer.rb +34 -0
- data/lib/exvo_auth/autonomous/provider.rb +35 -0
- data/lib/exvo_auth/controllers/base.rb +0 -4
- data/lib/exvo_auth/controllers/rails.rb +11 -0
- metadata +21 -4
data/README
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
OAuth2
|
2
|
+
======
|
3
|
+
|
1
4
|
-1. Get familiar with OmniAuth by Intridea: http://github.com/intridea/omniauth. Read about OAuth2.
|
2
5
|
|
3
6
|
|
@@ -14,10 +17,12 @@ There are two middlewares. Usually you will need the "interactive" one:
|
|
14
17
|
ExvoAuth::Strategies::Interactive
|
15
18
|
ExvoAuth::Strategies::NonInteractive
|
16
19
|
|
17
|
-
Both middlewares need client_id and client_secret
|
18
|
-
In Rails, the relevant
|
20
|
+
Both middlewares need client_id and client_secret configured.
|
21
|
+
In Rails, the relevant lines could look like this:
|
19
22
|
|
20
|
-
|
23
|
+
ExvoAuth::Config.client_id = "foo"
|
24
|
+
ExvoAuth::Config.client_secret = "bar"
|
25
|
+
config.middleware.use ExvoAuth::Strategies::Interactive
|
21
26
|
|
22
27
|
|
23
28
|
3. Add routes.
|
@@ -33,6 +38,13 @@ You can have separate callbacks for interactive and non-interactive
|
|
33
38
|
callback routes but you can also route both callbacks to the same controller method
|
34
39
|
like shown above.
|
35
40
|
|
41
|
+
You also need a root_url route defined in routes (Rails) or this little hack (Merb):
|
42
|
+
|
43
|
+
Merb::Controller.class_eval do
|
44
|
+
def root_url
|
45
|
+
absolute_url("/foo") # probably a "/"
|
46
|
+
end
|
47
|
+
end
|
36
48
|
|
37
49
|
4. Include controller helpers into your application controller.
|
38
50
|
|
@@ -66,3 +78,28 @@ In short: you get params[:auth]. Do what you want to do with it: store the data,
|
|
66
78
|
|
67
79
|
|
68
80
|
6. Read the source, there are few features not mentioned in this README.
|
81
|
+
|
82
|
+
|
83
|
+
Inter-Application Communication
|
84
|
+
===============================
|
85
|
+
|
86
|
+
|
87
|
+
# Consumer side
|
88
|
+
|
89
|
+
consumer = ExvoAuth::Autonomous::Consumer.new(
|
90
|
+
:provider_id => "this is client_id of the app you want to connect to"
|
91
|
+
)
|
92
|
+
consumer.access_token => "this is the access token to use along with your client_id to communicate with providing app"
|
93
|
+
|
94
|
+
|
95
|
+
# Provider side
|
96
|
+
|
97
|
+
provider = ExvoAuth::Autonomous::Provider.new(
|
98
|
+
:consumer_id => "the client_id of the consuming app",
|
99
|
+
:access_token => "the access_token of the consuming app"
|
100
|
+
)
|
101
|
+
provider.scopes => ["users", "payments"] # example access scopes defined in auth server.
|
102
|
+
|
103
|
+
Scopes are used by providing app to check if a given consuming app should have access to a given resource inside a scope.
|
104
|
+
If scopes are empty, then provider app should not present any resources to consumer.
|
105
|
+
|
data/Rakefile
CHANGED
@@ -10,6 +10,7 @@ begin
|
|
10
10
|
gem.homepage = "http://github.com/Exvo/Auth"
|
11
11
|
gem.authors = ["Jacek Becela"]
|
12
12
|
gem.add_dependency "oa-oauth", "0.0.1"
|
13
|
+
gem.add_dependency "httparty", "0.6.1"
|
13
14
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
14
15
|
end
|
15
16
|
Jeweler::GemcutterTasks.new
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.6.0
|
data/exvo-auth.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{exvo-auth}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.6.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Jacek Becela"]
|
12
|
-
s.date = %q{2010-07-
|
12
|
+
s.date = %q{2010-07-19}
|
13
13
|
s.description = %q{Sign in with Exvo account}
|
14
14
|
s.email = %q{jacek.becela@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -26,6 +26,9 @@ Gem::Specification.new do |s|
|
|
26
26
|
"VERSION",
|
27
27
|
"exvo-auth.gemspec",
|
28
28
|
"lib/exvo-auth.rb",
|
29
|
+
"lib/exvo_auth/autonomous/cache.rb",
|
30
|
+
"lib/exvo_auth/autonomous/consumer.rb",
|
31
|
+
"lib/exvo_auth/autonomous/provider.rb",
|
29
32
|
"lib/exvo_auth/config.rb",
|
30
33
|
"lib/exvo_auth/controllers/base.rb",
|
31
34
|
"lib/exvo_auth/controllers/merb.rb",
|
@@ -53,11 +56,14 @@ Gem::Specification.new do |s|
|
|
53
56
|
|
54
57
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
55
58
|
s.add_runtime_dependency(%q<oa-oauth>, ["= 0.0.1"])
|
59
|
+
s.add_runtime_dependency(%q<httparty>, ["= 0.6.1"])
|
56
60
|
else
|
57
61
|
s.add_dependency(%q<oa-oauth>, ["= 0.0.1"])
|
62
|
+
s.add_dependency(%q<httparty>, ["= 0.6.1"])
|
58
63
|
end
|
59
64
|
else
|
60
65
|
s.add_dependency(%q<oa-oauth>, ["= 0.0.1"])
|
66
|
+
s.add_dependency(%q<httparty>, ["= 0.6.1"])
|
61
67
|
end
|
62
68
|
end
|
63
69
|
|
data/lib/exvo-auth.rb
CHANGED
@@ -1,15 +1,10 @@
|
|
1
1
|
require 'omniauth/oauth'
|
2
2
|
require 'multi_json'
|
3
|
+
require 'httparty'
|
3
4
|
|
4
5
|
module ExvoAuth
|
5
6
|
autoload :Config, 'exvo_auth/config'
|
6
7
|
|
7
|
-
module OAuth2
|
8
|
-
module Strategy
|
9
|
-
autoload :NonInteractive, 'exvo_auth/oauth2'
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
8
|
module Strategies
|
14
9
|
autoload :Base, 'exvo_auth/strategies/base'
|
15
10
|
autoload :Interactive, 'exvo_auth/strategies/interactive'
|
@@ -21,6 +16,18 @@ module ExvoAuth
|
|
21
16
|
autoload :Rails, 'exvo_auth/controllers/rails'
|
22
17
|
autoload :Merb, 'exvo_auth/controllers/merb'
|
23
18
|
end
|
19
|
+
|
20
|
+
module Autonomous
|
21
|
+
autoload :Consumer, 'exvo_auth/autonomous/consumer'
|
22
|
+
autoload :Provider, 'exvo_auth/autonomous/provider'
|
23
|
+
autoload :Cache, 'exvo_auth/autonomous/cache'
|
24
|
+
end
|
25
|
+
|
26
|
+
module OAuth2
|
27
|
+
module Strategy
|
28
|
+
autoload :NonInteractive, 'exvo_auth/oauth2'
|
29
|
+
end
|
30
|
+
end
|
24
31
|
end
|
25
32
|
|
26
33
|
OAuth2::Client.class_eval do
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class ExvoAuth::Autonomous::Cache
|
2
|
+
def initialize
|
3
|
+
@data = {}
|
4
|
+
end
|
5
|
+
|
6
|
+
def read(key)
|
7
|
+
@data[key]
|
8
|
+
end
|
9
|
+
|
10
|
+
def write(key, value)
|
11
|
+
@data[key] = value
|
12
|
+
end
|
13
|
+
|
14
|
+
def fetch(key)
|
15
|
+
if block_given?
|
16
|
+
read(key) || write(key, yield)
|
17
|
+
else
|
18
|
+
read(key)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
class ExvoAuth::Autonomous::Consumer
|
2
|
+
attr_reader :options
|
3
|
+
@@cache = ExvoAuth::Autonomous::Cache.new
|
4
|
+
|
5
|
+
def initialize(options = {})
|
6
|
+
options[:site] ||= ExvoAuth::Config.host
|
7
|
+
options[:client_id] ||= ExvoAuth::Config.client_id
|
8
|
+
options[:client_secret] ||= ExvoAuth::Config.client_secret
|
9
|
+
|
10
|
+
if options[:site].nil? || options[:client_id].nil? || options[:client_secret].nil? || options[:provider_id].nil?
|
11
|
+
raise(ArgumentError, "Please configure site, client_id, client_secret and provider_id")
|
12
|
+
end
|
13
|
+
|
14
|
+
@options = options
|
15
|
+
end
|
16
|
+
|
17
|
+
def access_token
|
18
|
+
@@cache.fetch(options) do
|
19
|
+
access_token!
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def access_token!
|
24
|
+
response = HTTParty.get("/apps/consumer/authorizations/#{options[:provider_id]}.json",
|
25
|
+
:base_uri => options[:site],
|
26
|
+
:basic_auth => {
|
27
|
+
:username => options[:client_id],
|
28
|
+
:password => options[:client_secret]
|
29
|
+
}
|
30
|
+
)
|
31
|
+
|
32
|
+
@@cache.write(options, response["access_token"])
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
class ExvoAuth::Autonomous::Provider
|
2
|
+
attr_reader :options
|
3
|
+
@@cache = ExvoAuth::Autonomous::Cache.new
|
4
|
+
|
5
|
+
def initialize(options = {})
|
6
|
+
options[:site] ||= ExvoAuth::Config.host
|
7
|
+
options[:client_id] ||= ExvoAuth::Config.client_id
|
8
|
+
options[:client_secret] ||= ExvoAuth::Config.client_secret
|
9
|
+
|
10
|
+
if options[:site].nil? || options[:client_id].nil? || options[:client_secret].nil? || options[:consumer_id].nil? || options[:access_token].nil?
|
11
|
+
raise(ArgumentError, "Please configure site, client_id, client_secret, consumer_id and access_token")
|
12
|
+
end
|
13
|
+
|
14
|
+
@options = options
|
15
|
+
end
|
16
|
+
|
17
|
+
def scopes
|
18
|
+
@@cache.fetch(options) do
|
19
|
+
scopes!
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def scopes!
|
24
|
+
response = HTTParty.get("/apps/provider/authorizations/#{options[:consumer_id]}.json",
|
25
|
+
:base_uri => options[:site],
|
26
|
+
:basic_auth => {
|
27
|
+
:username => options[:client_id],
|
28
|
+
:password => options[:client_secret]
|
29
|
+
},
|
30
|
+
:query => { :access_token => options[:access_token] }
|
31
|
+
)
|
32
|
+
|
33
|
+
@@cache.write(options, response["scope"].to_s.split)
|
34
|
+
end
|
35
|
+
end
|
@@ -19,10 +19,6 @@ module ExvoAuth::Controllers::Base
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
# If there's no stored location then it's a popup login.
|
23
|
-
# If there's a stored location then it's a redirect login
|
24
|
-
# caused by #authenticate_user! method.
|
25
|
-
#
|
26
22
|
# Usually this method is called from your sessions#create.
|
27
23
|
def sign_in_and_redirect!(user_id)
|
28
24
|
session[:user_id] = user_id
|
@@ -7,6 +7,17 @@ module ExvoAuth::Controllers::Rails
|
|
7
7
|
|
8
8
|
module InstanceMethods
|
9
9
|
protected
|
10
|
+
|
11
|
+
def authenticate_app_in_scope!(scope)
|
12
|
+
authenticate_or_request_with_http_basic do |consumer_id, access_token|
|
13
|
+
@current_scopes = ExvoAuth::Autonomous::Provider.new(
|
14
|
+
:consumer_id => consumer_id,
|
15
|
+
:access_token => access_token
|
16
|
+
).scopes
|
17
|
+
|
18
|
+
@current_scopes.include?(scope)
|
19
|
+
end
|
20
|
+
end
|
10
21
|
|
11
22
|
def find_user_by_id(id)
|
12
23
|
User.find(id)
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 0.
|
7
|
+
- 6
|
8
|
+
- 0
|
9
|
+
version: 0.6.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Jacek Becela
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-07-
|
17
|
+
date: 2010-07-19 00:00:00 +02:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -31,6 +31,20 @@ dependencies:
|
|
31
31
|
version: 0.0.1
|
32
32
|
type: :runtime
|
33
33
|
version_requirements: *id001
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: httparty
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
segments:
|
42
|
+
- 0
|
43
|
+
- 6
|
44
|
+
- 1
|
45
|
+
version: 0.6.1
|
46
|
+
type: :runtime
|
47
|
+
version_requirements: *id002
|
34
48
|
description: Sign in with Exvo account
|
35
49
|
email: jacek.becela@gmail.com
|
36
50
|
executables: []
|
@@ -50,6 +64,9 @@ files:
|
|
50
64
|
- VERSION
|
51
65
|
- exvo-auth.gemspec
|
52
66
|
- lib/exvo-auth.rb
|
67
|
+
- lib/exvo_auth/autonomous/cache.rb
|
68
|
+
- lib/exvo_auth/autonomous/consumer.rb
|
69
|
+
- lib/exvo_auth/autonomous/provider.rb
|
53
70
|
- lib/exvo_auth/config.rb
|
54
71
|
- lib/exvo_auth/controllers/base.rb
|
55
72
|
- lib/exvo_auth/controllers/merb.rb
|