We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent f6f2281 commit 041cf22Copy full SHA for 041cf22
lib/jwt_util.rb
@@ -0,0 +1,28 @@
1
+module JWTUtil
2
+ include RSAUtil
3
+
4
+ def self::encode(user)
5
+ JWT.encode(
6
+ {
7
+ iss: 'probably digitalocean or some shit',
8
+ iat: Time.now.to_i,
9
+ sub: user.id + '.' + Time.now.to_s
10
+ },
11
+ OpenSSL::PKey::RSA.new(RSAUtil::Keys::priv, ENV['PASSPHRASE']),
12
+ 'RS256'
13
+ )
14
+ end
15
16
+ def self::decode(token)
17
+ begin
18
+ JWT.decode(
19
+ token,
20
+ OpenSSL::PKey::RSA.new(RSAUtil::Keys::pub, ENV['PASSPHRASE']),
21
+ true,
22
+ { algorithm: 'RS256' }
23
24
+ rescue JWT::DecodeError
25
+ return nil
26
27
28
+end
0 commit comments