Ответ 1
Я занимаюсь разработкой службы с помощью rails-api. Мы еще не развернулись, но приближаемся к этому времени и не испытывали никаких проблем при тестировании. Вам необходимо включить любые несущественные модули, которые вы хотите использовать, поскольку rails-api урезается справа. Я использую authenticate_or_request_with_http_token в ApplicationController, например:
include ActionController::HttpAuthentication::Token::ControllerMethods
def authenticate
authenticate_or_request_with_http_token do |token, options|
apiKey = ApiKey.where(auth_token: token).first
@current_user = apiKey.user if apiKey
end
end
Если вам нужен только токен, есть удобный метод token_and_options:
include ActionController::HttpAuthentication::Token
def current_user
api_key = ApiKey.where(auth_token: token_and_options(request)).first
User.find(api_key.user_id) if api_key
end