0

Below is code to create user by firebase authentication.

require 'google/apis/identitytoolkit_v3'

service_account = "./firebase-auth.json"

service = Google::Apis::IdentitytoolkitV3::IdentityToolkitService.new
service.authorization = Google::Auth::ServiceAccountCredentials.make_creds(
  json_key_io: File.open(service_account),
  scope: 'https://www.googleapis.com/auth/identitytoolkit'
)

request = Google::Apis::IdentitytoolkitV3::SignupNewUserRequest.new(
  email: 'sample@example.com',
  email_verified: false
)
service.signup_new_user(request)

After create user, I want to send email link for sign-in automatically.Maybe it's possible by Node.js, Java, Python, and Go because they're supported officially. https://firebase.google.com/docs/auth/admin/email-action-links#node.js_3 Is there a way to do that by ruby-client? (I just want to send email below)

Email template at firebase console

  • You should be able to pass the same values to the API as the Node.js SDK does: https://github.com/firebase/firebase-admin-node/blob/9f7529f6b57bf2e504c7e761de97c11905f14435/src/auth/auth.ts#L572, but I don't know of a ready-made Ruby client that does this already. – Frank van Puffelen Aug 19 '21 at 14:10
  • @FrankvanPuffelen I realized that all I need is here. https://firebase.google.com/docs/reference/rest/auth#section-send-email-verification As you say, Node.js SDK providing the option means there is a way to do it from scratch. Thanks! – Shun.Tagami Aug 20 '21 at 13:59

1 Answers1

1

Even if ruby-client doesn't provide the option, you should be able to implement the API client from scratch like below. (Look up official document more carefully.)

require 'net/http'
require 'uri'
require 'json'

uri = URI.parse("https://identitytoolkit.googleapis.com/v1/accounts:sendOobCode?key=[YOUR_API_KEY]")
request = Net::HTTP::Post.new(uri)
request.content_type = "application/json"
request.body = JSON.dump({requestType: "PASSWORD_RESET",email: "[EMAIL_OF_THE_USER]"})
response = Net::HTTP.start(uri.host, uri.port, { use_ssl: true }) do |http|
  http.request(request)
end