omniauth-password giving invalid_credentials error - ruby-on-rails

I set up omniauth-password exactly as shown here:
https://github.com/namick/omniauth-password
I, however, get an invalid_credentials error every time I try to sign in. Now, there are no users in my database so it should be creating them right? I'm kind of confused where registration fits into this.
The problem is that my controller is not even being called. Here are the logs.
(password) Callback phase initiated.
(password) Authentication failure! invalid_credentials encountered.
Started POST "/auth/password/callback" for 127.0.0.1 at 2012-12-05 02:34:05 -0800
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."email" = 'asd#asf.comssdf' LIMIT 1
Started GET "/auth/failure?message=invalid_credentials&strategy=password" for 127.0.0.1 at 2012-12-05 02:34:05 -0800
Processing by SessionsController#failure as HTML
Parameters: {"message"=>"invalid_credentials", "strategy"=>"password"}
Rendered text template (0.0ms)
Completed 200 OK in 16ms (Views: 15.4ms | ActiveRecord: 0.0ms)
Any help appreciated!

not quite answering your specific problem with omniauth-password but,
have you considered using omniauth-identity?
It's a database-based strategy that used username (or email) and password credentials, and there is a Railscast of it.
And: I succesfuully made it work with other strategies.
Omniauth-identity: https://github.com/intridea/omniauth-identity
Railscast: http://railscasts.com/episodes/304-omniauth-identity

Related

integrate devise_invitable with angular js in rails4

