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_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
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/firebase-admin/client/accounts.rb', line 119 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 |
#get_user_by(key, value) ⇒ Resource
Get user by email/phone/uid
151 152 153 154 155 156 |
# File 'lib/firebase-admin/client/accounts.rb', line 151 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
165 166 167 |
# File 'lib/firebase-admin/client/accounts.rb', line 165 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
105 106 107 108 |
# File 'lib/firebase-admin/client/accounts.rb', line 105 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
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 |