Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Diferent tokens from devise and devise_token_auth some times get in conflict... #780

Closed
diogowernik opened this issue Nov 30, 2016 · 2 comments

Comments

@diogowernik
Copy link

diogowernik commented Nov 30, 2016

Hi,

I am building an rails app that:

  • Is a web app, build with ruby on rails (that uses devise for autentication)
  • Is also an API (that uses devise_token_auth)

It look like that when i do the autentication with devise, i get one token

When i do the autentication with devise_token_auth, i get other token...

And some times, i get "invalid credentials"... i think that is because the tokens are diferent...

Here are the logs of the autentication with the same email and password, one from ionic app and other web app

Is it possíble to have in both same token system?

Login via ionic app

Started OPTIONS "/api/v1/auth/sign_in" for 200.9.131.11 at 2016-11-30 09:58:03 -0500
Cannot render console from 200.9.131.11! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255
Started POST "/api/v1/auth/sign_in" for 200.9.131.11 at 2016-11-30 09:58:03 -0500
Cannot render console from 200.9.131.11! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255
Processing by DeviseTokenAuth::SessionsController#create as HTML
  Parameters: {"email"=>"test123@email.com", "password"=>"[FILTERED]", "session"=>{"email"=>"test123@email.com", "password"=>"[FILTERED]"}}
  �[1m�[36mSubdomain Load (0.6ms)�[0m  �[1m�[34mSELECT  "subdomains".* FROM "subdomains" WHERE "subdomains"."address" = $1 LIMIT $2�[0m  [["address", ""], ["LIMIT", 1]]
  �[1m�[36mDomain Load (0.3ms)�[0m  �[1m�[34mSELECT  "domains".* FROM "domains" WHERE "domains"."address" = $1 LIMIT $2�[0m  [["address", "smartmarket.io"], ["LIMIT", 1]]
Unpermitted parameter: session
Unpermitted parameter: session
  �[1m�[36mUser Load (0.7ms)�[0m  �[1m�[34mSELECT  "users".* FROM "users" WHERE (email = 'test123@email.com' AND provider='email') ORDER BY "users"."id" ASC LIMIT $1�[0m  [["LIMIT", 1]]
Unpermitted parameter: session
Unpermitted parameter: session
  �[1m�[35m (0.3ms)�[0m  �[1m�[35mBEGIN�[0m
  �[1m�[36mUser Exists (0.7ms)�[0m  �[1m�[34mSELECT  1 AS one FROM "users" WHERE "users"."email" = $1 AND ("users"."id" != $2) LIMIT $3�[0m  [["email", "test123@email.com"], ["id", 15], ["LIMIT", 1]]
  �[1m�[35mSQL (0.6ms)�[0m  �[1m�[33mUPDATE "users" SET "tokens" = $1, "updated_at" = $2 WHERE "users"."id" = $3�[0m  [["tokens", "{\"_WTC8LjiWFOnszWqCJTfJA\":{\"token\":\"$2a$10$OYwA.JS9BzYxnx9SFLdYIeT/fpHuzVfXgYLTxW5g0qTw5W3PKsIni\",\"expiry\":1481727392,\"last_token\":\"$2a$10$lf3uV4hy.mzExpWCBDJ/Veqqd9i9xtnZ.5yvH.zbQSIcnH1Re7idS\",\"updated_at\":\"2016-11-30T09:56:32.183-05:00\"},\"2UVdLlH0TTW0zaTtZ93O8w\":{\"token\":\"$2a$10$7YEouDT1b3gD57O2ES6ul.l0mgd5ete79NjJp2W9WGHv5.qAZuMwq\",\"expiry\":1481727483}}"], ["updated_at", 2016-11-30 14:58:03 UTC], ["id", 15]]
  �[1m�[35m (1.0ms)�[0m  �[1m�[35mCOMMIT�[0m
  �[1m�[35m (0.1ms)�[0m  �[1m�[35mBEGIN�[0m
  �[1m�[35mSQL (1.1ms)�[0m  �[1m�[33mUPDATE "users" SET "sign_in_count" = $1, "current_sign_in_at" = $2, "last_sign_in_at" = $3, "current_sign_in_ip" = $4, "last_sign_in_ip" = $5, "updated_at" = $6 WHERE "users"."id" = $7�[0m  [["sign_in_count", 1], ["current_sign_in_at", 2016-11-30 14:58:03 UTC], ["last_sign_in_at", 2016-11-30 14:58:03 UTC], ["current_sign_in_ip", "200.9.131.11/32"], ["last_sign_in_ip", "200.9.131.11/32"], ["updated_at", 2016-11-30 14:58:03 UTC], ["id", 15]]
  �[1m�[35m (0.6ms)�[0m  �[1m�[35mCOMMIT�[0m
[active_model_serializers] Rendered ActiveModel::Serializer::Null with Hash (0.26ms)
  �[1m�[36mUser Exists (0.5ms)�[0m  �[1m�[34mSELECT  1 AS one FROM "users" WHERE "users"."email" = $1 AND ("users"."id" != $2) LIMIT $3�[0m  [["email", "test123@email.com"], ["id", 15], ["LIMIT", 1]]
  �[1m�[35m (0.1ms)�[0m  �[1m�[35mBEGIN�[0m
  �[1m�[36mUser Load (0.6ms)�[0m  �[1m�[37mSELECT  "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2 FOR UPDATE�[0m  [["id", 15], ["LIMIT", 1]]
  �[1m�[36mUser Exists (0.8ms)�[0m  �[1m�[34mSELECT  1 AS one FROM "users" WHERE "users"."email" = $1 AND ("users"."id" != $2) LIMIT $3�[0m  [["email", "test123@email.com"], ["id", 15], ["LIMIT", 1]]
  �[1m�[35mSQL (0.6ms)�[0m  �[1m�[33mUPDATE "users" SET "tokens" = $1, "updated_at" = $2 WHERE "users"."id" = $3�[0m  [["tokens", "{\"_WTC8LjiWFOnszWqCJTfJA\":{\"token\":\"$2a$10$OYwA.JS9BzYxnx9SFLdYIeT/fpHuzVfXgYLTxW5g0qTw5W3PKsIni\",\"expiry\":1481727392,\"last_token\":\"$2a$10$lf3uV4hy.mzExpWCBDJ/Veqqd9i9xtnZ.5yvH.zbQSIcnH1Re7idS\",\"updated_at\":\"2016-11-30T09:56:32.183-05:00\"},\"2UVdLlH0TTW0zaTtZ93O8w\":{\"token\":\"$2a$10$keGTG9db2pNot1dkMmnkcO41/3MF3KQntYJv8Y/q7.8g/lhkh8zwG\",\"expiry\":1481727483,\"last_token\":\"$2a$10$7YEouDT1b3gD57O2ES6ul.l0mgd5ete79NjJp2W9WGHv5.qAZuMwq\",\"updated_at\":\"2016-11-30T09:58:03.753-05:00\"}}"], ["updated_at", 2016-11-30 14:58:03 UTC], ["id", 15]]
  �[1m�[35m (1.0ms)�[0m  �[1m�[35mCOMMIT�[0m
Completed 200 OK in 513ms (Views: 1.4ms | ActiveRecord: 10.0ms)

Login with same email and password with devise:

Started POST "/login" for 200.9.131.11 at 2016-11-30 09:59:55 -0500
Cannot render console from 200.9.131.11! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255
Processing by Devise::SessionsController#create as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"YikU/yRF8zpo5kPwRSe675GjzVLUVlZDt4XVCW8uB1cTfSc01XGtzVtw8bVll5/Mpi0i+a4gQV0e7ALfpifMcg==", "user"=>{"email"=>"test123@email.com", "password"=>"[FILTERED]", "remember_me"=>"0"}, "commit"=>"Log In"}
  �[1m�[36mSubdomain Load (0.4ms)�[0m  �[1m�[34mSELECT  "subdomains".* FROM "subdomains" WHERE "subdomains"."address" = $1 LIMIT $2�[0m  [["address", "yoga"], ["LIMIT", 1]]
  �[1m�[36mDomain Load (0.6ms)�[0m  �[1m�[34mSELECT  "domains".* FROM "domains" WHERE "domains"."address" = $1 LIMIT $2�[0m  [["address", "smartmarket.io"], ["LIMIT", 1]]
  �[1m�[36mUser Load (0.8ms)�[0m  �[1m�[34mSELECT  "users".* FROM "users" WHERE "users"."email" = $1 ORDER BY "users"."id" ASC LIMIT $2�[0m  [["email", "test123@email.com"], ["LIMIT", 1]]
  �[1m�[35m (0.2ms)�[0m  �[1m�[35mBEGIN�[0m
  �[1m�[35mSQL (0.7ms)�[0m  �[1m�[33mUPDATE "users" SET "current_sign_in_at" = $1, "sign_in_count" = $2, "updated_at" = $3 WHERE "users"."id" = $4�[0m  [["current_sign_in_at", 2016-11-30 14:59:55 UTC], ["sign_in_count", 2], ["updated_at", 2016-11-30 14:59:55 UTC], ["id", 15]]
  �[1m�[35m (0.6ms)�[0m  �[1m�[35mCOMMIT�[0m
Redirected to http://example.com/
Completed 302 Found in 246ms (ActiveRecord: 15.5ms)
@brunowego
Copy link

Duplicate #600

@zachfeldman
Copy link
Contributor

Solution posted there (#600)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants