Sha256: 14eb705973d11fb71a70f6ada632b95aec487039fe90a0bf290ff32965ebf9c8

Contents?: true

Size: 1.88 KB

Versions: 4

Compression:

Stored size: 1.88 KB

Contents

module Corkboard
  class AuthorizationsController < Corkboard::ApplicationController
    before_filter(:auth_admin, {
      :except => [:create]
    })

    # GET  /:mount_point/authorizations
    def index
      authorizations = Corkboard::Authorization.all
      providers      = authorizations.map(&:provider)
      available      = Corkboard.services.reject { |s| providers.include?(s) }

      render(:index, :locals => {
        :activated => authorizations,
        :available => available
      })
    end

    # GET  /:mount_point/auth/:provider/callback
    # POST /:mount_point/auth/:provider/callback
    def create
      # TODO:
      #   * guard based on "state" param:
      #     if `session['omniauth.state]`, `params[:state]` must match.

      authorization = Corkboard::Authorization.create!(auth_attrs)
      subscription  = Corkboard::Subscription.create!(provider, authorization)

      Corkboard.publish!(subscription.backlog)
      redirect_to(authorizations_path)
    end

    # DELETE /:mount_point/auth/:provider
    def destroy
      # TODO: resolve the fact that there may be more than one for the same
      # provider.  either disallow multiple, or select the correct one.
      auth = Corkboard::Authorization.find_by_provider(params[:provider])
      auth.destroy if auth
      Corkboard.clear_all!

      redirect_to(authorizations_path)
    end

    private

      def auth_attrs
        @auth_attrs ||= {
          :resource_owner => nil, # TODO
          :provider       => auth_params.provider,
          :uid            => auth_params.uid,
          :token          => auth_params.credentials.token,
          :info           => auth_params.info,
          :extra          => auth_params.extra
        }
      end

      def auth_params
        @auth_params ||= request.env['omniauth.auth']
      end

      def provider
        @provider ||= params[:provider]
      end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
corkboard-0.1.3 app/controllers/corkboard/authorizations_controller.rb
corkboard-0.1.2 app/controllers/corkboard/authorizations_controller.rb
corkboard-0.1.1 app/controllers/corkboard/authorizations_controller.rb
corkboard-0.1.0 app/controllers/corkboard/authorizations_controller.rb