lam_auth 0.1.3 → 0.1.4
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/lib/lam_auth/controller_extensions.rb +5 -5
- data/lib/lam_auth/model.rb +3 -3
- data/lib/lam_auth/version.rb +1 -1
- metadata +4 -4
@@ -9,7 +9,7 @@ module LamAuth
|
|
9
9
|
|
10
10
|
extend ClassMethods
|
11
11
|
include InstanceMethods
|
12
|
-
protected :logged_in?, :current_user, :current_user=, :
|
12
|
+
protected :logged_in?, :current_user, :current_user=, :access_token, :login_from_cookie, :login_required
|
13
13
|
end
|
14
14
|
|
15
15
|
module ClassMethods
|
@@ -32,16 +32,16 @@ module LamAuth
|
|
32
32
|
@current_user = new_user
|
33
33
|
end
|
34
34
|
|
35
|
-
def
|
35
|
+
def access_token
|
36
36
|
cookie = cookies[LamAuth.cookie_id]
|
37
|
-
|
37
|
+
LamAuth.valid_cookie?(cookie) && LamAuth.parse_cookie_to_hash(cookie)['access_token']
|
38
38
|
end
|
39
39
|
|
40
40
|
def login_from_cookie
|
41
41
|
if logged_in?
|
42
|
-
!
|
42
|
+
!access_token && self.current_user = nil
|
43
43
|
else
|
44
|
-
|
44
|
+
access_token && self.current_user = self.class.user_model_class.find_by_access_token(access_token)
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
data/lib/lam_auth/model.rb
CHANGED
@@ -10,12 +10,12 @@ module LamAuth
|
|
10
10
|
end
|
11
11
|
|
12
12
|
module ClassMethods
|
13
|
-
def
|
14
|
-
Rails.logger.info("Trying to authorize a token #{
|
13
|
+
def find_by_access_token(access_token)
|
14
|
+
Rails.logger.info("Trying to authorize a token #{access_token.inspect} ")
|
15
15
|
|
16
16
|
lam_uri = LamAuth.uri
|
17
17
|
http = Net::HTTP.new(lam_uri.host, lam_uri.port)
|
18
|
-
response, body = http.get("#{lam_uri.path}/users/me", {'Authorization' => "Token token=\"#{
|
18
|
+
response, body = http.get("#{lam_uri.path}/users/me", {'Authorization' => "Token token=\"#{access_token}\""})
|
19
19
|
if response.code == "200"
|
20
20
|
data = ActiveSupport::JSON.decode(body)
|
21
21
|
Rails.logger.info("...success: #{data.inspect}")
|
data/lib/lam_auth/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lam_auth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 4
|
10
|
+
version: 0.1.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Max Macovsky
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2011-
|
19
|
+
date: 2011-07-23 00:00:00 +04:00
|
20
20
|
default_executable:
|
21
21
|
dependencies: []
|
22
22
|
|