Rails 3.0.9 + open_id_authentication - ruby-on-rails

I'm using open_id_authentication gem to authenticate to google. In my sessions controller I call
authenticate_with_open_id(complete_identity_url, OPENID_OPTS) do |openid_result, identity_url, registration|
and it returns 401 status code Unauthenticated. But it should show google page in which I must confirm access.
I made example app: https://github.com/mbashirov/rails3-test, it only has code in sessions controller and routes set.
That code works perfectly on rails 2.3 app. There is error?
Thanks.
Solution.
In sessions controller add
class SessionsController < ApplicationController
include OpenIdAuthentication
In config/application.rb add
config.app_middleware.use OpenIdAuthentication
After this two steps all works fine.

If it works in 2.3 and then doesn't work in 3, it sounds like an error not of your own making.
Next steps:
1) Upgrade to latest 3.1 (or better 3.1.1) Rails
2) Contact the authors of the gem to see what their 3.1 support plans are. They may already be working on a solution that you can help test.
3) If you have the skills, it would be awesome for you to contribute back by solving the problem.
I suggest that you start with an Ether peek tool such as Fiddler or a Mac tool to see if your machine is sending out the same requests/getting the same responses when running 3.1.1 vs 2.3.
Then debug....

Related

Rails 4.2 + Ember => unexpected identifier

I'm following Vic Ramon's tutorial. I tried to use the latest version of Rails and Ember-source and I get the following error when visiting home page:
After clicking on link next to error I get this:
How can I fix that?
I ran the following commands:
rails g ember:bootstrap -n App --javascript-engine coffee
rails g ember:install
I removed turbolinks. I also created home controller and an empty view for home#index. Root is set to home#index. Also created following view file:
// app/assets/javascripts/templates/application.js.emblem
h1 Hello World
outlet
Ember gems im using:
Using emblem-source 0.3.18
Using ember-data-source 1.0.0.beta.14.1
Using ember-rails 0.16.1
Using emblem-rails 0.2.2
This could be due to some version incompatibilities between your versions of ember-related gems, as there were quite substantial changes in recent versions of ember (e.g. introduction of HTMLBars, etc.)
Your best bet is to clone the original repo and then try to upgrade individual gems and check if it still works after each upgrade. This way you will be able to identify the troubling gem.
I have verified that the original repo code indeed works with the versions of gems in its current Gemfile.lock.
If you are starting a new Rails + Ember app, ember-cli-rails is probably the way to go, giving you the best of both worlds.
Emblem was the culprit. Replacing .emblem with .handlebars fixed the problem. I tried the tip from emblem-rails git page and icluded
gem "emblem-source", github: "machty/emblem.js"
but that didn't change anything.
I also followed this tutorial (alongside a few others) and I encountered several issues alongside the way ranging from handling templates to setting up the JSON API. I don't see your entire source code so I cannot pinpoint the exact problem. However, it seems that we have similar projects, so you can compare your code to my blog project source code and see what is causing these issues. Comparing to Ramon's tutorial, my blog has implemented everything until chapter 15.
https://github.com/Deovandski/Fakktion/tree/Ember-Rails
If you are a beginner like myself, then I recommend avoiding CoffeeScript and Emblem and sticking to Javascript as much as possible for the first months because you will find more resources and examples. Also, let me know if you need assistance in setting up the project as I used .gitignore to hide things like secrets.yml

Authenticating users Ionic App with Rails + Devise backend

Has anyone successfully implemented authentication on an Ionic application that uses a Rails application with Devise as a backend? If so, what implementation did you use to that end?
I have already tried solutions like cloudspace's angular-devise but it doesn't really play well with Devise on the server due to CORS (which I have already included the headers needed for it to work)
The current rails application allows facebook login, it would be nice if the Ionic app had that ability as well.
Try to give this cloudspace's angular-devise another shot
I have combined it with rack-cors
and it worked for me.
Another Implementation via Toke Auth is also working..
An example implementation of the rails part can be found here:
https://github.com/julianbei/authService
The Ionic Part can be found here:
https://github.com/julianbei/authService/tree/master/mobile
Its not beautiful but a working "quick and dirty" implementation
good luck!

Spree API and New Relic monitoring

