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
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'app/controllers/skydrive/launch_controller.rb', line 49 def basic_launch tp = tool_provider if tp.lti_errorlog render text: tp.lti_errorlog, status: 400, layout: "skydrive/error" return end user_id = tp.get_custom_param('masquerading_user_id') || tp.user_id is_masquerading = user_id == tp.get_custom_param('masquerading_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.ensure_token user.cleanup_api_keys code = user.session_api_key(params).oauth_code redirect_to "#{root_path}launch/#{code}" end |
#launch_error ⇒ Object
147 148 149 150 151 |
# File 'app/controllers/skydrive/launch_controller.rb', line 147 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
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'app/controllers/skydrive/launch_controller.rb', line 102 def microsoft_oauth begin api_key = ApiKey.trade_oauth_code_for_access_token(params['state']) raise RuntimeError, 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!(skydrive_client) 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 Exception => api_error launch_exception_handler api_error end end |
#skydrive_authorized ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'app/controllers/skydrive/launch_controller.rb', line 83 def skydrive_token = current_user.token if skydrive_token && skydrive_token.requires_refresh? begin skydrive_client.refresh_token = skydrive_token.refresh_token skydrive_token.refresh!(skydrive_client) rescue Skydrive::APIResponseErrorException => error current_user.reset_token! end end if skydrive_token && skydrive_token.is_valid? 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
142 143 144 145 |
# File 'app/controllers/skydrive/launch_controller.rb', line 142 def skydrive_logout render json: {}, status: 200 current_user.token.destroy end |
#tool_provider ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'app/controllers/skydrive/launch_controller.rb', line 16 def tool_provider 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 # ## this isn't actually checking anything like it should, just want people ## implementing real tools to be aware they need to check the nonce #if was_nonce_used_in_last_x_minutes?(@tp.request_oauth_nonce, 60) # register_error "Why are you reusing the nonce?" # return false #end return tp end |
#xml_config ⇒ Object
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'app/controllers/skydrive/launch_controller.rb', line 122 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 |