簡體   English   中英

為webapp和api使用devise_token_auth庫

[英]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

我不知道是否有使用方式devisedevise_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中接收。

這是你需要做的:

  1. 使用devise_token_auth提供的路由登錄。
  2. 如果登錄成功,您將在標頭中收到access-tokenclienttoken-typeuid
  3. 每當您要運行必須要登錄用戶的控制器操作時,請在查詢標頭中指定access-tokenclienttoken-typeuid

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM