Sha256: c1cda3fdb051ba4144dd296fee2edc72c922fb79207c04ce161cf960e8dc4434

Contents?: true

Size: 1.44 KB

Versions: 15

Compression:

Stored size: 1.44 KB

Contents

module Doorkeeper
  class TokensController < Doorkeeper::ApplicationMetalController
    def create
      response = authorize_response
      self.headers.merge! response.headers
      self.response_body = response.body.to_json
      self.status        = response.status
    rescue Errors::DoorkeeperError => e
      handle_token_exception e
    end

    # OAuth 2.0 Token Revocation - http://tools.ietf.org/html/rfc7009
    def revoke
      # The authorization server first validates the client credentials
      if doorkeeper_token && doorkeeper_token.accessible?
        # Doorkeeper does not use the token_type_hint logic described in the RFC 7009
        # due to the refresh token implementation that is a field in the access token model.
        revoke_token(request.POST['token']) if request.POST['token']
      end
      # The authorization server responds with HTTP status code 200 if the
      # token has been revoked successfully or if the client submitted an invalid token
      render json: {}, status: 200
    end

    private

    def revoke_token(token)
      token = AccessToken.by_token(token) || AccessToken.by_refresh_token(token)
      if token && doorkeeper_token.same_credential?(token)
        token.revoke
        true
      else
        false
      end
    end

    def strategy
      @strategy ||= server.token_request params[:grant_type]
    end

    def authorize_response
      @authorize_response ||= strategy.authorize
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
doorkeeper-4.0.0.rc3 app/controllers/doorkeeper/tokens_controller.rb
doorkeeper-4.0.0.rc2 app/controllers/doorkeeper/tokens_controller.rb
doorkeeper-4.0.0.rc1 app/controllers/doorkeeper/tokens_controller.rb
doorkeeper-3.1.0 app/controllers/doorkeeper/tokens_controller.rb
doorkeeper-3.0.1 app/controllers/doorkeeper/tokens_controller.rb
doorkeeper-2.2.2 app/controllers/doorkeeper/tokens_controller.rb
doorkeeper-3.0.0 app/controllers/doorkeeper/tokens_controller.rb
doorkeeper-3.0.0.rc2 app/controllers/doorkeeper/tokens_controller.rb
doorkeeper-3.0.0.rc1 app/controllers/doorkeeper/tokens_controller.rb
doorkeeper-2.2.1 app/controllers/doorkeeper/tokens_controller.rb
doorkeeper-2.2.0 app/controllers/doorkeeper/tokens_controller.rb
doorkeeper-2.1.4 app/controllers/doorkeeper/tokens_controller.rb
doorkeeper-2.1.3 app/controllers/doorkeeper/tokens_controller.rb
doorkeeper-2.1.2 app/controllers/doorkeeper/tokens_controller.rb
doorkeeper-2.1.1 app/controllers/doorkeeper/tokens_controller.rb