crystal-community/jwt

update for crystal 0.31.1 ?

Closed this issue · 8 comments

Attempting to run one of the examples (basic_usage.cr) results in the following:

aaron@t430:~/Documents/ogreets/OGV3/lib/jwt$ shards install
Fetching https://github.com/stakach/openssl_ext.git
Installing openssl_ext (1.0.0)
aaron@t430:~/Documents/ogreets/OGV3/lib/jwt$ crystal run examples/basic_usage.cr 
In src/jwt.cr:116:29

 116 | if exp.to_s.to_i < Time.now.to_unix
                               ^--
Warning: Deprecated Time.now. Use `Time.local` or `Time.utc` instead.

In src/jwt.cr:122:29

 122 | if nbf.to_s.to_i > Time.now.to_unix
                               ^--
Warning: Deprecated Time.now. Use `Time.local` or `Time.utc` instead.

A total of 2 warnings were found.
"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJmb28iOiJiYXIifQ.Y3shN5Wh4FmOPM34biIm9QQmat373hJFKNxgSANQWJo"
{"foo" => "bar"}
{"typ" => "JWT", "alg" => "HS256"}
aaron@t430:~/Documents/ogreets/OGV3/lib/jwt$ 

I used this lib successfully for one year with crystal 0.25.1
Attempts at encode/decode using this lib in my app @0.31.1 produces the following:


17 | token = JWT.encode(uh, "secretpass", JWT::Algorithm::HS256)
                  ^-----
Error: instantiating 'JWT:Module#encode(Hash(String, Bool | Int32 | String | Nil), String, JWT::Algorithm)'


In lib/jwt/src/jwt.cr:25:17

 25 | segments << encoded_signature(algorithm, key, segments.join("."))
                  ^----------------
Error: instantiating 'encoded_signature(JWT::Algorithm, String, String)'


In lib/jwt/src/jwt.cr:88:17

 88 | signature = sign(algorithm, key, data)
                  ^---
Error: instantiating 'sign(JWT::Algorithm, String, String)'


In lib/jwt/src/jwt.cr:102:20

 102 | OpenSSL::RSA.new(key).sign(OpenSSL::Digest.new("sha256"), data)
                    ^--
Error: instantiating 'OpenSSL::RSA.class#new(String)'


In lib/openssl_ext/src/openssl_ext/pkey.cr:16:5

 16 | def self.new(encoded : String, passphrase = nil, is_private = true)
      ^--
Error: instantiating 'new(String, Nil, Bool)'


In lib/openssl_ext/src/openssl_ext/pkey.cr:18:12

 18 | self.new(IO::Memory.new(encoded), passphrase, is_private)
           ^--
Error: instantiating 'OpenSSL::RSA.class#new(IO::Memory, Nil, Bool)'


In lib/openssl_ext/src/openssl_ext/pkey.cr:24:26

 24 | bio = GETS_BIO.new(io)
                     ^--
Error: instantiating 'OpenSSL::GETS_BIO.class#new(IO::Memory)'


In lib/openssl_ext/src/openssl_ext/bio.cr:16:10

 16 | io.seek(position)
         ^---
Error: instantiating 'IO+#seek((Int32 | Int64))'

I confess to total ignorance of OpenSSL::RSA, as I can't even find it...
https://crystal-lang.org/api/0.31.1/OpenSSL.html
(the RSA part... OpenSSL is there...)

I could totally be conflating my own errors with lib errors, so any light you can give is most appreciated...

Interesting that this repo's shard.yml doesn't have a crystal version number.
(I had cloned it locally with a version that worked with Crystal 0.25.1, aka JWT version 0.3.0)

When I attempt to run the examples/basic_usage.cr under Crystal 0.25.1 & 0.26.1 I can no longer do so, so it's been updated since... (errorsrelate to Time stuff in Crystal that changed since then.)

Crystal 0.27.1 runs the examples fine.

What I am confused about, is how are all these other frameworks that already are updated to 0.31.1 using this lib just fine?

never mind... Time.now got changed to Time.utc already... somehow I don't have this change locally from a shards install yesterday...

Hmmm a shards install still pulls a jwt.cr that has Time.now on lines 116 and 122...

But your repo looks proper at Time.utc...I'm confused.

So, git-cloned your repo, and the examples build fine.
I'll close this issue, but I'd like to know why a shards install grabs old code with Time.now

The earlier OpenSSL::RSA issue is obviously my own problem, as it's basically right off the "basic_usage.cr" example.

Looks like master was updated here: f55d2e8 but it hasn't been released yet.

You can change your shards to use branch: master

ah! thanks for the git/shards tip!

Ahh my bad. I've released a new version with the time fixes