class Contrib::Auth::Provider::GoogleAuth
Constants
- DEFAULT_BASE_ENDPOINT
- PUBLIC_KEYS_URI
Public Class Methods
new(api_key, http_client = Faraday.new(DEFAULT_BASE_ENDPOINT))
click to toggle source
# File lib/contrib/auth/provider/google_auth.rb, line 10 def initialize(api_key, http_client = Faraday.new(DEFAULT_BASE_ENDPOINT)) @api_key = api_key @http_client = http_client end
Public Instance Methods
certificates()
click to toggle source
refers to: firebase.google.com/docs/auth/admin/verify-id-tokens
# File lib/contrib/auth/provider/google_auth.rb, line 76 def certificates response = @http_client.get(PUBLIC_KEYS_URI) JSON.parse(response.body) end
change_password(id_token, password)
click to toggle source
# File lib/contrib/auth/provider/google_auth.rb, line 81 def change_password(id_token, password) response = @http_client.post('/v1/accounts:update') do |req| req.params[:key] = @api_key req.headers['Content-Type'] = 'application/json' req.body = JSON.generate( idToken: id_token, password: password, returnSecureToken: true, ) end parsed_response = JSON.parse(response.body) Contrib::Auth::Provider::Responses::ChangePassword.new( id_token: parsed_response['idToken'], refresh_token: parsed_response['refreshToken'], expires_in: parsed_response['expiresIn'], email: parsed_response['email'], ) end
reset_password(email_or_username)
click to toggle source
refers to: firebase.google.com/docs/reference/rest/auth#section-send-password-reset-email
# File lib/contrib/auth/provider/google_auth.rb, line 60 def reset_password(email_or_username) # TODO: X-Firebase-Locale optional header response = @http_client.post('/v1/accounts:sendOobCode') do |req| req.params[:key] = @api_key req.headers['Content-Type'] = 'application/json' req.body = JSON.generate( email: email_or_username, requestType: 'PASSWORD_RESET', ) end response.success? end
sign_in_with_password(email_or_username, password)
click to toggle source
refers to: firebase.google.com/docs/reference/rest/auth#section-sign-in-email-password
# File lib/contrib/auth/provider/google_auth.rb, line 38 def sign_in_with_password(email_or_username, password) response = @http_client.post('/v1/accounts:signInWithPassword') do |req| req.params[:key] = @api_key req.headers['Content-Type'] = 'application/json' req.body = JSON.generate( email: email_or_username, password: password, returnSecureToken: true, ) end parsed_response = JSON.parse(response.body) # TODO: Handle errors Contrib::Auth::Provider::Responses::SignInWithPassword.new( id_token: parsed_response['idToken'], refresh_token: parsed_response['refreshToken'], expires_in: parsed_response['expiresIn'], ) end
sign_up_with_email_and_password(email_or_username, password)
click to toggle source
refers to: firebase.google.com/docs/reference/rest/auth#section-create-email-password
# File lib/contrib/auth/provider/google_auth.rb, line 16 def sign_up_with_email_and_password(email_or_username, password) response = @http_client.post('/v1/accounts:signUp') do |req| req.params[:key] = @api_key req.headers['Content-Type'] = 'application/json' req.body = JSON.generate( email: email_or_username, password: password, returnSecureToken: true, ) end parsed_response = JSON.parse(response.body) # TODO: Handle errors Contrib::Auth::Provider::Responses::SignUpWithEmailAndPassword.new( id_token: parsed_response['idToken'], refresh_token: parsed_response['refreshToken'], expires_in: parsed_response['expiresIn'], ) end