Class: Firebase::Admin::Auth::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/firebase/admin/auth/client.rb

Overview

A client for communicating with the Firebase Auth service.

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Client

Constructs a new client

Parameters:



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/firebase/admin/auth/client.rb', line 9

def initialize(app)
  @project_id = app.project_id
  @service_account_id = app.
  @credentials = app.credentials

  @emulated = Utils.is_emulated?
  v1_url_override = Utils.get_emulator_v1_url
  @credentials = EmulatorCredentials.new if @emulated

  @id_token_verifier = IDTokenVerifier.new(app)
  @user_manager = UserManager.new(@project_id, @credentials, v1_url_override)
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.

Parameters:

  • uid (String, nil) (defaults to: nil)

    The id to assign to the newly created user.

  • display_name (String, nil) (defaults to: nil)

    The user’s display name.

  • email (String, nil) (defaults to: nil)

    The user’s primary email.

  • email_verified (Boolean, nil) (defaults to: nil)

    A boolean indicating whether or not the user’s primary email is verified.

  • phone_number (String, nil) (defaults to: nil)

    The user’s primary phone number.

  • photo_url (String, nil) (defaults to: nil)

    The user’s photo URL.

  • password (String, nil) (defaults to: nil)

    The user’s raw, unhashed password.

  • disabled (Boolean, nil) (defaults to: nil)

    A boolean indicating whether or not the user account is disabled.

Returns:

Raises:



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/firebase/admin/auth/client.rb', line 42

def create_user(uid: nil, display_name: nil, email: nil, email_verified: nil, phone_number: nil, photo_url: nil, password: nil, disabled: nil)
  @user_manager.create_user(
    uid: uid,
    display_name: display_name,
    email: email,
    email_verified: email_verified,
    phone_number: phone_number,
    photo_url: photo_url,
    password: password,
    disabled: disabled
  )
end

#delete_user(uid) ⇒ Object

Deletes the user corresponding to the specified user id.

Parameters:

  • uid (String)

    The id of the user.



86
87
88
# File 'lib/firebase/admin/auth/client.rb', line 86

def delete_user(uid)
  @user_manager.delete_user(uid)
end

#emulated?Boolean

Checks if the auth client is configured to use the Firebase Auth Emulator. @ return [Boolean] true if configured for the auth emulator, false otherwise.

Returns:

  • (Boolean)


24
25
26
# File 'lib/firebase/admin/auth/client.rb', line 24

def emulated?
  @emulated
end

#get_user(uid) ⇒ UserRecord

Gets the user corresponding to the specified user id.

Parameters:

  • uid (String)

    The id of the user.

Returns:



61
62
63
# File 'lib/firebase/admin/auth/client.rb', line 61

def get_user(uid)
  @user_manager.get_user_by(uid: uid)
end

#get_user_by_email(email) ⇒ UserRecord

Gets the user corresponding to the specified email address.

Parameters:

  • email (String)

    An email address.

Returns:



71
72
73
# File 'lib/firebase/admin/auth/client.rb', line 71

def get_user_by_email(email)
  @user_manager.get_user_by(email: email)
end

#get_user_by_phone_number(phone_number) ⇒ Object

Gets the user corresponding to the specified phone number.

Parameters:

  • phone_number (String)

    A phone number, in international E.164 format.



78
79
80
# File 'lib/firebase/admin/auth/client.rb', line 78

def get_user_by_phone_number(phone_number)
  @user_manager.get_user_by(phone_number: phone_number)
end

#verify_id_token(token, check_revoked = false) ⇒ Hash

Verifies the signature and data for the provided JWT.

Accepts a signed token string, verifies that it is current, was issued to this project, and that it was correctly signed by Google.

Parameters:

  • token (String)

    A string of the encoded JWT.

  • check_revoked (Boolean) (defaults to: false)

    (false) If true, checks whether the token has been revoked.

Returns:

  • (Hash)

    A hash of key-value pairs parsed from the decoded JWT.



98
99
100
101
102
# File 'lib/firebase/admin/auth/client.rb', line 98

def verify_id_token(token, check_revoked = false)
  verified_claims = @id_token_verifier.verify(token, is_emulator: emulated?)
  revoked = check_revoked && !id_token_revoked?(verified_claims)
  verified_claims unless revoked
end