sq_auth 0.0.24 → 0.0.25

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/examples/client.rb CHANGED
@@ -1,13 +1,12 @@
1
1
  require 'sinatra'
2
2
  require 'sq_auth'
3
-
4
3
  enable :sessions
5
4
  set :port, 7842
6
5
 
7
- SqAuth.connect(host: "localhost", port: 3000) do |d|
6
+ SqAuth.connect(host: "localhost", port: 3000, https: false) do |d|
8
7
  d.project_name = "Project"
8
+ # d.gateway_ip = "192.168.0.1"
9
9
  end
10
-
11
10
  get ["admin"], "/something" do
12
11
  <<-EOF
13
12
  Logined to something with params #{params}
@@ -1,7 +1,7 @@
1
1
  module SqAuth
2
2
  class SqAuthAccess
3
3
  DEFAULT_ACCESS_PATH = "/access_partial"
4
- DEFAULT_DRAW_PROC = Proc.new {|uri, callback, role, project, session| SqAuthUtils::default_draw_template(uri, callback, role, project, session)}
4
+ DEFAULT_DRAW_PROC = Proc.new {|uri, project_params, user_params| SqAuthUtils::default_draw_template(uri, project_params, user_params)}
5
5
  DEFAULT_DATA_PROC = Proc.new { "Forbidden" }
6
6
  DEFAULT_OPTIONS = {project: "Project", https: true}
7
7
  attr_accessor :login_path, :callback, :project_name, :gateway_ip, :forced_host, :forced_port
@@ -53,7 +53,7 @@ module SqAuth
53
53
  if sq_auth_filter(roles, project, options)
54
54
  when_ok.call
55
55
  else
56
- when_no_role.(not_logged_in_proc.(login_to, callback, roles, project, @session_provider.session_for_current_user))
56
+ when_no_role.(not_logged_in_proc.(login_to, form_project_params(callback, roles, project), @session_provider.current_user_params))
57
57
  end
58
58
  end
59
59
 
@@ -61,10 +61,13 @@ module SqAuth
61
61
  @session_provider.session_for_current_user && @session_provider.role_exist_for_current_user?(roles, project)
62
62
  end
63
63
 
64
+ def form_project_params callback, roles, project
65
+ {callback: callback, roles: [*roles], auth_name: project}
66
+ end
64
67
 
65
68
  def when_not_authenticated(roles, project, options = {})
66
69
  not_logged_in_proc = get_not_logged_in_proc(options[:draw])
67
- not_logged_in_proc.call(login_to, callback, roles, project, @session_provider.session_for_current_user)
70
+ not_logged_in_proc.call(login_to, form_project_params(callback, roles, project), @session_provider.current_user_params)
68
71
  end
69
72
 
70
73
  def draw_when_not_authenticated(roles, project = @project_name)
@@ -95,7 +98,6 @@ module SqAuth
95
98
  else
96
99
  @session_provider.user.user_ip = ip
97
100
  end
98
- p @session_provider.user.user_ip
99
101
  end
100
102
 
101
103
  def login_to
@@ -20,6 +20,10 @@ module SqAuth
20
20
  session_for current_user
21
21
  end
22
22
 
23
+ def ip_for_current_user
24
+ ip_for current_user
25
+ end
26
+
23
27
  def check_connection
24
28
  send_request :check_connection
25
29
  end
@@ -50,6 +54,10 @@ module SqAuth
50
54
  @sessions[user]
51
55
  end
52
56
 
57
+ def ip_for user
58
+ user[:ip]
59
+ end
60
+
53
61
  def role_exist? user, roles, project
54
62
  request_hash = {sqauthsession: session_for(user), roles: [*roles], auth_name: project, ip: user[:ip]}
55
63
  response = send_request :check_role, request_hash
@@ -68,5 +76,9 @@ module SqAuth
68
76
  uri_builder = (@https ? URI::HTTPS : URI::HTTP)
69
77
  uri_builder.build(host: @host, port: @port)
70
78
  end
79
+
80
+ def current_user_params
81
+ {session: session_for_current_user, ip: ip_for_current_user}
82
+ end
71
83
  end
72
84
  end
@@ -1,9 +1,9 @@
1
1
  module SqAuth
2
2
  module SqAuthUtils
3
- def self.default_draw_template uri, callback, role, project, session
3
+ def self.default_draw_template uri, project_params, user_params #callback, role, project, session, ip
4
4
  <<-EOF
5
5
  <div class="sq_auth_not_logged_in">
6
- <iframe src='#{uri}?#{SqAuth::SqAuthRequest.hash_to_query({callback: callback, roles: [*role], auth_name: project, sqauthsession: session})}'>
6
+ <iframe src='#{uri}?#{SqAuth::SqAuthRequest.hash_to_query(project_params.merge(user_params))}'>
7
7
  </iframe>
8
8
  </div>
9
9
  EOF
@@ -1,3 +1,3 @@
1
1
  module SqAuth
2
- VERSION = "0.0.24"
2
+ VERSION = "0.0.25"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sq_auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.24
4
+ version: 0.0.25
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-03 00:00:00.000000000Z
12
+ date: 2012-05-28 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake