Class: Firebase::Admin::Auth::UserManager
- Inherits:
-
Object
- Object
- Firebase::Admin::Auth::UserManager
- Includes:
- Utils
- Defined in:
- lib/firebase/admin/auth/user_manager.rb
Overview
Provides methods for interacting with the Google Identity Toolkit
Constant Summary
Constants included from Utils
Firebase::Admin::Auth::Utils::AUTH_EMULATOR_HOST_VAR, Firebase::Admin::Auth::Utils::HOSTNAME_PATTERN, Firebase::Admin::Auth::Utils::INVALID_CHARS_PATTERN, Firebase::Admin::Auth::Utils::PATHNAME_PATTERN
Instance Method Summary collapse
-
#create_user(uid: nil, display_name: nil, email: nil, email_verified: nil, phone_number: nil, photo_url: nil, password: nil, disabled: nil) ⇒ UserRecord
Creates a new user account with the specified properties.
-
#delete_user(uid) ⇒ Object
Deletes the user corresponding to the specified user id.
-
#get_user_by(query) ⇒ UserRecord
Gets the user corresponding to the provided key.
-
#initialize(project_id, credentials, url_override = nil) ⇒ UserManager
constructor
Initializes a UserManager.
Methods included from Utils
get_emulator_host, get_emulator_v1_url, is_emulated?, #to_boolean, #validate_display_name, #validate_email, #validate_password, #validate_phone_number, #validate_photo_url, #validate_uid, validate_url
Constructor Details
#initialize(project_id, credentials, url_override = nil) ⇒ UserManager
Initializes a UserManager.
14 15 16 17 18 |
# File 'lib/firebase/admin/auth/user_manager.rb', line 14 def initialize(project_id, credentials, url_override = nil) uri = "#{url_override || ID_TOOLKIT_URL}/" @project_id = project_id @client = Firebase::Admin::Internal::HTTPClient.new(uri: uri, credentials: credentials) end |
Instance Method Details
#create_user(uid: nil, display_name: nil, email: nil, email_verified: nil, phone_number: nil, photo_url: nil, password: nil, disabled: nil) ⇒ UserRecord
Creates a new user account with the specified properties.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/firebase/admin/auth/user_manager.rb', line 34 def create_user(uid: nil, display_name: nil, email: nil, email_verified: nil, phone_number: nil, photo_url: nil, password: nil, disabled: nil) payload = { localId: validate_uid(uid), displayName: validate_display_name(display_name), email: validate_email(email), phoneNumber: validate_phone_number(phone_number), photoUrl: validate_photo_url(photo_url), password: validate_password(password), emailVerified: to_boolean(email_verified), disabled: to_boolean(disabled) }.compact res = @client.post(with_path("accounts"), payload).body uid = res&.fetch("localId") raise CreateUserError, "failed to create user #{res}" if uid.nil? get_user_by(uid: uid) end |
#delete_user(uid) ⇒ Object
Deletes the user corresponding to the specified user id.
78 79 80 |
# File 'lib/firebase/admin/auth/user_manager.rb', line 78 def delete_user(uid) @client.post(with_path("accounts:delete"), {localId: validate_uid(uid, required: true)}) end |
#get_user_by(query) ⇒ UserRecord
Gets the user corresponding to the provided key
59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/firebase/admin/auth/user_manager.rb', line 59 def get_user_by(query) if (uid = query[:uid]) payload = {localId: Array(validate_uid(uid, required: true))} elsif (email = query[:email]) payload = {email: Array(validate_email(email, required: true))} elsif (phone_number = query[:phone_number]) payload = {phoneNumber: Array(validate_phone_number(phone_number, required: true))} else raise ArgumentError, "Unsupported query: #{query}" end res = @client.post(with_path("accounts:lookup"), payload).body users = res["users"] if res UserRecord.new(users[0]) if users.is_a?(Array) && users.length > 0 end |