lynndylanhurley / lynndylanhurley/devise_token_auth
resource_class is undefined
- Dominant language
- Ruby
- Stars
- 3.6k
- Forks
- 1.1k
- PR merge metrics
- No merged PRs in 30d
Description
models
```
class User < ActiveRecord::Base
include DeviseTokenAuth::Concerns::User
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
```
routes
```
Rails.application.routes.draw do
mount_devise_token_auth_for "User", at: "auth"
```
controller
```
class ApplicationController < ActionController::Base
include DeviseTokenAuth::Concerns::SetUserByToken
...
protect_from_forgery with: :null_session
end
```
config/initializers/omniauth.rb
```
Rails.application.config.middleware.use OmniAuth::Builder do
provider :facebook,
"...",
"...",
scope: 'email', provider_ignores_state: true
end
```
config/initializers/devise_token_auth.rb
```
DeviseTokenAuth.setup do |config|
# By default the authorization headers will change after each request. The
# client is responsible for keeping track of the changing tokens. Change
# this to false to prevent the Authorization header from changing after
# each request.
config.change_headers_on_each_request = false
# By default, users will need to re-authenticate after 2 weeks. This setting
# determines how long tokens will remain valid after they are issued.
config.token_lifespan = 10.weeks
# Sets the max number of concurrent devices per user, which is 10 by default.
# After this limit is reached, the oldest tokens will be removed.
# config.max_number_of_devices = 10
# Sometimes it's necessary to make several requests to the API at the same
# time. In this case, each request in the batch will need to share the same
# auth token. This setting determines how far apart the requests can be while
# still using the same auth token.
# config.batch_request_buffer_throttle = 5.seconds
# This route will be the prefix for all oauth2 redirect callbacks. For
# example, using the default '/omniauth', the github oauth2 provider will
# redirect successful authentications to '/omniauth/github/callback'
config.omniauth_prefix = "/omniauth"
# By default sending current password is not needed for the password update.
# Uncomment to enforce current_password param to be checked before all
# attribute updates. Set it to :password if you want it to be checked only if
# password is updated.
# config.check_current_password_before_update = :attributes
# By default we will use callbacks for single omniauth.
# It depends on fields like email, provider and uid.
config.default_callbacks = true
# Makes it possible to change the headers names
# config.headers_names = {:'access-token' => 'access-token',
# :'client' => 'client',
# :'expiry' => 'expiry',
# :'uid' => 'uid',
# :'token-type' => 'token-type' }
# By default, only Bearer Token authentication is implemented out of the box.
# If, however, you wish to integrate with legacy Devise authentication, you can
# do so by enabling this flag. NOTE: This feature is highly experimental!
# config.enable_standard_devise_support = false
end
```
request from front end:
```
AuthSession.startAsync({
authUrl:
`https://www.facebook.com/v2.12/dialog/oauth` +
`?client_id=${CONFIG.FACEBOOK.APP_ID}` +
`&response_type=code` +
`&redirect_uri=${CONFIG.FACEBOOK.REDIRECT_URI}`,
})
```

Contributor guide
Research direction
Reproduce the Facebook authentication flow using the shown User model, mounted route, ApplicationController, and config/initializers/omniauth.rb setup. Start by tracing where the reported resource_class error occurs in the DeviseTokenAuth and OmniAuth integration; done means the supplied flow no longer raises the undefined-resource_class error and the behavior is covered by a regression check.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rails, ruby
- Domain
- api, authentication, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100