You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
First of all, thanks @gonzalo-bulnes for creating such a nice gem.
I'm using Rails 5.1, Devise and Mongoid. I followed everything mentioned in readme and setup the gem. However I'm getting 401 unauthorized error on r Rails console. I overridden sessions controller to get authentication token by providing user name and password. I got the token and I'm requesting as get: http://192.168.0.118:3000/quizzes
And sending headers as:
headers: {"Content-Type": "application/json", "Accept": "application/json", "user": {"login": "email", "authentication_token": "token"}}.
What am I missing? or making wrong?
Following is my setup:
Gem file:
gem 'simple_token_authentication', '~> 1.0'
simple_token_authentication.rb:
SimpleTokenAuthentication.configure do |config|
config.sign_in_token = false
config.header_names = {user: {authentication_token: 'authentication_token', login: 'login' }}
config.identifiers = {user: 'login'}
config.skip_devise_trackable = true
end
Model:
include Mongoid::Document
devise :database_authenticatable, :registerable,:invitable,
:recoverable, :rememberable, :trackable, :validatable
#Token Authenticatable
acts_as_token_authenticatable
attr_accessor :login
#For simple token
field :authentication_token
Controller:
module Api
module V1
class BaseController < ActionController::API
First of all, thanks @gonzalo-bulnes for creating such a nice gem.
I'm using Rails 5.1, Devise and Mongoid. I followed everything mentioned in readme and setup the gem. However I'm getting 401 unauthorized error on r Rails console. I overridden sessions controller to get authentication token by providing user name and password. I got the token and I'm requesting as get:
http://192.168.0.118:3000/quizzes
And sending headers as:
headers: {"Content-Type": "application/json", "Accept": "application/json", "user": {"login": "email", "authentication_token": "token"}}.
What am I missing? or making wrong?
Following is my setup:
Gem file:
gem 'simple_token_authentication', '~> 1.0'
simple_token_authentication.rb:
SimpleTokenAuthentication.configure do |config|
config.sign_in_token = false
config.header_names = {user: {authentication_token: 'authentication_token', login: 'login' }}
config.identifiers = {user: 'login'}
config.skip_devise_trackable = true
end
Model:
include Mongoid::Document
devise :database_authenticatable, :registerable,:invitable,
:recoverable, :rememberable, :trackable, :validatable
#Token Authenticatable
acts_as_token_authenticatable
attr_accessor :login
#For simple token
field :authentication_token
Controller:
module Api
module V1
class BaseController < ActionController::API
acts_as_token_authentication_handler_for User, fallback: :exception
respond_to :json
routes.rb:
devise_for :users, controllers: {invitations: "invitations", registrations: "admin/registrations", sessions: "api/v1/sessions"}
The text was updated successfully, but these errors were encountered: