module MnoEnterprise::Concerns::Controllers::Webhook::OAuthController
Constants
- PROVIDERS_WITH_OPTIONS
Public Instance Methods
app_instance()
click to toggle source
# File lib/mno_enterprise/concerns/controllers/webhook/o_auth_controller.rb, line 18 def app_instance @app_instance ||= MnoEnterprise::AppInstance.where(uid: params[:id]).first end
callback()
click to toggle source
GET /mnoe/webhook/oauth/:id/callback
# File lib/mno_enterprise/concerns/controllers/webhook/o_auth_controller.rb, line 73 def callback path = session.delete(:redirect_path).presence || mnoe_home_path if error_key = params.fetch(:oauth, {})[:error] path = add_param_to_fragment(path.to_s, 'flash', [{msg: error_message(error_key), type: :error}.to_json]) end unless params.fetch(:oauth, {})[:error] case params.fetch(:oauth, {})[:action] when 'sync' MnoEnterprise::EventLogger.info('app_connected', current_user.id, 'App connected', app_instance) when 'disconnect' MnoEnterprise::EventLogger.info('app_disconnected', current_user.id, 'App disconnected', app_instance) end end redirect_to path end
check_permissions()
click to toggle source
Redirect with an error if user is unauthorized
# File lib/mno_enterprise/concerns/controllers/webhook/o_auth_controller.rb, line 23 def check_permissions unless can?(:manage_app_instances, app_instance.owner) redirect_to mnoe_home_path, alert: "You are not authorized to perform this action" return false end true end
disconnect()
click to toggle source
GET /mnoe/webhook/oauth/:id/disconnect
# File lib/mno_enterprise/concerns/controllers/webhook/o_auth_controller.rb, line 93 def disconnect redirect_to MnoEnterprise.router.disconnect_oauth_url(params[:id], extra_params.merge(wtk: wtk)) end
error_message(error_key)
click to toggle source
# File lib/mno_enterprise/concerns/controllers/webhook/o_auth_controller.rb, line 42 def error_message(error_key) case error_key.to_sym when :bad_relinking %{A different account '#{app_instance.oauth_company}' was previously linked to this application, please re-link the same account.} when :unauthorized 'We could not validate your credentials, please try again' else error_key end end
extra_params()
click to toggle source
Return a hash of extra parameters that were passed along with the request
# File lib/mno_enterprise/concerns/controllers/webhook/o_auth_controller.rb, line 33 def extra_params params.except(:controller,:action,:id, :perform) end
sync()
click to toggle source
GET /mnoe/webhook/oauth/:id/sync
# File lib/mno_enterprise/concerns/controllers/webhook/o_auth_controller.rb, line 98 def sync redirect_to MnoEnterprise.router.sync_oauth_url(params[:id], extra_params.merge(wtk: wtk)) end
wtk()
click to toggle source
Current user web token
# File lib/mno_enterprise/concerns/controllers/webhook/o_auth_controller.rb, line 38 def wtk MnoEnterprise.jwt(user_id: current_user.uid) end