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

undefined method `provider' for #<User:0x007f49fd5da2e8> #257

Closed
user12121212 opened this issue May 28, 2015 · 13 comments · Fixed by #302
Closed

undefined method `provider' for #<User:0x007f49fd5da2e8> #257

user12121212 opened this issue May 28, 2015 · 13 comments · Fixed by #302

Comments

@user12121212
Copy link

I'm trying to setup the devise token auth for a rails application. I installed the gem and configured the roots and run those migrations. But I'm getting undefined methodprovider' for #User:0x007f49fd5da2e8` error while creating a user.

    NoMethodError in Devise::RegistrationsController#create
             undefined method `provider' for #<User:0x007f49fd5da2e8>

              Extracted source (around line #433):

          else
           match = match_attribute_method?(method.to_s)
           match ? attribute_missing(match, *args, &block) : super
          end
          end

and the route.rb is like this

   devise_for :admin_users, ActiveAdmin::Devise.config
   ActiveAdmin.routes(self)
   devise_for :users
   namespace :api do
     scope :v1 do
      mount_devise_token_auth_for 'User', at: 'auth'
     end
   end

schema

create_table "users", force: :cascade do |t|
t.string   "email",                  default: "", null: false
t.string   "encrypted_password",     default: "", null: false
t.string   "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.integer  "sign_in_count",          default: 0,  null: false
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.string   "current_sign_in_ip"
t.string   "last_sign_in_ip"
t.datetime "created_at"
t.datetime "updated_at"
t.string   "authentication_token"
t.string   "provider",                            null: false
t.string   "uid",                    default: "", null: false
t.string   "confirmation_token"
t.datetime "confirmed_at"
t.datetime "confirmation_sent_at"
t.string   "unconfirmed_email"
t.string   "name"
t.string   "nickname"
t.string   "image"
t.string   "tokens"
end

   add_index "users", ["authentication_token"], name: "index_users_on_authentication_token", using: :btree
   add_index "users", ["email"], name: "index_users_on_email", unique: true, using: :btree
   add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree
   add_index "users", ["uid", "provider"], name: "index_users_on_uid_and_provider", unique: true, using: :btree

User model

     class User < ActiveRecord::Base
      # Include default devise modules.
      devise :database_authenticatable, :registerable,
        :recoverable, :rememberable, :trackable, :validatable,
        :confirmable, :omniauthable
     include DeviseTokenAuth::Concerns::User
    has_many :movies
    has_many :reviews

   end

The POST request I used to signup.

{
    "user": {
    "email": "[email protected]",
    "password": "password12345678",
    "password_confirmation": "password12345678" }

     }

and the response is like this.

    {"status":"error","errors":["Please submit proper sign up data in request body."]}

What will be the issue behind that error, how can I solve it?

@ACPK
Copy link

ACPK commented May 28, 2015

Try passing "email" as the provider.

@jancel
Copy link

jancel commented May 28, 2015

I am seeing this error too simply trying to run rspec. First it was the uid, then it's the provider. Can we get it made clear in the documentation that this gem doesn't actually work "out of the box".

Maybe we could just provide the necessary steps to get it to work in the setup instructions.

@jancel
Copy link

jancel commented May 28, 2015

Here is what I did, and it seems to have at least got the initial specs running.

edited below: making it a little more palatable

  before_validation :set_provider
  def set_provider
    self[:provider] = "email" if self[:provider].blank?
  end

  before_validation :set_uid
  def set_uid
    self[:uid] = self[:email] if self[:uid].blank? && self[:email].present?
  end

@user12121212
Copy link
Author

@jancel that done the halfjob, Now I can create users from admin panel. But how I still getting the same error while trying to signup to POST the JSON. Is that JSON schema is correct?

@jancel
Copy link

jancel commented May 29, 2015

I haven't plugged my front end in yet but will be working on that this
evening. I will report back.

On Friday, May 29, 2015, user12121212 [email protected] wrote:

@jancel https://github.com/jancel that done the halfjob, Now I can
create users from admin panel. But how I still getting the same error while
trying to signup to POST the JSON. Is that schema is correct?


Reply to this email directly or view it on GitHub
#257 (comment)
.

Jeff Ancel

(314) 703-8829 - Main

www.jeffancel.com

@user12121212
Copy link
Author

@jancel That would be great!

@user12121212
Copy link
Author

I tried to POST something like this.

{"email":"[email protected]", "password":"12345678", "password_confirmation":"12345678"}

But I'm getting an error like this.

{"status":"error","data":{"id":null,"email":"[email protected]","created_at":null,"updated_at":null, "provider":"email","uid":"","name":null,"nickname":null,"image":null},"errors":["Missing `confirm_success_url` param."]}

@nicolas-besnard
Copy link
Contributor

You should read the error message CAREFULLY, the answer is in it :)

@jancel
Copy link

jancel commented May 29, 2015

Haha. Nice. So you need to send in a confirm_success_url, love the error
message.

On Fri, May 29, 2015 at 3:34 PM, Nicolas Besnard [email protected]
wrote:

You should read the error message CAREFULLY, the answer is in it :)


Reply to this email directly or view it on GitHub
#257 (comment)
.

Jeff Ancel

(314) 703-8829 - Main

www.jeffancel.com

@user12121212
Copy link
Author

@nicolas-besnard got it :)

I just disabled the confirmable method and I'm getting succes response. here is the success response.

{"status":"success","data":{"id":5,"email":"[email protected]","created_at":"2015-05-30T12:38:07.480Z","updated_at":"2015-05-30T12:38:07.709Z", "provider":"email","uid":"[email protected]","name":null,"nickname":null,"image":null}}

and here is the generated token in DB.
{"5ALoqN1P33Ji5KnCaAraeQ"=>{"token"=>"$2a$10$mHNxnyVwYu3z1RWjLLjttuKl2LySiZBbOAfetvDj38NihyA8re6Ai", "expiry"=>1434198553, "last_token"=>"$2a$10$C7J3HEUX.vkL2Sor9hNRC.OjvuWhFqe7h5jF/QGwQiaKh7lTERm4u", "updated_at"=>"2015-05-30T17:59:13.393+05:30"}}

How can I add those tokens into the responses?

I believe I have to send the token while accessing the protected methods.

Sorry, I haven't experimented with authentication systems.

@nicolas-besnard
Copy link
Contributor

You should read the documentation

On Sat, May 30, 2015 at 3:03 PM user12121212 [email protected]
wrote:

@nicolas-besnard https://github.com/nicolas-besnard got it :)

I just disabled the confirmable method and I'm getting succes response.
here is the success response.

{"status":"success","data":{"id":5,"email":"[email protected]","created_at":"2015-05-30T12:38:07.480Z","updated_at":"2015-05-30T12:38:07.709Z",
"provider":"email","uid":"[email protected]
","name":null,"nickname":null,"image":null}}

and here is the generated token in DB.
{"5ALoqN1P33Ji5KnCaAraeQ"=>{"token"=>"$2a$10$mHNxnyVwYu3z1RWjLLjttuKl2LySiZBbOAfetvDj38NihyA8re6Ai",
"expiry"=>1434198553,
"last_token"=>"$2a$10$C7J3HEUX.vkL2Sor9hNRC.OjvuWhFqe7h5jF/QGwQiaKh7lTERm4u",
"updated_at"=>"2015-05-30T17:59:13.393+05:30"}}

How could I add those tokens into the responses?

Sorry, I haven't experimented with authentication systems.


Reply to this email directly or view it on GitHub
#257 (comment)
.

@user12121212
Copy link
Author

@nicolas-besnard I was little late to read the concept portion of the documentation :D
https://github.com/lynndylanhurley/ng-token-auth/raw/master/test/app/images/flow/token-update-detail.jpg

Basically, every response will have token which can be user for the next request. How can we handle that situation in Android/iOS app? any easy way?

@nicolas-besnard
Copy link
Contributor

After each request, you store the new access-token, client and uid. As I
said, this is in the documentation :)

On Sat, May 30, 2015 at 3:24 PM user12121212 [email protected]
wrote:

@nicolas-besnard https://github.com/nicolas-besnard I was little late
to read the concept portion of the documentation :D

Basically, every response will have token which can be user for the next
request. How can we handle that situation in Android/iOS app?


Reply to this email directly or view it on GitHub
#257 (comment)
.

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

Successfully merging a pull request may close this issue.

4 participants