freeradius-oauth2-perl icon indicating copy to clipboard operation
freeradius-oauth2-perl copied to clipboard

Error parsing time at /usr/lib/x86_64-linux-gnu/perl/5.34/Time/Piece.pm line 598.

Open jimdigriz opened this issue 11 months ago • 1 comments

Probably something to fix whilst dealing with https://github.com/jimdigriz/freeradius-oauth2-perl/issues/13

On Mon, 18 Sep 2023, at 19:34, J R wrote:

I was setting up your code for authentication against Azure AD, but I received an error "Thread 2 terminated abnormally: Error parsing time at /usr/lib/x86_64-linux-gnu/perl/5.34/Time/Piece.pm line 598." when researching this. I found that changing from "Time::Piece" to "DateTime" solved the issue.

Here is the code change I made to successfully authenticate against azure.

File: main.pm

Added:

  • use DateTime;
  • use DateTime::Format::Strptime;

Commented out: if ($^V ge v5.28) { Time::Piece->use_locale(); } else { warn "old version of Perl (pre-5.28) detected, non-English locale users must run FreeRADIUS with LC_ALL=C"; } use constant RADTIME_FMT => '%b %e %Y %H:%M:%S %Z'; sub to_radtime { my ($s) = @_; return Time::Piece->strptime($s, '%Y-%m-%dT%H:%M:%SZ')->strftime(RADTIME_FMT); }

Replaced the commented out section with the following: if ($^V ge v5.28) { # No need for any specific action for DateTime } else { warn "old version of Perl (pre-5.28) detected, non-English locale users must run FreeRADIUS with LC_ALL=C"; }

use constant RADTIME_FMT => '%b %e %Y %H:%M:%S %Z';

my $strp = DateTime::Format::Strptime->new( pattern => '%Y-%m-%dT%H:%M:%SZ', time_zone => 'UTC', );

sub to_radtime { my ($s) = @_; my $dt = $strp->parse_datetime($s); return $dt->strftime(RADTIME_FMT); }

and then everything worked. credit goes to OpenAI for the new code.

jimdigriz avatar Sep 20 '23 10:09 jimdigriz

Replied:

On Mon, 18 Sep 2023, at 19:34, J R wrote:

I was setting up your code for authentication against Azure AD, but I received an error "Thread 2 terminated abnormally: Error parsing time at /usr/lib/x86_64-linux-gnu/perl/5.34/Time/Piece.pm line 598." when researching this. I found that changing from "Time::Piece" to "DateTime" solved the issue.

Thanks for picking up on this. I dropped your email into an issue so it gets captured and not lost.

jimdigriz avatar Sep 20 '23 10:09 jimdigriz