Class: Skydrive::LaunchController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- Skydrive::LaunchController
- Includes:
- ActionController::Cookies
- Defined in:
- app/controllers/skydrive/launch_controller.rb
Instance Method Summary collapse
- #basic_launch ⇒ Object
- #launch_error ⇒ Object
- #microsoft_oauth ⇒ Object
- #skydrive_authorized ⇒ Object
- #skydrive_logout ⇒ Object
- #tool_provider ⇒ Object
- #xml_config ⇒ Object
Instance Method Details
#basic_launch ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'app/controllers/skydrive/launch_controller.rb', line 38 def basic_launch tp = tool_provider if tp.lti_errorlog render text: tp.lti_errorlog, status: 400, layout: "skydrive/error" return end user_id = is_masquerading && tp.get_custom_param('masquerading_user_id') || tp.user_id name = is_masquerading ? 'masqueraded session' : tp.lis_person_name_full email = is_masquerading ? 'masqueraded session' : tp.lis_person_contact_email_primary user = @account.users.where(username: user_id).first || @account.users.create( lti_user_id: user_id, name: name, username: user_id, email: email ) if !is_masquerading && (user.email != email || user.name != name) user.email = email user.name = name user.save! end user.cleanup_api_keys code = user.session_api_key(params).oauth_code redirect_to "#{root_path}launch/#{code}" end |
#launch_error ⇒ Object
122 123 124 125 126 |
# File 'app/controllers/skydrive/launch_controller.rb', line 122 def launch_error @title = %s{Ooops! Something went terribly wrong!} @message = %s{Not sure what happened, or how you got here?!} render status: 400, layout: "skydrive/error" end |
#microsoft_oauth ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'app/controllers/skydrive/launch_controller.rb', line 77 def microsoft_oauth begin api_key = ApiKey.trade_oauth_code_for_access_token(params['state']) raise OAuthStateException, ERROR_NO_API_KEY unless api_key @current_user = api_key.user skydrive_client.request_oauth_token(params['code'], microsoft_oauth_url) service = skydrive_client.get_my_files_service() current_user.token.resource = service["serviceResourceId"] current_user.token.refresh! personal_url = skydrive_client.get_personal_url(service["serviceEndpointUri"]).gsub(/\/Documents$/,'/') current_user.token.update_attribute(:personal_url, personal_url) redirect_to "#{root_path}oauth/callback" rescue APIResponseErrorException, JSON::ParserError, OAuthStateException => api_error launch_exception_handler api_error end end |
#skydrive_authorized ⇒ Object
68 69 70 71 72 73 74 75 |
# File 'app/controllers/skydrive/launch_controller.rb', line 68 def if current_user.valid_skydrive_token? render json: {}, status: 201 else code = current_user.api_keys.active.skydrive_oauth.create.oauth_code render text: skydrive_client.(microsoft_oauth_url, state: code), status: 401 end end |
#skydrive_logout ⇒ Object
117 118 119 120 |
# File 'app/controllers/skydrive/launch_controller.rb', line 117 def skydrive_logout render json: {}, status: 200 current_user.token.destroy end |
#tool_provider ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/controllers/skydrive/launch_controller.rb', line 12 def tool_provider @tool_provider ||= begin require 'oauth/request_proxy/rack_request' @account = Account.where(key: params['oauth_consumer_key']).first if @account key = @account.key secret = @account.secret end tp = IMS::LTI::ToolProvider.new(key, secret, params) if !key tp.lti_errorlog = "Invalid consumer key or secret" elsif !secret tp.lti_errorlog = "Consumer key wasn't recognized" elsif !tp.valid_request?(request) tp.lti_errorlog = "The OAuth signature was invalid" elsif Time.now.utc.to_i - tp..to_i > 120 tp.lti_errorlog = "Your request is too old" end tp end end |
#xml_config ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'app/controllers/skydrive/launch_controller.rb', line 97 def xml_config host = request.scheme + "://" + request.host_with_port + "/" url = "#{request.protocol}#{request.host_with_port}#{launch_path}" title = "Onedrive Pro" tc = IMS::LTI::ToolConfig.new(:title => title, :launch_url => url) tc.extend IMS::LTI::Extensions::Canvas::ToolConfig tc.description = 'Allows you to pull in documents from Onedrive Pro to canvas' tc.canvas_privacy_public! tc.canvas_domain!(request.host) tc.canvas_icon_url!("#{host}assets/skydrive/skydrive_icon.png") tc.canvas_selector_dimensions!(700,600) tc.canvas_text!(title) tc.canvas_homework_submission! tc. tc.(visibility: 'admin') tc.set_custom_param('masquerading_user_id', '$Canvas.masqueradingUser.userId') render xml: tc.to_xml end |