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

Getting 401 unauthorized Error #361

Open
nitinzd opened this issue May 2, 2020 · 0 comments
Open

Getting 401 unauthorized Error #361

nitinzd opened this issue May 2, 2020 · 0 comments
Labels
support request This issue is a request for support using Simple Token Authentication.

Comments

@nitinzd
Copy link

nitinzd commented May 2, 2020

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"}

@gonzalo-bulnes gonzalo-bulnes added the support request This issue is a request for support using Simple Token Authentication. label Jan 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
support request This issue is a request for support using Simple Token Authentication.
Projects
None yet
Development

No branches or pull requests

2 participants