Sha256: fbffa23c10d1176c1287a4416f2fa01d5b3fc83277e56416c69c7eecb7eb9c2f

Contents?: true

Size: 939 Bytes

Versions: 5

Compression:

Stored size: 939 Bytes

Contents

module CanvasOauth
  class CanvasController < CanvasOauth::OauthApplicationController
    skip_before_filter :request_canvas_authentication

    def oauth
      if verify_oauth2_state(params[:state]) && params[:code]
        if token = canvas.get_access_token(params[:code])
          if CanvasOauth::Authorization.cache_token(token, user_id, tool_consumer_instance_guid)
            redirect_to main_app.root_path
          else
            render text: "Error: unable to save token"
          end
        else
          render text: "Error: invalid code - #{params[:code]}"
        end
      else
        render text: "#{CanvasOauth::Config.tool_name} needs access to your account in order to function properly. Please try again and click log in to approve the integration."
      end
    end

    def verify_oauth2_state(callback_state)
      callback_state.present? && callback_state == session.delete(:oauth2_state)
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
canvas_oauth_engine-1.1.2 app/controllers/canvas_oauth/canvas_controller.rb
canvas_oauth_engine-1.1.1 app/controllers/canvas_oauth/canvas_controller.rb
canvas_oauth_engine-1.1.0 app/controllers/canvas_oauth/canvas_controller.rb
canvas_oauth_engine-1.0.4 app/controllers/canvas_oauth/canvas_controller.rb
canvas_oauth_engine-1.0.3 app/controllers/canvas_oauth/canvas_controller.rb