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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 14cb7266c37ca3ff99cf6d0fe56fbda38ddc78dc9000e054f893292d305a7806
4
- data.tar.gz: a45823ef0f68109c8ee591b4eb07fdd00215e0e7acfa49bbffcb8eef744eefed
3
+ metadata.gz: 01af368370c6506d43d0b866a22f8e8a2d9ef87f658739040dc5651891db842d
4
+ data.tar.gz: f98532d5f405dd33ad1a2f261e864d6df74cba19b5820dbc93b2ba4bfe471f40
5
5
  SHA512:
6
- metadata.gz: fc5fbed31cbee20560af59302e60213a0a03d6e769865e3b32657320cb5f0bbaa835fbb75a1d19615b23787cdedfbda2675efe042194f391b6aeb1698cfd7057
7
- data.tar.gz: 0baac02ed5abea6f947fd29faa776131c6f69d0d8b1d1182978b8cf93b8bd9ae7e58a0910dbf38b92ebd73ce7cc3838df25f86b1c41b5129488c41b3c8e47c17
6
+ metadata.gz: c709dc01fef28e7287161b48313b2838fc2898de795a37bb5a3e5b72f964634d545cebc049b2f736d81d3f804fab646d6a80ff8f55795ba64339d1ce604ba97a
7
+ data.tar.gz: d73f627e987704e621a26b6effcd6a537e8e9a1f979b7705ce2a90cec32ee77fa8481cb1771c8e68bf285238d30614bc12b6043a390db94cd420e00823affad0
@@ -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?
@@ -1,3 +1,3 @@
1
1
  module StravaWeb
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stravaweb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lax