As the question I ask, now I can easily use devise_invitable module in rails app. However, it is hard to migrate to angular js.
I'm trying to use $http.post with url '/users/invitation.json' to trigger the invitation on the server side.
$scope.inviteUser = ->
$http.post('/users/invitation.json',
email: $scope.email
).success (data) ->
_log "successful"
The log file shows that
Started POST "/users/invitation.json" for 127.0.0.1 at 2014-10-24 03:48:49 +1100
Processing by Devise::InvitationsController#create as JSON
Parameters: {"email"=>"sample#mail.com", "invitation"=>{"email"=>"sample#mail.com"}}
User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = 1 ORDER BY "users"."id" ASC LIMIT 1
Completed 422 Unprocessable Entity in 3ms (Views: 0.1ms | ActiveRecord: 0.3ms)
I can figure out that the problem could be the credential. The params apparently miss
"authenticity_token"=>"MEAh9r7vD8cUxXQH9+qnjykHKV8OeC+fvuNW6Whsewg="
But don't know how to fix it. In plain rails app, every thing goes well. I can post email to user_invitation_path to invite new user.
And I'm really new to angular js, could any one help me on it?
I figure out what wrong with my code after several hours. There are 2 problems in the code. Firstly, I should add csrf manually, which should be
myAngularApp.config([
"$httpProvider", function($httpProvider) {
$httpProvider.defaults.headers.common['X-CSRF-Token'] = $('meta[name=csrf-token]').attr('content');
}
or just one simpler approach is use a gem
# Gemfile
gem 'angular_rails_csrf'
Secondly, in console, I can use User.invite!(:email => "123#example.com") to send the invitation, that because the email has been wrapped as an attribute in a User object. So in $http request, we cannot directly use email as a parameter.
$scope.inviteUser = ->
user = {
email: $scope.email
}
$http.post('/users/invitation',
user: user
)
Finally everything works well!!

Rails production.log (using Passenger) being written to by multiple processes, can't be parsed

Here's a snippet of my production.log:
Started GET "/product/514034/754240" for XX.XX.202.138 at 2012-06-21 11:52:28 -0700
Started GET "/product/614409/666897" for XX.XX.228.38 at 2012-06-21 11:52:28 -0700
Processing by ProductsController#show as HTML
Parameters: {"category_id"=>"514034", "product_id"=>"754240"}
Processing by ProductsController#show as HTML
Parameters: {"category_id"=>"614409", "product_id"=>"666897"}
Logged in 2940659 via auth cookie
Logged in 585210 via auth cookie
[e3e3fc56bb6bd137741b269ee397683c] [2940659] Read fragment views/global-caches/header (0.7ms)
[e3e3fc56bb6bd137741b269ee397683c] [2940659] Rendered shared/_email_form.html.haml (0.7ms)
[d81bb986be5acc0277c0c9e11b414249] [585210] Read fragment views/global-caches/sharebar-message (0.7ms)
[d81bb986be5acc0277c0c9e11b414249] [585210] Rendered shared/_email_form.html.haml (0.7ms)
...
As you can see, it's logging two concurrent sessions of two different users simultaneously to the same log file. This makes it impossible to parse my logs and determine, for example, the time it took to generate each kind of page, because the entries are not in the expected order of:
Started GET "/URL/BLAH" for IP at DATE
... stuff...
Completed 200 OK in XXms (ActiveRecord: YY.Yms)
Instead I get an unpredictable interleaved log like this:
Started GET "/URL/BLAH" for IP at DATE
Started GET "/URL/BLAH" for IP at DATE
... stuff...
Completed 200 OK in XXms (ActiveRecord: YY.Yms)
...stuff...
Completed 200 OK in XXms (ActiveRecord: YY.Yms)
So it's impossible to match the "completeds" with the "Started."
What I'd like is a way to have each child process write to its own log or something. Or if it's possible a way to write the each pageview's log atomically, but that might be impossible or difficult or hurt performance.
Rails 3.2 provides nice option config.log_tag
You can add to your production.rb:
config.log_tags = [ lambda { Time.now.to_i }]
So each line in your logs will be prepended by numbers. Example:
[1351867173] Started GET "/" for 127.0.0.1 at 2012-11-02 16:39:33 +0200
[1351867173] Processing by RecipesController#main as HTML
Logs are still shuffled, but now we can normalize, order them.
sort -f -s -k1.1,1.11 production.log | sed 's/^.............//' > sorted_production.log
(Sorter by first symbols (by timestamp) and remove timestamp by sed)
Now logs are easy to analyze.
In addition there is fix on related issue https://github.com/rails/rails/pull/7317 in rails 3.2.9
So keep this in mind.
Sorry for bad English... )

What is the difference in "Processing by Contoller#method as */*" and "Processing by BillsController#show as HTML"

All of my rails 3.2.2 ActiveRecord methods are being executed twice. I noticed that each execution is being processed differently, see the examples I grabbed from the console below...
Started GET "/api/bills/Jeremy%20Fox" for 127.0.0.1 at 2012-03-20 23:16:43 -0400
Processing by BillsController#show as HTML
Parameters: {"username"=>"Jeremy Fox"}
BillsForUsers Load (2.4ms) SELECT "bills_for_users".* FROM "bills_for_users" WHERE "bills_for_users"."billusername" = 'Jeremy Fox'
Completed 200 OK in 47ms (Views: 11.2ms | ActiveRecord: 2.4ms)
Started GET "/api/bills/Jeremy%20Fox" for 127.0.0.1 at 2012-03-20 23:16:44 -0400
Processing by BillsController#show as */*
Parameters: {"username"=>"Jeremy Fox"}
BillsForUsers Load (1.1ms) SELECT "bills_for_users".* FROM "bills_for_users" WHERE "bills_for_users"."billusername" = 'Jeremy Fox'
Completed 200 OK in 33ms (Views: 28.1ms | ActiveRecord: 1.1ms)
Can anyone explain to me why all of my ActiveRecord methods are being executed twice and/or what the difference is between Processing by BillsController#show as HTML and Processing by BillsController#show as */*?
Thanks.
It turns out the problem was actually the JSONView Chrome extension. As it states in the options menu...
Use safe method to parse HTTP response (*)
(*) : safe method forces the browser to send an extra HTTP request to get the raw HTTP content.
After spending days trying to figure out what I was doing wrong in my code, it was actually just chrome!
Hope no one else runs into this stupid issue.
-Jeremy
I've been grappling with this same issue. The HTML Validator Chrome extension is also guilty (with none of the fine print.)
In my case, I'm calling a ModestModel-backed search request, so the first hit (and rendering) was succeeding, followed by a phantom 500 as my non-DB search model was out of scope and nil on the second request.
Thanks, Jeremy!

406 error when template and partial exist as well as when they don't exist

I'm getting a 406 error and it's rendering a blank white page, even though the log makes it look like it's rendering my shared/404 page. I can even remove the layout and 404 page and same error. Any ideas?
Started GET "/" for 127.0.0.1 at 2012-02-19 22:26:56 -0800
Processing by MinisitesController#show as HTML
Account Load (0.4ms) SELECT "accounts".* FROM "accounts" WHERE "accounts"."full_domain" = 'test.eg.local' AND (accounts.deleted_at IS NULL) LIMIT 1
Rendered shared/404.html.haml (0.3ms)
Completed 406 Not Acceptable in 81ms (Views: 12.3ms | ActiveRecord: 2.2ms)

objects that are not created show on the page, and redirect fails

I tried out rails 3, and just started a new project. The following is all I typed.
rails new todo
cd todo
bundle install
rails generate scaffold Task done:boolean task:text created:date
rake db:migrate
rails server&
firefox 0.0.0:3000/tasks&
On page 0.0.0:3000/tasks/new, I filled in some values for the fields, and clicked the button to create a new task. It redirects to 0.0.0:3000/tasks with a blank page. When I manually reload the page, it shows up eight tasks even though there is supposed to be only one.
When I further click either show, edit, or destroy, it says, for e.g.: ActiveRecord::RecordNotFound in TasksController#show Couldn't find Task with ID=1.
When I reload to 0.0.0:3000/tasks, all eight tasks are still there.
What is wrong with this? Is rails corrupted on my computer?
Log
When I click 'create tasks', the terminal displays
Started GET "/tasks/new" for 127.0.0.1
at 2011-05-13 22:04:26 -0400
Processing by TasksController#new as
HTML Rendered tasks/_form.html.erb
(6.7ms) Rendered tasks/new.html.erb
within layouts/application (25.3ms)
Completed 200 OK in 35ms (Views:
27.9ms | ActiveRecord: 0.0ms)
folowed by something like this repeated eight times with x in tasks/x varying from 1 to 8:
Started POST "/tasks" for 127.0.0.1 at
2011-05-13 22:04:32 -0400 Processing
by TasksController#create as HTML
Parameters: {"utf8"=>"✓",
"authenticity_token"=>"QZHWWyE5KcZhLrzRhB4Fgnl9HGiQqNkn17O4CUfUUJU=",
"task"=>{"done"=>"0",
"task"=>"test\r\n",
"created(1i)"=>"2011",
"created(2i)"=>"5",
"created(3i)"=>"14"},
"commit"=>"Create Task"} AREL
(0.2ms) INSERT INTO "tasks" ("done",
"task", "created", "created_at",
"updated_at") VALUES ('f', 'test ',
'2011-05-14', '2011-05-14
02:04:32.065805', '2011-05-14
02:04:32.065805') Redirected to
http://0.0.0:3000/tasks/2 Completed
302 Found in 17ms [2011-05-13
22:04:32] ERROR URI::InvalidURIError:
the scheme http does not accept
registry part: 0.0.0:3000 (or bad
hostname?)
/usr/local/lib/ruby/1.9.1/uri/generic.rb:746:in
rescue in merge'
/usr/local/lib/ruby/1.9.1/uri/generic.rb:743:in
merge'
/usr/local/lib/ruby/1.9.1/webrick/httpresponse.rb:163:in
setup_header'
/usr/local/lib/ruby/1.9.1/webrick/httpresponse.rb:101:in
send_response'
/usr/local/lib/ruby/1.9.1/webrick/httpserver.rb:86:in
run'
/usr/local/lib/ruby/1.9.1/webrick/server.rb:183:in
block in start_thread'
You're trying to access your site using 0.0.0:3000 which is an invalid address (I'm actually surprised this even gives you access to the site at all).
Open 0.0.0.0:3000 in Firefox instead, and it will work perfectly!
(You can also use localhost:3000 or 127.0.0.1:3000)
Task is a reserved word in Rails. I guess thats the reason why rails is behaving in a starnge way.
For a list of other reserved words please refer to any of these links
http://cheat.errtheblog.com/s/rails_reserved_words/
http://www.yup.com/articles/2007/01/31/no-reservations-about-keywords-in-ruby-on-rails
http://oldwiki.rubyonrails.org/rails/pages/ReservedWords

Resources