Module: FirebaseAdmin::Client::Accounts
- Included in:
- FirebaseAdmin::Client
- Defined in:
- lib/firebase-admin/client/accounts.rb
Overview
Defines methods related to accounts
Instance Method Summary collapse
-
#create_account(params) ⇒ Resource
Create a new account.
-
#create_custom_token(uid) ⇒ String
Create a custom JWT token for a UID.
-
#get_user_by(key, value) ⇒ Resource
Get user by email/phone/uid.
-
#reset ⇒ Resource
Reset emulator.
-
#sign_in_with_custom_token(token) ⇒ Resource
Sign in with custom token.
-
#sign_in_with_password(params) ⇒ Resource
Sign in with a password.
-
#update_account(params) ⇒ Resource
Update an existing account.
Instance Method Details
#create_account(params) ⇒ Resource
Create a new account
)
32 33 34 |
# File 'lib/firebase-admin/client/accounts.rb', line 32 def create_account(params) post("v1/projects/#{project_id}/accounts", params) end |
#create_custom_token(uid) ⇒ String
Create a custom JWT token for a UID
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/firebase-admin/client/accounts.rb', line 105 def create_custom_token(uid) credentials = default_credentials service_account_email = credentials.fetch('client_email', ENV['GOOGLE_CLIENT_EMAIL']) private_key = OpenSSL::PKey::RSA.new credentials.fetch('private_key', ENV['GOOGLE_PRIVATE_KEY']) now_seconds = Time.now.to_i payload = { iss: service_account_email, sub: service_account_email, aud: 'https://identitytoolkit.googleapis.com/google.identity.identitytoolkit.v1.IdentityToolkit', iat: now_seconds, exp: now_seconds + (60 * 60), # Maximum expiration time is one hour uid: uid } JWT.encode(payload, private_key, 'RS256') end |
#get_user_by(key, value) ⇒ Resource
Get user by email/phone/uid
132 133 134 135 136 137 |
# File 'lib/firebase-admin/client/accounts.rb', line 132 def get_user_by(key, value) params = {} params[key] = Array(value) response = post('v1/accounts:lookup', params) (response[:users] || []).first end |
#reset ⇒ Resource
Reset emulator
146 147 148 |
# File 'lib/firebase-admin/client/accounts.rb', line 146 def reset delete("emulator/v1/projects/#{project_id}/accounts") end |
#sign_in_with_custom_token(token) ⇒ Resource
Sign in with custom token
92 93 94 |
# File 'lib/firebase-admin/client/accounts.rb', line 92 def sign_in_with_custom_token(token) post('v1/accounts:signInWithCustomToken', { token: token, returnSecureToken: true }) end |
#sign_in_with_password(params) ⇒ Resource
Sign in with a password
)
80 81 82 |
# File 'lib/firebase-admin/client/accounts.rb', line 80 def sign_in_with_password(params) post('v1/accounts:signInWithPassword', params) end |
#update_account(params) ⇒ Resource
Update an existing account
)
62 63 64 |
# File 'lib/firebase-admin/client/accounts.rb', line 62 def update_account(params) post("v1/projects/#{project_id}/accounts:update", params) end |