safie 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/safie/access_token.rb +30 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c322e6bbb628507a172dcfc47d18d0b0a235e5360cd3e2437a78f931548c67a2
|
4
|
+
data.tar.gz: bc16514d4641816bb8d09c36de3a148fe4878fbdd843479094fbd7df692fb103
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8368d23b5456a5c98227bcc53e9bf40be9141916229671021348e700cb07e80abab1c4243919f7ceca10ae83ea63ac77e5c87546a28ec16890f1ea446780e777
|
7
|
+
data.tar.gz: 659cb03e5750197c76d7f7e65e948c4626a86567a188919cac430e60b7e75c93fa428a555aace554b8952ffa0e00cdd12ee170a892f6122be3cc063d96504348
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.2
|
data/lib/safie/access_token.rb
CHANGED
@@ -6,8 +6,36 @@ module Safie
|
|
6
6
|
super attributes.merge(access_token: access_token)
|
7
7
|
end
|
8
8
|
|
9
|
-
def token_info!
|
10
|
-
|
9
|
+
def token_info!(params = {})
|
10
|
+
resource_request do
|
11
|
+
get File.join(ISSUER, '/auth/tokeninfo'), params
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def user_info!(params = {})
|
16
|
+
token_info = token_info! params
|
17
|
+
{
|
18
|
+
sub: token_info[:user_id],
|
19
|
+
email: token_info[:mail_address]
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def resource_request
|
26
|
+
res = yield
|
27
|
+
case res.status
|
28
|
+
when 200
|
29
|
+
JSON.parse(res.body).with_indifferent_access
|
30
|
+
when 400
|
31
|
+
raise BadRequest.new('API Access Faild', res)
|
32
|
+
when 401
|
33
|
+
raise Unauthorized.new('Access Token Invalid or Expired', res)
|
34
|
+
when 403
|
35
|
+
raise Forbidden.new('Insufficient Scope', res)
|
36
|
+
else
|
37
|
+
raise HttpError.new(res.status, 'Unknown HttpError', res)
|
38
|
+
end
|
11
39
|
end
|
12
40
|
end
|
13
41
|
end
|