Class: FirebaseRepository

Inherits:
Ibrain::BaseRepository
  • Object
show all
Defined in:
app/repositories/firebase_repository.rb

Instance Method Summary collapse

Constructor Details

#initialize(record, params) ⇒ FirebaseRepository

Returns a new instance of FirebaseRepository.



6
7
8
9
10
11
12
# File 'app/repositories/firebase_repository.rb', line 6

def initialize(record, params)
  super(nil, record)

  @private_key_json = load_private_file
  @firebase_owner_email = Ibrain::Auth::Config.firebase_owner_email
  @params = params
end

Instance Method Details

#generate_custom_token!Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/repositories/firebase_repository.rb', line 14

def generate_custom_token!
  iat = Time.now.to_i
  exp = 60.minutes.from_now.to_i
  uid = retrieve_uid_execution

  raise IbrainErrors::UnknownError.new I18n.t("ibrain.errors.custom_token.not_retrieve_uid") unless uid

  payload = {
    iss: firebase_owner_email,
    sub: firebase_owner_email,
    aud: Ibrain::Auth::Config.firebase_auth_url,
    iat: iat,
    exp: exp,
    uid: uid,
    claims: {}
  }

  JWT.encode payload, private_key, "RS256"
end