Class: NextAuthDecoder::Token

Inherits:
Object
  • Object
show all
Defined in:
lib/next_auth_decoder/token.rb

Instance Method Summary collapse

Constructor Details

#initialize(token, info: '', secret: ENV['NEXT_AUTH_SECRET'], length: 32) ⇒ Token



8
9
10
11
12
13
# File 'lib/next_auth_decoder/token.rb', line 8

def initialize(token, info: '', secret: ENV['NEXT_AUTH_SECRET'], length: 32)
  @token = token
  @info = info
  @length = length
  @secret = secret
end

Instance Method Details

#decodeObject



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/next_auth_decoder/token.rb', line 15

def decode
  raise error if invalid?
  JOSE::JWT
    .decrypt(jwk_secret, @token)
    .first
    .fields
    .to_h
rescue OpenSSL::Cipher::CipherError
  puts 'Error: Decryption error.'
  nil
end