rails RailsでFirebaseUserのパスワードを変更する

本稿について

本稿はサイト運営者が学んだことなどを記したメモの内容です。
全てが正確な情報とは限りません。ご注意ください。また修正するべき点は適時修正していきます

require 'google/apis/identitytoolkit_v3'

class FirebaseAuth
  def self.update_password(email, new_password, old_password)
    service = Google::Apis::IdentitytoolkitV3::IdentityToolkitService.new
    auth = Google::Auth::ServiceAccountCredentials.make_creds(
      json_key_io: File.open(Rails.root.join('config/firebase_admin', ENV['GCP_AUTH_KEY_FILE'])),
      scope: ['https://www.googleapis.com/auth/identitytoolkit']
    )
    service.authorization = auth

    request = Google::Apis::IdentitytoolkitV3::ResetPasswordRequest.new(
      email:        email,
      new_password: new_password,
      old_password: old_password
    )
    service.reset_password(request)
  end
end

[参考]

Back