【问题标题】:Devise Token Auth - Not returning tokens to client设计令牌身份验证 - 不将令牌返回给客户端
【发布时间】:2021-05-18 23:36:21
【问题描述】:

设置 devise_token_auth。

继续解决源代码中的问题。

例如:

def token_validation_response
  as_json(except: %i[tokens created_at updated_at])
end

将从以下位置调用:

SessionsController::create > render_create_success > token_validation_response

据我了解,您需要将令牌获取到客户端并将其存储在客户端并随每个请求一起发送。 如果我们不将令牌提供给客户端和 except 它,我不确定这应该如何工作。

except: %i[tokens created_at updated_at]

来源链接: https://github.com/lynndylanhurley/devise_token_auth/blob/c92258038c05fcc8f6a0374ccce2e63b9f8d5312/app/controllers/devise_token_auth/sessions_controller.rb#L36

https://github.com/lynndylanhurley/devise_token_auth/blob/c92258038c05fcc8f6a0374ccce2e63b9f8d5312/app/models/devise_token_auth/concerns/user.rb#L205

【问题讨论】:

    标签: ruby-on-rails devise devise-token-auth


    【解决方案1】:

    也许这对某人有用。令牌出现在标题而不是正文中。

    更新:

    我还需要解决客户端 cors 问题。

    一些有帮助的选项:

    Vue Axios CORS policy: No 'Access-Control-Allow-Origin'

    https://blog.bitsrc.io/how-and-why-you-should-avoid-cors-in-single-page-apps-db25452ad2f8

    最简单的解决方案是在命令行中执行 chrome:

    open -n -a /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --args --user-data-dir="/tmp/chrome_dev_test" --disable-web-security

    来源:https://alfilatov.com/posts/run-chrome-without-cors/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-16
      • 1970-01-01
      • 2015-12-21
      • 2013-08-19
      • 1970-01-01
      • 2016-05-08
      相关资源
      最近更新 更多