Sha256: ca25572cc7f4c049689de0b49168227c84e162b65b8c9be07b2eef7d83c95b69

Contents?: true

Size: 1.46 KB

Versions: 20

Compression:

Stored size: 1.46 KB

Contents

class Oauth2::AuthorizationsController < ApplicationController
  before_filter :authenticate_user!

  rescue_from Rack::OAuth2::Server::Authorize::BadRequest do |e|
    @error = e
    render :error, :status => e.status
  end

  def new
    respond *authorize_endpoint.call(request.env)
  end

  def create
    respond *authorize_endpoint(:allow_approval).call(request.env)
  end

  private

  def respond(status, header, response)
    ["WWW-Authenticate"].each do |key|
      headers[key] = header[key] if header[key].present?
    end
    if response.redirect?
      redirect_to header['Location']
    else
      render :new
    end
  end

  def authorize_endpoint(allow_approval = false)
    Rack::OAuth2::Server::Authorize.new do |req, res|
      @client = Client.find_by_identifier(req.client_id) || req.bad_request!
      res.redirect_uri = @redirect_uri = req.verify_redirect_uri!(@client.redirect_uri)
      if allow_approval
        if params[:approve].present?
          case req.response_type
          when :code
            authorization_code = current_user.authorization_codes.create(:client_id => @client, :redirect_uri => @redirect_uri)
            res.code = authorization_code.token
          when :token
            res.access_token = current_user.access_tokens.create(:client_id => @client).to_bearer_token
          end
          res.approve!
        else
          req.access_denied!
        end
      else
        @response_type = req.response_type
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 2 rubygems

Version Path
devise_oauth2_providable-0.3.6 app/controllers/oauth2/authorizations_controller.rb
devise_oauth2_providable-0.3.5 app/controllers/oauth2/authorizations_controller.rb
devise_oauth2_providable-0.3.4 app/controllers/oauth2/authorizations_controller.rb
devise_oauth2_providable-0.3.3 app/controllers/oauth2/authorizations_controller.rb
devise_oauth2_providable-0.3.2 app/controllers/oauth2/authorizations_controller.rb
devise_oauth2_providable-0.3.1 app/controllers/oauth2/authorizations_controller.rb
devise_oauth2_providable-0.3.0 app/controllers/oauth2/authorizations_controller.rb
devise_oauth2_providable-0.2.4 app/controllers/oauth2/authorizations_controller.rb
devise_oauth2_providable-0.2.3 app/controllers/oauth2/authorizations_controller.rb
devise_oauth2_providable-0.2.2 app/controllers/oauth2/authorizations_controller.rb
devise_oauth2_providable-0.2.1 app/controllers/oauth2/authorizations_controller.rb
devise_oauth2_providable-0.2.0 app/controllers/oauth2/authorizations_controller.rb
devise_oauth2_providable-0.1.6 app/controllers/oauth2/authorizations_controller.rb
devise_oauth2_providable-0.1.5 app/controllers/oauth2/authorizations_controller.rb
devise_oauth2_providable-0.1.4 app/controllers/oauth2/authorizations_controller.rb
devise_oauth2_providable-0.1.3 app/controllers/oauth2/authorizations_controller.rb
devise_oauth2_providable-0.1.2 app/controllers/oauth2/authorizations_controller.rb
devise_oauth2_providable-0.1.1 app/controllers/oauth2/authorizations_controller.rb
devise_oauth2_providable-0.1.0 app/controllers/oauth2/authorizations_controller.rb
devise_oauth2_token_bearer_authenticatable-0.0.1 app/controllers/oauth2/authorizations_controller.rb