Devise with omniauth facebook for multiple subdomains? - devise

I will have several subdomains on my site, one per language, and authentication is via facebook-omniauth. What is the best way to establish the constants (FB id, secret) for all the subdomains? I'm using Rails 3.1.x

The solution:
/config/initializers/session_store.rb
InfiniteshelterComDevise::Application.config.session_store :cookie_store,
:key => '_infiniteshelter.com-devise_session',
:domain => TOP_DOMAIN
and the constant TOP_DOMAIN is something like '.infiniteshelter.com' for infiniteshelter.com, pt.infiniteshelter.com and ru.infiniteshelter.com.

Related

Suburl's ruby on rails

I'm having a problem using a sub url, when I try to access through authentication page, it generates an authentication cookie, but i keep on login screen and if i try access some page it says that i must got logged.
If you mean sub-domain, you have to change, your config/initializer/session_store.rb
And add your subdomain, with a dot before like that :
Rails.application.config.session_store :cookie_store, :key => '_key', :domain => ".yourdomain.com"

Rails 3 - Help! Subdomains - Users Cannot Logout?

I've followed the ascii cast up at http://asciicasts.com/episodes/221-subdomains-in-rails-3
I've set the :domain option to :all in session store:
Rails.application.config.session_store :cookie_store, :key => '_bloggit_session', :domain => :all
Now my users cannot logout.
Any ideas why? I've tried deleting all cookies and then trying again, etc.
I can login, and my session is carried across subdomains, but I can't logout.
I am using rails 3, and authlogic for authentication.
Thanks for any help!
Specify the Domain.
I had the exact same issue and the culprit was using :domain => :all.
You'd think that would be all you need but it seems to cause some problems so I had to manually specify the domain with a preceding dot (.), like so:
:domain => '.lvh.me'
This fixed the issue in development. You can use different ways to set this in your various environments but I landed on something like this:
Rails.application.config.session_store :cookie_store,
:key => '_bloggit_session',
:domain => { production: '.bloggit.com',
staging: '.bloggitstaging.com',
development: '.lvh.me' }.fetch(Rails.env.to_sym)

Devise (or OmniAuth) appending "#_" to URL after sign in

I'm using Devise and OmniAuth (Facebook) in a Rails 3 app. I just started noticing this behavior recently.
When a user signs in, he is redirected to his dashboard, however, the characters "#_" are being appended to the url. The only thing I can think of now is a conflict between the routes created by:
resources :users
and
# User Authentication
devise_for :users,
:singular => :user,
:controllers => {:registrations => 'registrations'} do
get 'logout' => 'devise/sessions#destroy'
end
Is this only happening with Facebook? If so it is probably related to: https://developers.facebook.com/blog/post/552/. Notice how Facebook outlines that they changed the session redirect handling to append a #_=_ to responses. I'm not sure why this was done, however you may be able to fix it by supplying an explicit redirect url.

Setting Up Devise & Sendgrid on Heroku

My site is hosted on Heroku and I installed the Sendgrid Add-On as it looked almost too good to be true - but so far none of the email functionality is working. I have read the documentation and it clearly says just add-the add on - is more configuration required to get Devise working?
When I select 'send me new password' I get a 404 page which makes me think there is more to this. Like how does Sendgrid know/where to use the pre-installed Devise templates?
Thx.
I just set up Devise and SendGrid this morning and have no problems. I'm going to resume the steps I took.
First, install Devise and SendGrid. Congratulations, you've already done that ;)
Then, for production, add this to your files:
config/initializers/devise.rb :
config.mailer_sender = "mail-to-send#from.com"
Set up Rails ActionMailer to use SendGrid
config/environments/production.rb
config.action_mailer.default_url_options = { :host => 'your.websitedomain.com' }
ActionMailer::Base.smtp_settings = {
:user_name => ENV['SENDGRID_USERNAME'],
:password => ENV['SENDGRID_PASSWORD'],
:address => "smtp.sendgrid.net",
:port => 587,
:enable_starttls_auto => true,
:authentication => :plain,
:domain => "yourdomain.com"
}
And everything's working great with that. Sign up confirmations, password recovery...
Also, you should use Logging Expanded (it's Free!) and check your logs with heroku logs --tail (for real time).
If you still get errors, post your logs.
Have a good day !
I've used the sendgrid Add-On and it really should just work. Like you said, even the docs say so:
Rails apps using ActionMailer will just work, no setup is needed after the add-on is installed.
So, this makes me think something else is going on. Have you tried using the heroku logs command to see if your application is logging any errors?

Sinatra Warden with existing Ruby on Rails application that uses Devise

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.
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.
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:
Get Devise working with Rails (Devise is a Rails app, won't work
without it)
Setup the mapping (route) on Rack level to support both Rails and Sinatra
Share the sessions between Rails and Sinatra
Setup Warden and make it available to Sinatra
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
See, http://labnote.beedesk.com/sinatra-warden-rails-devise for a complete solution.