openam_auth 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fc60c0f8f563389a4986b738a0cb1d4c7a0c9d67
4
- data.tar.gz: 60ad9c40f97b78b656610bb7a1408c534f8546fe
3
+ metadata.gz: 0913734338ee45a826e3d2b8b2d060c405532105
4
+ data.tar.gz: 79dbfc448da870664023029b11fbe2413b69ee7c
5
5
  SHA512:
6
- metadata.gz: 3365ce33d3deb11202f0f3ef7e4eeccc599d437ff849e09f91c4fa7ef5c8ac4883b0c90904b635d9cb2f9f2a8dd99c50c9682808a27a0467741e9782cc2f2185
7
- data.tar.gz: 2d8f06fd82e83e2aef8d8f0ee73d04e3810f0a7ce4486875db4e460357f17e2beecaf0c05436dbc831c693e6e157480b70d30c80f5179661c83d69c9369e7802
6
+ metadata.gz: 3504d9e01a6a22a669dc5c00b0d9d4a73230a489893fce6f89f34726e328ef2a58dd87398f071048f4aad387a16e99b4a6c5ddb3fc788a6540d992815c619a4d
7
+ data.tar.gz: 1a92e5e78da602b5f8147354833540c53a0105dfa11483e465768ff6175982e7e8ac86b64cf7d05ef5bcaf7a2b477e0cca89deeccc8753ef61a613b337379295
@@ -1,45 +1,48 @@
1
1
  module OpenamAuth
2
2
  module Authenticate
3
- module ClassMethods ; end
4
-
5
- module InstanceMethods
6
-
7
- def authenticate_user!
8
- status = false
9
- openam = OpenamAuth::Openam.new
10
- cookie_name = openam.cookie_name
11
- token = openam.token_cookie(request, cookie_name)
12
-
13
- #The following class method shold be implemented by the parent application
14
- user = User.existing_user_by_token(token) if token
15
-
16
- unless user
17
- if openam.valid_token?(token)
18
- response = openam.openam_user(cookie_name, token)
19
- user_hash = openam.user_hash(response.body)
20
- #following class method should be implemented by the parent application
21
- user = User.update_openam_user(token, user_hash)
22
- end
23
- end
24
- if user
25
- session[:user_id] = user.id
26
- status = true
27
- end
28
- status ? true : (redirect_to openam.login_url)
29
- end
3
+ attr_accessor :openam_instance
4
+ extend ActiveSupport::Concern
5
+
6
+ def authenticate_user!
7
+ user ||= User.update_openam_user(token, user_hash) if openam.valid_token?(token)
8
+
9
+ session[:user_id] = user.id if user
10
+
11
+ !!session[:user_id] || redirect_to(openam.login_url)
30
12
  end
31
13
 
32
- def openam_logout(token)
33
- OpenamAuth::Openam.new.logout(token)
14
+ private
15
+ def openam
16
+ @openam_instance ||= OpenamAuth::Openam.new
17
+ @openam_instance
18
+ end
19
+
20
+ def cookie_name
21
+ openam.cookie_name
22
+ end
23
+
24
+ def token
25
+ openam.token_cookie(request, cookie_name)
26
+ end
27
+
28
+ def user
29
+ User.existing_user_by_token(token)
34
30
  end
35
31
 
36
32
  def current_user
37
33
  User.where(id: session[:user_id]).first
38
34
  end
39
35
 
40
- def self.included(receiver)
41
- receiver.extend ClassMethods
42
- receiver.send :include, InstanceMethods
36
+ def user_hash
37
+ openam.user_hash(openam_response.body)
38
+ end
39
+
40
+ def openam_response
41
+ openam.openam_user(cookie_name, token)
42
+ end
43
+
44
+ def openam_logout(token)
45
+ openam.new.logout(token)
43
46
  end
44
47
  end
45
48
  end
@@ -57,8 +57,6 @@ module OpenamAuth
57
57
  end
58
58
  opensso_user
59
59
  end
60
-
61
-
62
60
  end
63
61
  end
64
62
 
@@ -1,3 +1,3 @@
1
1
  module OpenamAuth
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/lib/openam_auth.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require 'active_support/concern'
1
2
  require "openam_auth/version"
2
3
  require "openam_auth/openam"
3
4
  require "openam_auth/authenticate"
@@ -47,7 +47,7 @@ EOF
47
47
  to_return(:status => 200, :body => response, :headers => {})
48
48
  end
49
49
 
50
- it "should return openam user string" do
50
+ fit "should return openam user string" do
51
51
  OpenamAuth::Openam.new.openam_user('iPlanetDirectoryPro',token).to_s.should eq(response)
52
52
  end
53
53
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openam_auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - sameera207
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-31 00:00:00.000000000 Z
11
+ date: 2014-04-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler