0
レールアクションコントローラからDoorkeeperメソッドを認証する機会はありますか?私は自分のアクション( 'show')の認証だけをスキップしたいと思いますが、特定の条件が当てはまる場合、私はapiauthenticateメソッドを呼び出してその仕事をしたいと思っています。したがって、アクション 'ショー'では、まず条件をチェックし、適用されない場合は、api_authenticateをアクティブにする必要があります。私は、api_authenticateを呼び出し、そこで停止するテストを開始しています。しかし何らかの理由でそれが続けられ、それは止まらない。アクションからドアキーパにアクセスするレールコントローラ
これは私のコントローラ
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....
のコードであり、これは私が似た何かを実装している私はauthenticateメソッド
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