Skip to content
This repository has been archived by the owner on Mar 22, 2021. It is now read-only.

login without email #183

Open
ernandejr opened this issue Aug 14, 2017 · 3 comments
Open

login without email #183

ernandejr opened this issue Aug 14, 2017 · 3 comments

Comments

@ernandejr
Copy link

My application logs in with username, how can I generate the token with username instead of email?

@thalesfp
Copy link

thalesfp commented Aug 29, 2017

You can modify the default behavior implementing within your entity model a class method from_token_request that takes the request in argument.

class User < ActiveRecord::Base
  def self.from_token_request(request)
    username = request.params["auth"] && request.params["auth"]["username"]
    self.find_by(username: username)
  end
end

More info: https://github.com/nsarno/knock#via-the-entity-model

@przbadu
Copy link

przbadu commented Nov 10, 2017

You might also need to override strong parameters:

app/controllers/user_token_controller.rb

class UserTokenController < Knock::AuthTokenController

  private

  def auth_params
    params.require(:auth).permit(:username, :password)
  end
end

app/models/user.rb

class User < ActiveRecord::Base
  def self.from_token_request(request)
    username = request.params["auth"] && request.params["auth"]["username"]
    self.find_by(username: username)
  end
end

@rubiii
Copy link

rubiii commented Aug 5, 2018

I’m also using a username and no emails. What about making this configurable?

@andrerpbts andrerpbts mentioned this issue Dec 13, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants