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.
-
#delete_account(localId) ⇒ Object
DELETES the account completely from firebase.
-
#get_user_by(key, value) ⇒ Resource
Get user by email/phone/uid.
-
#reset ⇒ Resource
Reset emulator.
-
#sign_in_for_uid(uid) ⇒ Resource
Sign in based on the UID of an account This generates a custom token for the UID and signs in using the custom token.
-
#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
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/firebase-admin/client/accounts.rb', line 133 def create_custom_token(uid) if service_account_email.nil? || service_account_email == '' raise InvalidCredentials, "No client email provided via options, 'GOOGLE_APPLICATION_CREDENTIALS' or 'GOOGLE_CLIENT_EMAIL'" end if service_account_private_key.nil? || service_account_private_key == '' raise InvalidCredentials, "No private key provided via options, 'GOOGLE_APPLICATION_CREDENTIALS' or 'GOOGLE_PRIVATE_KEY'" end 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, OpenSSL::PKey::RSA.new(unescape(service_account_private_key)), 'RS256') end |
#delete_account(localId) ⇒ Object
DELETES the account completely from firebase. Once deleted we can retreive the account Need to be used cautiously
73 74 75 76 77 |
# File 'lib/firebase-admin/client/accounts.rb', line 73 def delete_account(localId) params = {'localId': localId} path = "v1/projects/#{project_id}/accounts:delete" post path, params end |
#get_user_by(key, value) ⇒ Resource
Get user by email/phone/uid
165 166 167 168 169 170 |
# File 'lib/firebase-admin/client/accounts.rb', line 165 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
179 180 181 |
# File 'lib/firebase-admin/client/accounts.rb', line 179 def reset delete("emulator/v1/projects/#{project_id}/accounts") end |
#sign_in_for_uid(uid) ⇒ Resource
Sign in based on the UID of an account This generates a custom token for the UID and signs in using the custom token
119 120 121 122 |
# File 'lib/firebase-admin/client/accounts.rb', line 119 def sign_in_for_uid(uid) custom_token = create_custom_token(uid) sign_in_with_custom_token(custom_token) end |
#sign_in_with_custom_token(token) ⇒ Resource
Sign in with custom token
106 107 108 |
# File 'lib/firebase-admin/client/accounts.rb', line 106 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
)
94 95 96 |
# File 'lib/firebase-admin/client/accounts.rb', line 94 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 |