oauth2-checker 0.1.0 → 0.2.0
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 +4 -4
- data/lib/oauth2/checker.rb +10 -15
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a13681001a07a13b77eb53f1e7c8bf2f75240a5d
|
4
|
+
data.tar.gz: e67b162a1aefa0fd698d7804987089daa4b78a47
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a060caf95b0e9cd199b6baf960db72a3fec7a6deafdfe17e1d0dfabac00167e1f3fbf2b0e7e8bea1430baffe4b78bba406c0c0c8f6da302a2da0d8521d8f4e38
|
7
|
+
data.tar.gz: 82601ac65c50a2b82959294e1847037e8832fa41e52c41625bb295213fe3c80babff542badaa92da67e2e2b2655618feb0406868f00050515758f2bb8e578e37
|
data/lib/oauth2/checker.rb
CHANGED
@@ -1,32 +1,27 @@
|
|
1
1
|
require 'oauth2'
|
2
2
|
|
3
3
|
class OAuth2::Checker
|
4
|
+
attr_reader :client
|
4
5
|
def initialize(client_id, client_secret, options = {}, &block)
|
5
6
|
@client = OAuth2::Client.new(client_id, client_secret, options, &block)
|
6
7
|
end
|
7
8
|
|
8
9
|
def check_access_token(token)
|
9
|
-
|
10
|
-
# at = AccessToken.where(token: token).take
|
11
|
-
|
12
|
-
# try to check if token is still valid with oauth provider
|
13
|
-
begin
|
14
|
-
# try to do a request to the oauth provider
|
15
|
-
req = @client.request(:get, "oauth/token/info", {:params => {:access_token => token}})
|
16
|
-
# if i got here, the request was success => token is valid
|
17
|
-
return token
|
18
|
-
rescue
|
19
|
-
# unexisting or expired token, access denied
|
20
|
-
return false
|
21
|
-
end
|
10
|
+
validate(token)[0]
|
22
11
|
end
|
23
12
|
|
24
13
|
def get_resource_owner(token)
|
14
|
+
owner = validate(token)[1]
|
15
|
+
owner.nil? ? 'undefined' : owner
|
16
|
+
end
|
17
|
+
|
18
|
+
## validates the token and return [valid (boolen), resource_owner_id (string or nil)]
|
19
|
+
def validate(token)
|
25
20
|
begin
|
26
21
|
req = @client.request(:get, "oauth/token/info", {:params => {:access_token => token}})
|
27
|
-
return req.parsed["resource_owner_id"]
|
22
|
+
return [true, req.parsed["resource_owner_id"]]
|
28
23
|
rescue
|
29
|
-
return
|
24
|
+
return [false, nil]
|
30
25
|
end
|
31
26
|
end
|
32
27
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oauth2-checker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sandro Mehic
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-
|
12
|
+
date: 2016-11-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: oauth2
|