Gibt es eine Chance, authentifizieren Doorkeeper-Methode von einem Rails Action Controller zugreifen? Ich möchte die Authentifizierung nur für eine meiner Aktionen überspringen ('show'), aber wenn eine bestimmte Bedingung zutrifft, möchte ich die Methode apiauthenticate aufrufen, um ihre Aufgabe zu erledigen. In der Aktion 'show' überprüfe ich zuerst eine Bedingung, und wenn dies nicht zutrifft, muss ich die api_authenticate aktivieren. Ich starte einen Test, der api_authenticate aufrufen und dort stoppen soll. Aber aus irgendeinem Grund geht es weiter und es hört nicht auf. Access Doorkeeper von Aktion Rails Controller
Dies ist der Code meiner Controller
skip_before_action :api_authenticate, only: :show
def show
param! :id, String, required: true
post = Services::Posts.find(params[:id])
if post.public
@post = post
@user_id = nil
else
api_authenticate
ap "it shouldnt get here if user is not logged in"
user = current_resource_owner
@post = Services::Posts.show(params[:id], user)
@user_id = user.identity rescue nil
end
end
#more actions....
Und das ist die api_controller.rb, wo ich die authenticate Methode haben
class ApiController < ApplicationController
protect_from_forgery with: :null_session
# Check the user is authenticated
before_action :api_authenticate
rescue_from ActionController::RoutingError, :with => :route_error
rescue_from ::AbstractController::ActionNotFound, :with => :action_error
rescue_from Exception, :with => :base_error if Rails.env.production?
def api_authenticate
doorkeeper_authorize!()
end
end