- # logout - Clear our rack session BUT essentially redirect to the provider
- # to clean up the Devise session from there too !
- def logout
- session[:user_id] = nil
-
- flash[:notice] = 'You have logged off'
- return_to = params[:return_to] || root_url
- redirect_to "#{Rails.configuration.sso_provider_url}/users/sign_out?redirect_uri=#{CGI.escape return_to}"
- end
-
- # login - Just bounce to /auth/joshid. The only purpose of this function is
- # to save the return_to parameter (if it exists; see the application
- # controller). /auth/joshid bypasses the application controller.
- def login
- if params[:remote] !~ /^[0-9a-z]{5}$/ && !params[:remote].nil?
- return send_error 'Invalid remote cluster id', status: 400
- end
- if current_user and params[:return_to]
- # Already logged in; just need to send a token to the requesting
- # API client.
- #
- # FIXME: if current_user has never authorized this app before,
- # ask for confirmation here!
-
- return send_api_token_to(params[:return_to], current_user, params[:remote])
- end
- p = []
- p << "auth_provider=#{CGI.escape(params[:auth_provider])}" if params[:auth_provider]
- if params[:return_to]
- # Encode remote param inside callback's return_to, so that we'll get it on
- # create() after login.
- remote_param = params[:remote].nil? ? '' : params[:remote]
- p << "return_to=#{CGI.escape(remote_param + ',' + params[:return_to])}"
- end
- redirect_to "/auth/joshid?#{p.join('&')}"
- end
-
- def send_api_token_to(callback_url, user, remote=nil)