简体   繁体   English

将devise_token_auth与表单身份验证一起使用

[英]Using devise_token_auth with form auth

I'm trying to allow using on mobile devices to be authenticated using a token, while still using the webforms for the web application. 我正在尝试允许在移动设备上使用令牌进行身份验证,同时仍然使用Web应用程序的webforms。 I decided to use devise_token_auth . 我决定使用devise_token_auth Whenever I try and start the application I get an error because a session path is already defined. 每当我尝试启动应用程序时,我都会收到错误,因为已经定义了会话路径。

error 错误

ArgumentError: Invalid route name, already in use: 'new_provider_session' 

config/routes.rb 配置/ routes.rb中

mount_devise_token_auth_for 'Provider', at: 'api/v1/auth'
  devise_for :providers, controllers: {} do
    get 'providers/sign_in', to: 'web/sessions#new'
    delete 'providers/sign_out', to: 'web/sessions#destroy'
  end
  root to: 'web/welcome#welcome'

  devise_for :admins, controllers: {} do
    get 'admins/sign_in', to: 'web/sessions#new'
    delete 'admins/sign_out', to: 'web/sessions#destroy'
  end

try this: 试试这个:

Generate the Provider resource with the devise_token_auth generator 使用devise_token_auth生成器生成Provider资源

$ rails g devise_token_auth:install Provider auth

then change the config/routes.rb for placing this routes inside the namespaces for API versioning 然后更改config/routes.rb以将此路由放在名称空间中以进行API版本控制

namespace :api do
  namespace :v1 do
    mount_devise_token_auth_for 'Provider', at: 'auth'
  end
end

Check the routes 检查路线

$ rake routes

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM