[英]Using devise_token_auth library for both webapp and api
我正在使用devise_token_auth( https://github.com/lynndylanhurley/devise_token_auth )對移動設備進行身份驗證,並且我還需要為我的Web應用程序使用devise。
問題是用戶可以通過devise_token_auth進行注冊,但是如果用戶登錄並嘗試在包含“ before_action :authenticate_user!
”的控制器中調用某些功能, before_action :authenticate_user!
收到一條錯誤消息,提示Authorized Users Only
。
我不知道是否有使用方式devise
和devise_token_auth
在一起。
碼:
class RestrictedController < ApplicationController
before_action :authenticate_user!
def stuff
head :ok
end
end
首先,您應該知道devise
不再管理用戶的會話。 這就是為什么建議使用devise_token_auth
。
每當你指定before_action :authenticate_user!
在Controller上,所有操作(如RestrictedController#stuff
)都需要用戶登錄devise_token_auth
期望在下面列出的查詢標題4 params中接收。
這是你需要做的:
devise_token_auth
提供的路由登錄。 access-token
, client
, token-type
和uid
。 access-token
, client
, token-type
和uid
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.