class Fb::Jwt::Auth::ServiceAccessToken

Attributes

encoded_private_key[R]
issuer[R]
namespace[R]
subject[R]

Public Class Methods

new(subject: nil, issuer: nil) click to toggle source
# File lib/fb/jwt/auth/service_access_token.rb, line 10
def initialize(subject: nil, issuer: nil)
  @subject = subject
  @encoded_private_key = Fb::Jwt::Auth.encoded_private_key
  @namespace = Fb::Jwt::Auth.namespace
  @issuer = issuer || Fb::Jwt::Auth.issuer
end

Public Instance Methods

generate() click to toggle source
# File lib/fb/jwt/auth/service_access_token.rb, line 17
def generate
  return '' if encoded_private_key.blank?

  private_key = OpenSSL::PKey::RSA.new(encoded_private_key.chomp)

  JWT.encode(
    token,
    private_key,
    'RS256'
  )
end

Private Instance Methods

token() click to toggle source
# File lib/fb/jwt/auth/service_access_token.rb, line 31
def token
  payload = {
    iss: issuer,
    iat: Time.current.to_i
  }
  payload[:sub] = subject if subject.present?
  payload[:namespace] = namespace if namespace.present?
  payload
end