class GraphQL::Auth::JwtManager

Constants

ALGORITHM
TYPE

Public Class Methods

decode(token) click to toggle source
# File lib/graphql-auth/jwt_manager.rb, line 33
def decode(token)
  token = extract_token token
  decrypted_token = JWT.decode token,
                               auth_secret,
                               true,
                               { algorithm: ALGORITHM }
  decrypted_token.first
end
issue(payload) click to toggle source
# File lib/graphql-auth/jwt_manager.rb, line 21
def issue(payload)
  token = JWT.encode payload,
                     auth_secret,
                     ALGORITHM
  set_type token
end
Also aliased as: issue_without_expiration
issue_with_expiration(payload, custom_expiration = nil) click to toggle source
# File lib/graphql-auth/jwt_manager.rb, line 11
def issue_with_expiration(payload, custom_expiration = nil)
  if custom_expiration.present? && custom_expiration.is_a?(ActiveSupport::Duration)
    payload[:exp] = custom_expiration
  else
    payload.merge!(expiration)
  end

  issue payload
end
token_expiration(token) click to toggle source
# File lib/graphql-auth/jwt_manager.rb, line 28
def token_expiration(token)
  decrypted_token = decode(token)
  decrypted_token.try(:[], 'exp')
end

Private Class Methods

auth_secret() click to toggle source
# File lib/graphql-auth/jwt_manager.rb, line 44
def auth_secret
  GraphQL::Auth.configuration.jwt_secret_key
end
expiration() click to toggle source
# File lib/graphql-auth/jwt_manager.rb, line 56
def expiration
  exp = Time.now.to_i + GraphQL::Auth.configuration.token_lifespan
  { exp: exp }
end
extract_token(token) click to toggle source
# File lib/graphql-auth/jwt_manager.rb, line 52
def extract_token(token)
  token.gsub "#{TYPE} ", ''
end
issue_without_expiration(payload)
Alias for: issue
set_type(token) click to toggle source
# File lib/graphql-auth/jwt_manager.rb, line 48
def set_type(token)
  "#{TYPE} #{token}"
end