Sha256: c1d0144f8314e39624009ec328b6769eeb4cde6ad7251e833dffebd20dee459a

Contents?: true

Size: 888 Bytes

Versions: 1

Compression:

Stored size: 888 Bytes

Contents

# frozen_string_literal: true

class FirebaseRepository < Ibrain::BaseRepository
  def initialize(record, _params)
    super(nil, record)

    @private_key_json = File.open(Ibrain::Auth::Config.firebase_private_key_path).read
    @firebase_owner_email = Ibrain::Auth::Config.firebase_owner_email
  end

  def generate_custom_token!
    now = Time.now.to_i

    payload = {
      iss: firebase_owner_email,
      sub: firebase_owner_email,
      aud: Ibrain::Auth::Config.firebase_auth_url,
      iat: now,
      exp: now + 3600,
      uid: params[:uid],
      claims: {}
    }

    JWT.encode payload, private_key, "RS256"
  end

  private

  attr_reader :private_key_json, :firebase_owner_email

  def method_name
  end

  def json_firebase
    JSON.parse(private_key_json, symbolize_names: true)
  end

  def private_key
    OpenSSL::PKey::RSA.new json_firebase[:private_key]
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ibrain-auth-0.3.1 app/repositories/firebase_repository.rb