diff options
author | Daniel Friesel <derf@finalrewind.org> | 2020-10-04 10:38:09 +0200 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2020-10-04 10:38:09 +0200 |
commit | 80b02a47b443280a7b8876c45c2bad0b605a7968 (patch) | |
tree | f1871d61c6044c326de1a4724ebbd737d0fb3431 /lib/Travelynx/Helper/Traewelling.pm | |
parent | 5e2813e36eae43372842b85b0424309b7147678b (diff) |
Traewelling: Warn when bearer token is about to expire
Diffstat (limited to 'lib/Travelynx/Helper/Traewelling.pm')
-rw-r--r-- | lib/Travelynx/Helper/Traewelling.pm | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/lib/Travelynx/Helper/Traewelling.pm b/lib/Travelynx/Helper/Traewelling.pm index 1b94aa0..6d7c367 100644 --- a/lib/Travelynx/Helper/Traewelling.pm +++ b/lib/Travelynx/Helper/Traewelling.pm @@ -4,6 +4,8 @@ use strict; use warnings; use 5.020; +use DateTime; +use DateTime::Format::Strptime; use Mojo::Promise; sub new { @@ -182,10 +184,16 @@ sub login_p { } else { $token = $tx->result->json->{token}; + + # As of 2020-10-04, Traewelling tokens expire one year after they + # are generated + my $expiry_dt = DateTime->now( time_zone => 'Europe/Berlin' ) + ->add( years => 1 ); $self->{model}->link( - uid => $uid, - email => $email, - token => $token + uid => $uid, + email => $email, + token => $token, + expires => $expiry_dt ); return $self->get_user_p( $uid, $token ); } |