I've got problem with monitoring my app with New Relic.
I have latest Spree engine mounted in my routes and own controller to serve as root.
For some reason, New Relic gathers only data from this root route, any call to Spree JSON API is ignored and don't show up in Dashboard, so I can see only one transaction and it's pretty useless.
Is there any way to enable monitoring on whole mounted app? Am I missing something?
As long as you're running on Rails 4.0 or later, adding the following to app/controllers/spree/api/base_controller_decorator.rb or some equivalent location should get instrumentation wired up:
class Spree::Api::BaseController
include ActionController::Instrumentation
end
This works because on Rails 4.0 and later New Relic's controller instrumentation is based off ActiveSupport::Notifications, and include ActionController::Instrumentation gets those events flowing.
My guess is that this is happening because Spree's API is inheriting from ActionController::Metal, where NewRelic doesn't hook into.
Check here: https://github.com/spree/spree/blob/6ac62c32f91e6626b338564aab7a7ad570cbd4c3/api/app/controllers/spree/api/base_controller.rb#L5
This is probably a good argument for switching away from this within Spree, so please submit an issue for that.
I've found a way to bypass the problem in this article.
Create app/controllers/spree/api/base_controller_decorator.rb with following code:
require 'new_relic/agent/instrumentation/action_controller_subscriber'
require 'new_relic/agent/instrumentation/rails4/action_controller'
Spree::Api::BaseController.class_eval do
before_filter :check_for_user
include NewRelic::Agent::Instrumentation::ControllerInstrumentation
include NewRelic::Agent::Instrumentation::Rails4::ActionController
NewRelic::Agent::Instrumentation::ActionControllerSubscriber \
.subscribe(/^process_action.action_controller$/)
end

Authlogic_oauth2 alternative for Rails 2.3

In order to let users signup and login using facebook I used the authlogic_oauth2 gem (v.1.1.2) along with oauth2 (v. 0.0.10) and authlogic (2.1.6) in a Rails 2.3 application.
Everything worked well for more than 2 years but from a month or so, users are not able to login or signup with Facebook anymore.
I don't know what happened but I didn't changed anything so it seems that Facebook changed something on their end and authlogic_oauth2 doesn't seem to be able to work anymore.
Which could be the easiest way to fix the issue and bring back user login/signup with facebook?
Is there any better gem to help on the job?
Thanks in advance,
Augusto
I doubt that you may have done some changes in your present application unknowingly that caused the login and logout failures.
One possible cause of the problem might be the redirections from: http://yoursite.com to http://www.yoursite.com based on the changes that you made. Check the blog that mentions this problem.
The fix is to set: config.action_controller.session[:domain] = '.YOURDOMAIN.COM' inside of environment.rb (Make sure to prefix it with the .). That will make cookies work for both www.yourdomain.com and yourdomain.com (as well as any other subdomains).
I also recommend to check the login behavior in different environments: Development and Production and then check the output in the log files clearly.
This may help you to tweak the problem domain, as you mentioned that your code was working previously.
Update:
there is an update in facebook oauth and it is mentioned that all applications need to be updated to the latest version of oauth.
So that is the possible cause for your problem.
It outlines a plan requiring all sites and apps to migrate to OAuth 2.0, process the signed_request parameter, and obtain an SSL certificate by October 1.
check the link below:
http://developers.facebook.com/blog/post/497/
Thanks!
I found the solution: Omniauth works perfectly fine with Rails 2.3 and there is even a demo app on how to integrate it with Authlogic.
A popular one would be Devise which plays well with Omniauth. I am not sure of the compatibilities with rails 2 though, maybe time to upgrade...
Any reason you can not use Koala? https://github.com/arsduo/koala

Any working tutorials for Authlogic?

I've been trying to build my first rails app and have gotten stuck on the issue of user authentication. I've found a number of tutorials for using various plug-ins to do this, but so far every single one of them is out-dated, and as a result, broken!
From what I've read, I think Authlogic may be the best fit for me, and I've tried two things:
1) Going through Railscast, episode #160 (which is a tutorial for setting it up)
2) Using Ryan B's nifty_authentication gem with the --authlogic tag
In both cases, I get the following error as soon as I try to do anything with a user:
undefined local variable or method `acts_as_authentic' for #
I believe this is from the User model:
class User < ActiveRecord::Base
acts_as_authentic
end
I'm sure I've installed the authlogic gem, and I've added
config.gem "authlogic"
to my environment.rb
Any ideas about what's wrong? Anybody know of a complete and up to date tutorial for adding user authentication?
Edit:
I'm running Ruby v. 1.8.6 and rails v. 2.3.5
There is one thing that Ryan Bates in the RailsCasts episode doesn't talk about is about creating sessions table in your database. Type rake db:sessions:create in the console and run the migration rake db:migrate. Also like ghoppe says run rake gems:install after installing the gem. That is a requisite.
Here's an example app with a step-by-step guide - it's from last year but should still be mostly if not entirely accurate:
authlogic_example
Since you added that line to your environment.rb, have you tried rake gems:install to ensure the gem is installed and working correctly?
Also, what version of Ruby? What version of Rails? Have you tried running gem environment and gem list to make sure they're installed and running from the right place?
Another option is to use authlogic as a plugin, with:
script/plugin install git://github.com/binarylogic/authlogic.git
It also helps to look at a projects that uses authlogic as authentication module, like the fat_free_crm project, have a look at user.rb there
Last but not least, there is an active mailing list:
authlogic mailing list
Becoming popular is also the devise gem. Here you can add authentication with script/generate devise and you will have some views for login as well.
I forked that authlogic_example and added activity_tracker, authlogic, paperclip for user profile images, declarative_authorization, and user to user messages.
http://github.com/jspooner/authlogic_cucumber_rspec_example

Resources