@@ -10,6 +10,7 @@ abstract class OAuth2::AccessToken
10
10
scope = nil
11
11
mac_algorithm = nil
12
12
mac_key = nil
13
+ extra = nil
13
14
14
15
pull.read_object do |key |
15
16
case key
@@ -21,7 +22,8 @@ abstract class OAuth2::AccessToken
21
22
when " mac_algorithm" then mac_algorithm = pull.read_string
22
23
when " mac_key" then mac_key = pull.read_string
23
24
else
24
- raise " Uknown key in access token json: #{ key } "
25
+ extra ||= {} of String => String
26
+ extra[key] = pull.read_raw
25
27
end
26
28
end
27
29
@@ -30,9 +32,9 @@ abstract class OAuth2::AccessToken
30
32
if token_type
31
33
case token_type.downcase
32
34
when " bearer"
33
- Bearer .new(access_token, expires_in, refresh_token, scope)
35
+ Bearer .new(access_token, expires_in, refresh_token, scope, extra )
34
36
when " mac"
35
- Mac .new(access_token, expires_in, mac_algorithm.not_nil!, mac_key.not_nil!, refresh_token, scope)
37
+ Mac .new(access_token, expires_in, mac_algorithm.not_nil!, mac_key.not_nil!, refresh_token, scope, Time .now.epoch, extra )
36
38
else
37
39
raise " Uknown token_type in access token json: #{ token_type } "
38
40
end
@@ -46,7 +48,15 @@ abstract class OAuth2::AccessToken
46
48
property refresh_token : String ?
47
49
property scope : String ?
48
50
49
- def initialize (@access_token : String , expires_in : Int ?, @refresh_token : String ? = nil , @scope : String ? = nil )
51
+ # JSON key-value pairs that are outside of the OAuth2 spec are
52
+ # stored in this property in case they are needed. Their value
53
+ # is the raw JSON string found in the JSON value (with possible
54
+ # changes in the string format, but preserving JSON semantic).
55
+ # For example if the value was `[1, 2, 3]` then the value in this hash
56
+ # will be the string "[1,2,3]".
57
+ property extra : Hash (String , String )?
58
+
59
+ def initialize (@access_token : String , expires_in : Int ?, @refresh_token : String ? = nil , @scope : String ? = nil , @extra = nil )
50
60
@expires_in = expires_in.try & .to_i64
51
61
end
52
62
0 commit comments