auth_passport_checkpoint 0.0.17.29 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/auth_passport_checkpoint/engine.rb +1 -6
- data/lib/auth_passport_checkpoint/helpers/controller_helpers/access_token_helper.rb +14 -0
- data/lib/auth_passport_checkpoint/{booster.rb → helpers/controller_helpers/booster.rb} +0 -0
- data/lib/auth_passport_checkpoint/helpers/controller_helpers/current_user_helper.rb +41 -0
- data/lib/auth_passport_checkpoint/helpers/controller_helpers/signed_request.rb +42 -0
- data/lib/auth_passport_checkpoint/helpers/controller_helpers.rb +34 -0
- data/lib/auth_passport_checkpoint/version.rb +1 -1
- data/lib/auth_passport_checkpoint.rb +18 -2
- metadata +19 -19
- data/lib/auth_passport_checkpoint/frontend_app/access_token_helper.rb +0 -24
- data/lib/auth_passport_checkpoint/intermediary_api/access_token_helper.rb +0 -25
- data/lib/auth_passport_checkpoint/intermediary_api/current_user_helper.rb +0 -47
- data/lib/auth_passport_checkpoint/signed_request.rb +0 -32
@@ -8,12 +8,7 @@ module AuthPassportCheckpoint
|
|
8
8
|
initializer "auth_passport_checkpoint.configure" do |app|
|
9
9
|
AuthPassportCheckpoint.configure(app.config.auth_passport_checkpoint)
|
10
10
|
|
11
|
-
require 'auth_passport_checkpoint/
|
12
|
-
require 'auth_passport_checkpoint/intermediary_api/access_token_helper'
|
13
|
-
require 'auth_passport_checkpoint/intermediary_api/current_user_helper'
|
14
|
-
require 'auth_passport_checkpoint/booster'
|
15
|
-
require 'auth_passport_checkpoint/signed_request'
|
16
|
-
|
11
|
+
require 'auth_passport_checkpoint/helpers/controller_helpers'
|
17
12
|
|
18
13
|
if ::AuthPassportCheckpoint.is_intermediary_api?
|
19
14
|
::AuthOriginControl.setup do |config|
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module AuthPassportCheckpoint
|
2
|
+
module AccessTokenHelper
|
3
|
+
|
4
|
+
def current_access_token
|
5
|
+
unless token = params[:access_token]
|
6
|
+
return nil unless session['user_id']
|
7
|
+
token = session['user_id'].try(:credentials).try(:token)
|
8
|
+
end
|
9
|
+
token
|
10
|
+
end
|
11
|
+
|
12
|
+
ActiveSupport.run_load_hooks :auth_passport_checkpoint_access_token_helper, self
|
13
|
+
end
|
14
|
+
end
|
File without changes
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module AuthPassportCheckpoint
|
2
|
+
module CurrentUserHelper
|
3
|
+
module ForIntermediaryApi
|
4
|
+
def login_required
|
5
|
+
if !current_user
|
6
|
+
error = { 'error' => '401 Unauthorized', 'status' => 401 }
|
7
|
+
if Object.const_defined?("Grape") and self.class == Grape::Endpoint
|
8
|
+
error!('401 Unauthorized', 401)
|
9
|
+
else
|
10
|
+
render :json => error.to_json
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def current_user
|
16
|
+
return @current_user if @current_user
|
17
|
+
if result = user_signed_request_result(AuthPassportCheckpoint.current_user_url)
|
18
|
+
return @current_user ||= OpenStruct.new(result)
|
19
|
+
end
|
20
|
+
nil
|
21
|
+
end
|
22
|
+
|
23
|
+
ActiveSupport.run_load_hooks :auth_passport_checkpoint_current_user_helper_for_intermediary_api, self
|
24
|
+
end
|
25
|
+
|
26
|
+
module ForAll
|
27
|
+
def self.included base
|
28
|
+
base.send :extend, ForAll::ClassMethods
|
29
|
+
puts "included in #{base.to_s}"
|
30
|
+
end
|
31
|
+
|
32
|
+
module ClassMethods
|
33
|
+
def make_auth_passport_checkpoint_intermediary_api
|
34
|
+
self.send(:include, AuthPassportCheckpoint::CurrentUserHelper::ForIntermediaryApi)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
ActiveSupport.run_load_hooks :auth_passport_checkpoint_current_user_helper_for_all, self
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module AuthPassportCheckpoint
|
2
|
+
module SignedRequestHelper
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
def user_signed_request_result(request_uri, args = {})
|
6
|
+
if kurrent_user = AuthPassportCheckpoint::Booster.get(current_access_token)
|
7
|
+
return kurrent_user
|
8
|
+
else
|
9
|
+
request_params = (args[:params] || {}).merge({access_token: current_access_token})
|
10
|
+
result = AuthOriginControl::SignedRequest.new(request_uri, args.merge({:payload => request_params})).try(:result)
|
11
|
+
if result = success_result(result)
|
12
|
+
AuthPassportCheckpoint::Booster.set current_access_token, result
|
13
|
+
return AuthPassportCheckpoint::Booster.get(current_access_token) || result
|
14
|
+
end
|
15
|
+
end
|
16
|
+
nil
|
17
|
+
end
|
18
|
+
|
19
|
+
def signed_request_result(request_uri, args = {}, redirect=true)
|
20
|
+
begin
|
21
|
+
kurrent_access_token = current_access_token
|
22
|
+
rescue NoMethodError
|
23
|
+
kurrent_access_token = args[:params].try(:[],:acces_token)
|
24
|
+
end
|
25
|
+
request_params = (args[:params] || {}).merge({access_token: kurrent_access_token})
|
26
|
+
raw_result = AuthOriginControl::SignedRequest.new(request_uri, args.merge({:payload => request_params})).try(:result)
|
27
|
+
if result = success_result(raw_result)
|
28
|
+
result
|
29
|
+
else
|
30
|
+
return redirect ? redirect_to(AuthPassportCheckpoint.authenticate_redirect_url(self)) : raw_result
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def success_result r
|
35
|
+
error = (r.is_a?(Hash) and r.try(:[],:error) || r.try(:[],"error"))
|
36
|
+
return r unless error
|
37
|
+
nil
|
38
|
+
end
|
39
|
+
|
40
|
+
ActiveSupport.run_load_hooks(:auth_passport_checkpoint_signed_request_helper, self)
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'auth_passport_checkpoint/helpers/controller_helpers/access_token_helper'
|
2
|
+
require 'auth_passport_checkpoint/helpers/controller_helpers/current_user_helper'
|
3
|
+
require 'auth_passport_checkpoint/helpers/controller_helpers/booster'
|
4
|
+
require 'auth_passport_checkpoint/helpers/controller_helpers/signed_request'
|
5
|
+
|
6
|
+
module AuthPassportCheckpoint
|
7
|
+
module ControllerHelpers
|
8
|
+
|
9
|
+
def self.included base
|
10
|
+
include_dependents base
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.include_dependents base
|
14
|
+
base.send :include, AuthOriginControl::Helpers # from AuthOriginControl
|
15
|
+
base.send :include, AuthPassportCheckpoint::AccessTokenHelper
|
16
|
+
if AuthPassportCheckpoint.is_intermediary_api?
|
17
|
+
base.send :include, AuthPassportCheckpoint::CurrentUserHelper::ForIntermediaryApi
|
18
|
+
else
|
19
|
+
base.send :include, AuthPassportCheckpoint::CurrentUserHelper::ForAll
|
20
|
+
end
|
21
|
+
base.send :include, AuthPassportCheckpoint::SignedRequestHelper
|
22
|
+
end
|
23
|
+
include_dependents self
|
24
|
+
|
25
|
+
this = self
|
26
|
+
ActiveSupport.on_load :action_controller do
|
27
|
+
ActiveSupport.run_load_hooks :auth_passport_checkpoint_controller_helpers, this
|
28
|
+
end
|
29
|
+
|
30
|
+
ActiveSupport.on_load :auth_passport_checkpoint_controller_helpers do
|
31
|
+
ActionController::Base.send :include, self
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -17,7 +17,17 @@ module AuthPassportCheckpoint
|
|
17
17
|
|
18
18
|
mattr_accessor :redis_connection
|
19
19
|
def self.redis_connection
|
20
|
-
@@redis_connection ||=
|
20
|
+
@@redis_connection ||= try_redis_connection
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.try_redis_connection
|
24
|
+
begin
|
25
|
+
redis = @@redis_config ? Redis.new(@@redis_config) : nil
|
26
|
+
redis.keys
|
27
|
+
redis
|
28
|
+
rescue Redis::CannotConnectError => e
|
29
|
+
nil
|
30
|
+
end
|
21
31
|
end
|
22
32
|
|
23
33
|
mattr_accessor :redis_cache_expiration, :redis_config
|
@@ -25,6 +35,12 @@ module AuthPassportCheckpoint
|
|
25
35
|
@@is_intermediary_api = args[:is_intermediary_api] || false
|
26
36
|
@@current_user_url = args[:current_user_url]
|
27
37
|
@@redis_config = args[:redis_config]
|
28
|
-
@@redis_cache_expiration = args[:redis_cache_expiration] ||
|
38
|
+
@@redis_cache_expiration = args[:redis_cache_expiration] || 9.minutes
|
39
|
+
@@authenticate_redirect_url = args[:authenticate_redirect_url]
|
29
40
|
end
|
41
|
+
|
42
|
+
mattr_accessor :authenticate_redirect_url
|
43
|
+
def self.authenticate_redirect_url context
|
44
|
+
@@authenticate_redirect_url ||= context.login_path
|
45
|
+
end
|
30
46
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: auth_passport_checkpoint
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-04-
|
12
|
+
date: 2014-04-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
16
|
-
requirement: &
|
16
|
+
requirement: &70366743684880 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,32 +21,32 @@ dependencies:
|
|
21
21
|
version: 3.2.11
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70366743684880
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: auth_origin_control
|
27
|
-
requirement: &
|
27
|
+
requirement: &70366743684360 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: 0.1.
|
32
|
+
version: 0.1.2
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70366743684360
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: sso_clyent
|
38
|
-
requirement: &
|
38
|
+
requirement: &70366743683900 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
42
42
|
- !ruby/object:Gem::Version
|
43
|
-
version: 0.0
|
43
|
+
version: 0.1.0
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70366743683900
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: redis
|
49
|
-
requirement: &
|
49
|
+
requirement: &70366743683340 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: 3.0.0
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70366743683340
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: mysql2
|
60
|
-
requirement: &
|
60
|
+
requirement: &70366743682960 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,7 +65,7 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70366743682960
|
69
69
|
description: ! 'Checks id at entry: id of users on client apps and on intermediary
|
70
70
|
apps (sso_clyent), id of apps on intermediary apps (auth_origin_control), id '
|
71
71
|
email:
|
@@ -80,12 +80,12 @@ files:
|
|
80
80
|
- app/helpers/auth_passport_checkpoint/application_helper.rb
|
81
81
|
- app/views/layouts/auth_passport_checkpoint/application.html.erb
|
82
82
|
- config/routes.rb
|
83
|
-
- lib/auth_passport_checkpoint/booster.rb
|
84
83
|
- lib/auth_passport_checkpoint/engine.rb
|
85
|
-
- lib/auth_passport_checkpoint/
|
86
|
-
- lib/auth_passport_checkpoint/
|
87
|
-
- lib/auth_passport_checkpoint/
|
88
|
-
- lib/auth_passport_checkpoint/signed_request.rb
|
84
|
+
- lib/auth_passport_checkpoint/helpers/controller_helpers/access_token_helper.rb
|
85
|
+
- lib/auth_passport_checkpoint/helpers/controller_helpers/booster.rb
|
86
|
+
- lib/auth_passport_checkpoint/helpers/controller_helpers/current_user_helper.rb
|
87
|
+
- lib/auth_passport_checkpoint/helpers/controller_helpers/signed_request.rb
|
88
|
+
- lib/auth_passport_checkpoint/helpers/controller_helpers.rb
|
89
89
|
- lib/auth_passport_checkpoint/version.rb
|
90
90
|
- lib/auth_passport_checkpoint.rb
|
91
91
|
- lib/tasks/auth_passport_checkpoint_tasks.rake
|
@@ -1,24 +0,0 @@
|
|
1
|
-
# module AccessTokenHelper
|
2
|
-
# extend ActiveSupport::Concern
|
3
|
-
#
|
4
|
-
# def current_access_token
|
5
|
-
# return nil unless session[:user_id]
|
6
|
-
# session[:user_id]['access_token']
|
7
|
-
# end
|
8
|
-
# end
|
9
|
-
# if !AuthPassportCheckpoint.is_intermediary_api?
|
10
|
-
# ActionController::Base.send :include, AccessTokenHelper
|
11
|
-
# end
|
12
|
-
|
13
|
-
# REMOVED THE INTERMEDIARY API LOGIC - Useless
|
14
|
-
#
|
15
|
-
# if !AuthPassportCheckpoint.is_intermediary_api?
|
16
|
-
# module AuthPassportCheckpoint
|
17
|
-
# module Helper
|
18
|
-
# def current_access_token
|
19
|
-
# return nil unless session['user_id']
|
20
|
-
# session['user_id'].try(:credentials).try(:token)
|
21
|
-
# end
|
22
|
-
# end
|
23
|
-
# end
|
24
|
-
# end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
module AuthPassportCheckpoint
|
2
|
-
module IntermediaryApi
|
3
|
-
module AccessTokenHelper
|
4
|
-
|
5
|
-
def current_access_token
|
6
|
-
unless token = params[:access_token]
|
7
|
-
return nil unless session['user_id']
|
8
|
-
token = session['user_id'].try(:credentials).try(:token)
|
9
|
-
end
|
10
|
-
token
|
11
|
-
end
|
12
|
-
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
# REMOVED THE INTERMEDIARY API LOGIC - Useless
|
18
|
-
#
|
19
|
-
#if AuthPassportCheckpoint.is_intermediary_api?
|
20
|
-
module AuthPassportCheckpoint
|
21
|
-
module Helper
|
22
|
-
include AuthPassportCheckpoint::IntermediaryApi::AccessTokenHelper
|
23
|
-
end
|
24
|
-
end
|
25
|
-
#end
|
@@ -1,47 +0,0 @@
|
|
1
|
-
module AuthPassportCheckpoint
|
2
|
-
module IntermediaryApi
|
3
|
-
module CurrentUserHelper
|
4
|
-
module ForIntermediaryApi
|
5
|
-
def login_required
|
6
|
-
if !current_user
|
7
|
-
error = { 'error' => '401 Unauthorized', 'status' => 401 }
|
8
|
-
if Object.const_defined?("Grape") and self.class == Grape::Endpoint
|
9
|
-
error!('401 Unauthorized', 401)
|
10
|
-
else
|
11
|
-
render :json => error.to_json
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
def current_user
|
17
|
-
return @current_user if @current_user
|
18
|
-
|
19
|
-
result = user_signed_request_result(AuthPassportCheckpoint.current_user_url)
|
20
|
-
@current_user ||= (result.try(:[],:error) || result.try(:[],"error")) ? nil : result
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
module ForAll
|
25
|
-
extend ActiveSupport::Concern
|
26
|
-
|
27
|
-
module ClassMethods
|
28
|
-
def make_auth_passport_checkpoint_intermediary_api
|
29
|
-
self.send(:include, AuthPassportCheckpoint::IntermediaryApi::CurrentUserHelper::ForIntermediaryApi)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
if AuthPassportCheckpoint.is_intermediary_api?
|
38
|
-
module AuthPassportCheckpoint
|
39
|
-
module Helper
|
40
|
-
include AuthPassportCheckpoint::IntermediaryApi::CurrentUserHelper::ForIntermediaryApi
|
41
|
-
end
|
42
|
-
end
|
43
|
-
else
|
44
|
-
class ActionController::Base
|
45
|
-
include AuthPassportCheckpoint::IntermediaryApi::CurrentUserHelper::ForAll
|
46
|
-
end
|
47
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
module SignedRequestHelper
|
2
|
-
extend ActiveSupport::Concern
|
3
|
-
|
4
|
-
def user_signed_request_result(request_uri, args = {})
|
5
|
-
logger.debug current_access_token
|
6
|
-
if kurrent_user = AuthPassportCheckpoint::Booster.get(current_access_token)
|
7
|
-
kurrent_user
|
8
|
-
else
|
9
|
-
request_params = (args[:params] || {}).merge({access_token: current_access_token})
|
10
|
-
AuthPassportCheckpoint::Booster.set current_access_token, AuthOriginControl::SignedRequest.new(request_uri, args.merge({:payload => request_params})).try(:result)
|
11
|
-
AuthPassportCheckpoint::Booster.get(current_access_token)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
def signed_request_result(request_uri, args = {})
|
16
|
-
current_access_token = respond_to?(:current_access_token) ? current_access_token : args[:params].try(:[],:acces_token)
|
17
|
-
request_params = (args[:params] || {}).merge({access_token: current_access_token})
|
18
|
-
AuthOriginControl::SignedRequest.new(request_uri, args.merge({:payload => request_params})).try(:result)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
module AuthPassportCheckpoint
|
23
|
-
module Helper
|
24
|
-
include AuthOriginControl::Helpers # from AuthOriginControl
|
25
|
-
include SignedRequestHelper
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
class ActionController::Base
|
30
|
-
include AuthPassportCheckpoint::Helper
|
31
|
-
end
|
32
|
-
|