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.



4
5
6
7
8
9
# File 'app/repositories/firebase_repository.rb', line 4

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

Instance Method Details

#generate_custom_token!Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/repositories/firebase_repository.rb', line 11

def generate_custom_token!
  now = Time.now.to_i

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

  JWT.encode payload, private_key, "RS256"
end