stravaweb 0.0.1 → 0.0.2
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/stravaweb/fetch.rb +23 -0
- data/lib/stravaweb/version.rb +1 -1
- 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: 01af368370c6506d43d0b866a22f8e8a2d9ef87f658739040dc5651891db842d
|
|
4
|
+
data.tar.gz: f98532d5f405dd33ad1a2f261e864d6df74cba19b5820dbc93b2ba4bfe471f40
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c709dc01fef28e7287161b48313b2838fc2898de795a37bb5a3e5b72f964634d545cebc049b2f736d81d3f804fab646d6a80ff8f55795ba64339d1ce604ba97a
|
|
7
|
+
data.tar.gz: d73f627e987704e621a26b6effcd6a537e8e9a1f979b7705ce2a90cec32ee77fa8481cb1771c8e68bf285238d30614bc12b6043a390db94cd420e00823affad0
|
data/lib/stravaweb/fetch.rb
CHANGED
|
@@ -29,6 +29,8 @@ module StravaWeb
|
|
|
29
29
|
class Fetch
|
|
30
30
|
AUTH_HELP = "Set sync.strava.web_auth.jwt in config.yml — see docs/strava-web-auth.md".freeze
|
|
31
31
|
|
|
32
|
+
attr_reader :expires_at
|
|
33
|
+
|
|
32
34
|
def initialize(jwt: nil, auth_seed: nil, cookie_path: nil)
|
|
33
35
|
@cookie_path = cookie_path
|
|
34
36
|
@jar = HTTP::CookieJar.new
|
|
@@ -40,8 +42,10 @@ module StravaWeb
|
|
|
40
42
|
explicit = jwt || (auth_seed && !auth_seed.to_s.strip.empty?)
|
|
41
43
|
|
|
42
44
|
if explicit
|
|
45
|
+
@expires_at = decode_exp(jwt)
|
|
43
46
|
login_with_jwt(jwt)
|
|
44
47
|
elsif authenticated?
|
|
48
|
+
@expires_at = decode_exp(cookie_token)
|
|
45
49
|
return
|
|
46
50
|
else
|
|
47
51
|
raise AuthError, "no web session — set jwt or auth_seed\n#{AUTH_HELP}"
|
|
@@ -118,6 +122,25 @@ module StravaWeb
|
|
|
118
122
|
seed.to_s.strip
|
|
119
123
|
end
|
|
120
124
|
|
|
125
|
+
def decode_exp(jwt)
|
|
126
|
+
parts = jwt.split(".")
|
|
127
|
+
return nil unless parts.length == 3
|
|
128
|
+
|
|
129
|
+
payload = parts[1]
|
|
130
|
+
payload += "=" * (4 - payload.length % 4) if payload.length % 4 != 0
|
|
131
|
+
|
|
132
|
+
data = JSON.parse(Base64.decode64(payload))
|
|
133
|
+
exp = data["exp"]
|
|
134
|
+
Time.at(exp) if exp.is_a?(Numeric)
|
|
135
|
+
rescue StandardError
|
|
136
|
+
nil
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
def cookie_token
|
|
140
|
+
cookie = @jar.cookies(URI(BASE_URL)).find { |c| c.name == "strava_remember_token" }
|
|
141
|
+
cookie && cookie.value
|
|
142
|
+
end
|
|
143
|
+
|
|
121
144
|
def login_with_jwt(jwt)
|
|
122
145
|
jwt = jwt.to_s.strip
|
|
123
146
|
raise AuthError, "jwt is empty" if jwt.empty?
|
data/lib/stravaweb/version.rb
CHANGED