capcoauth 0.2.0 → 0.2.1
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.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 88d88d5d24669f7c09057d039ed04bcf8f7e4215
|
4
|
+
data.tar.gz: e3126ba3d76375574f63dd3b7f65177e66f1a781
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c7ed882f4e5786775fa4f858c994398f6bd01720f27ea2da660eec2dd2ae2e3f1d98029c50a9ce49b2c45a2292d0bfd54430d5a87deb13e467739a842022fbc3
|
7
|
+
data.tar.gz: c41136838fe6f2e529b2f290a1b27e7860983c756e089e1751bb3bece86c61bf9d54598c38741a077357fc161ba2f3c2222224a24f8d8104f8c0f48fdced2b84
|
@@ -9,7 +9,7 @@ module Capcoauth
|
|
9
9
|
|
10
10
|
def self.verify(access_token)
|
11
11
|
raise UnauthorizedError if access_token.blank? or access_token.token.blank?
|
12
|
-
return access_token if TTLCache.
|
12
|
+
return access_token if TTLCache.user_id_for(access_token.token)
|
13
13
|
|
14
14
|
# Call Capcoauth
|
15
15
|
response = ::HTTParty.get("#{Capcoauth.configuration.capcoauth_url}/oauth/token/info", {
|
@@ -23,7 +23,7 @@ module Capcoauth
|
|
23
23
|
access_token.user_id = response.parsed_response['resource_owner_id']
|
24
24
|
if response.parsed_response.fetch('application', {}).fetch('uid', nil) === Capcoauth.configuration.client_id
|
25
25
|
logger.info("CapcOAuth: The access token for user ##{access_token.user_id} was verified successfully") unless logger.nil?
|
26
|
-
TTLCache.update(access_token.token)
|
26
|
+
TTLCache.update(access_token.token, access_token.user_id)
|
27
27
|
access_token
|
28
28
|
else
|
29
29
|
logger.info("CapcOAuth: The access token for user ##{access_token.user_id} was valid, but for a different OAuth client ID") unless logger.nil?
|
@@ -3,13 +3,14 @@ module Capcoauth
|
|
3
3
|
class TTLCache
|
4
4
|
@@cache = {}
|
5
5
|
|
6
|
-
def self.
|
6
|
+
def self.user_id_for(access_token)
|
7
7
|
purge
|
8
|
-
|
8
|
+
return @@cache[access_token][:user_id] if @@cache[access_token].present?
|
9
|
+
nil
|
9
10
|
end
|
10
11
|
|
11
|
-
def self.update(access_token)
|
12
|
-
@@cache[access_token] = Time.zone.now
|
12
|
+
def self.update(access_token, user_id)
|
13
|
+
@@cache[access_token] = { last_checked: Time.zone.now, user_id: user_id }
|
13
14
|
end
|
14
15
|
|
15
16
|
def self.remove(access_token)
|
@@ -18,7 +19,7 @@ module Capcoauth
|
|
18
19
|
|
19
20
|
def self.purge
|
20
21
|
@@cache.delete_if do |k, v|
|
21
|
-
Time.zone.now > v + Capcoauth.configuration.token_verify_ttl
|
22
|
+
Time.zone.now > v[:last_checked] + Capcoauth.configuration.token_verify_ttl
|
22
23
|
end
|
23
24
|
end
|
24
25
|
end
|
data/lib/capcoauth/version.rb
CHANGED