blockstack 0.5.1 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/blockstack/version.rb +1 -1
- data/lib/blockstack.rb +36 -5
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2d182963e3410d64223d4e5617b937dacdb0ddde
|
4
|
+
data.tar.gz: 9ea95bcb1501f22f18dddbeffa11a572971334ff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9072263456ede40a861129b34c6e96d7960c4a60f7dbaa480600aa30947e1bb44a415ba75b5ba14110bb5d1a31dd71aec9afb254ef0a30a35592dce17e782aea
|
7
|
+
data.tar.gz: da42e8b8dc4526fac002e79e509a82b82a238b76c1579e4456711ddcf9a5827ce02373fe4ca0ef2fb3484d9528283bd7c7b12563025d03230db52dd22163a76d
|
data/lib/blockstack/version.rb
CHANGED
data/lib/blockstack.rb
CHANGED
@@ -4,14 +4,39 @@ require "faraday"
|
|
4
4
|
require "jwt"
|
5
5
|
|
6
6
|
module Blockstack
|
7
|
+
class InvalidAuthResponse < StandardError; end
|
8
|
+
|
7
9
|
USER_AGENT = "blockstack-ruby #{VERSION}"
|
8
10
|
ALGORITHM = "ES256K"
|
9
11
|
REQUIRED_CLAIMS = %w(iss iat jti exp username profile publicKeys)
|
10
|
-
LEEWAY = 300 # seconds
|
11
|
-
VALID_WITHIN = 300 # seconds
|
12
|
-
BLOCKSTACK_API = "http://localhost:6270"
|
13
12
|
|
14
|
-
|
13
|
+
DEFAULT_LEEWAY = 30 # seconds
|
14
|
+
DEFAULT_VALID_WITHIN = 30 # seconds
|
15
|
+
DEFAULT_API = "http://localhost:6270"
|
16
|
+
|
17
|
+
def self.api=(api)
|
18
|
+
@@api = api.nil? ? DEFAULT_API : api
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.api
|
22
|
+
@@api
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.leeway=(leeway)
|
26
|
+
@@leeway = leeway.nil? ? DEFAULT_LEEWAY : leeway
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.leeway
|
30
|
+
@@leeway
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.valid_within=(valid_within)
|
34
|
+
@@valid_within = valid_within.nil? ? DEFAULT_VALID_WITHIN : valid_within
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.valid_within
|
38
|
+
@@valid_within
|
39
|
+
end
|
15
40
|
|
16
41
|
def self.verify_auth_response(auth_token)
|
17
42
|
# decode & verify token without checking signature so we can extract
|
@@ -20,7 +45,7 @@ module Blockstack
|
|
20
45
|
verify = false
|
21
46
|
decoded_tokens = JWT.decode auth_token, public_key, verify, algorithm: ALGORITHM
|
22
47
|
decoded_token = decoded_tokens[0]
|
23
|
-
|
48
|
+
|
24
49
|
REQUIRED_CLAIMS.each do |field|
|
25
50
|
raise InvalidAuthResponse.new("Missing required '#{field}' claim.") if !decoded_token.key?(field.to_s)
|
26
51
|
end
|
@@ -102,4 +127,10 @@ module Blockstack
|
|
102
127
|
connection.headers[:user_agent] = USER_AGENT
|
103
128
|
connection
|
104
129
|
end
|
130
|
+
|
131
|
+
private
|
132
|
+
|
133
|
+
@@leeway = DEFAULT_LEEWAY
|
134
|
+
@@valid_within = DEFAULT_VALID_WITHIN
|
135
|
+
@@api = DEFAULT_API
|
105
136
|
end
|