module BookingSync::Engine::AuthHelpers
Constants
- NEW_AUTHORIZATION_URL
Path which will be used in POST request to start a new Authorization process.
Default to /auth/bookingsync
Private Instance Methods
after_bookingsync_sign_in_path()
click to toggle source
Path to which the user should be redirected after successful authorization. This method should be overridden in applications using this engine.
Defaults to root_path.
# File lib/bookingsync/engine/auth_helpers.rb, line 135 def after_bookingsync_sign_in_path root_path end
after_bookingsync_sign_out_path()
click to toggle source
Path to which the user should be redirected after sign out. This method should be overridden in applications using this engine.
Defaults to root_path.
# File lib/bookingsync/engine/auth_helpers.rb, line 143 def after_bookingsync_sign_out_path root_path end
authenticate_account!()
click to toggle source
Requests authorization if not currently authorized.
# File lib/bookingsync/engine/auth_helpers.rb, line 148 def authenticate_account! store_bookingsync_account_id if BookingSync::Engine.embedded sign_out_if_inactive enforce_requested_account_authorized! request_authorization! if current_account.nil? end
auto_submit_form_html()
click to toggle source
# File lib/bookingsync/engine/auth_helpers.rb, line 159 def auto_submit_form_html Repost::Senpai.perform( new_authorization_path, params: { account_id: session[:_bookingsync_account_id] }, options: { authenticity_token: Rack::Protection::AuthenticityToken.token(session) } ).html_safe end
current_account()
click to toggle source
@return [Account, nil] currently authorized Account or nil if unauthorized
# File lib/bookingsync/engine/auth_helpers.rb, line 17 def current_account return if session[:account_id].nil? @current_account ||= ::BookingSyncEngine.account_model.find_by_host_and_bookingsync_id_key(request.host, session[:account_id]) end
handle_oauth_error(error)
click to toggle source
Handler to rescue OAuth errors
@param error [OAuth2::Error] the rescued error
# File lib/bookingsync/engine/auth_helpers.rb, line 122 def handle_oauth_error(error) if error.code == "Not authorized" current_account.try(:clear_token!) reset_authorization! else raise end end