西纳特拉与监狱长对使用设计的Rails应用现有的Ruby [英] Sinatra Warden with existing Ruby on Rails application that uses Devise
问题描述
我试图分裂我目前的Ruby on Rails的3 web的应用程序,它的Web服务(API)。我的网络应用程序在Heroku上运行,并且实现了API作为我的应用程序中的一个名称空间的路线。例如 /事件
返回一个HTML页面和 / API / V1 /事件
返回JSON数据。
I am trying to split my current Ruby on Rails 3 web-application and it's web-services (API). My web-application is running on Heroku and implements API as a namespaced route within my application. For example /events
returns a HTML page and /api/v1/events
returns a JSON data.
根据一些最佳实践的,我想要分割的那些成两个不同的应用程序。我选择了西纳特拉实现API的应用程序。现在它适用于那些不需要身份验证简单的请求。
According to some best practices, I want to split those into two different applications. I have chosen Sinatra to implement the API application. It works now for simple requests where authentication is not required.
我on Rails的3个应用程序的Ruby是使用设计对用户进行认证。还有与Facebook帐号登录的能力。现在我想达到什么是用户(包括注册登记)通过我的基于西纳特拉的API的HTTP基本验证通过监狱长。
My Ruby on Rails 3 application is using Devise to authenticate users. There's also ability to login with Facebook account. Now what I want to achieve, is HTTP Basic Authentication of users (including registration) through my Sinatra-based API by using Warden.
什么是做的最好的方法?或者,也许我可以用不同的东西,然后监狱长?
What is the best way to do that? Or maybe I can use something different then Warden?
请记住,我不是很熟悉,机架:)
Keep in mind that I am not very familiar with Rack :)
推荐答案
我能得到它的工作。有几个主要方面:
I was able to get it working. There were a few main aspects:
- 获取设计使用Rails的工作(设计是一个Rails应用程序,将无法正常工作
没有它) - 安装在机架级的映射(路线),以支持Rails和Sinatra的
- 共享Rails和西纳特拉之间的会话
- 设置监狱长和其提供给西纳特拉
下面是/config.ru code的最相关的部分:
Here is most relevant part of code from /config.ru:
#
# ...
# Rest with Rails
map "/" do
run MyApp::Application
end
# Anything urls starting with /slim will go to Sinatra
map "/slim" do
# make sure :key and :secret be in-sync with initializers/secret_store.rb initializers/secret_token.rb
use Rack::Session::Cookie, :key => '<< see, initializers/secret_store.rb >>', :secret => '<< copy from initializers/secret_token.rb >>'
# Point Warden to the Sinatra App
use Warden::Manager do |manager|
manager.failure_app = AppMain
manager.default_scope = Devise.default_scope
end
# Borrowed from https://gist.github.com/217362
Warden::Manager.before_failure do |env, opts|
env['REQUEST_METHOD'] = "POST"
end
run AppMain
end
请参阅http://labnote.beedesk.com/sinatra-warden-rails-devise一个完整的解决方案。
See, http://labnote.beedesk.com/sinatra-warden-rails-devise for a complete solution.
这篇关于西纳特拉与监狱长对使用设计的Rails应用现有的Ruby的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!