简体   繁体   English

如果没有令牌/错误令牌,Guardian.Plug.VerifyHeader不执行任何操作

[英]Guardian.Plug.VerifyHeader do nothing if no token / wrong token

From router: 来自路由器:

  pipeline :possibly_authorized do
    plug(:fetch_session)

    plug(
      Guardian.Plug.Pipeline,
      module: BoilerplateWeb.Guardian,
      error_handler: BoilerplateWeb.AuthErrorController
    )

    plug Guardian.Plug.VerifyHeader, realm: :none
    plug Guardian.Plug.LoadResource, allow_blank: true
  end

How do I make plug Guardian.Plug.VerifyHeader do nothing if token is missing or wrong? 如果令牌丢失或错误,如何使plug Guardian.Plug.VerifyHeader不执行任何操作? Now it raises error via error_handler. 现在它通过error_handler引发错误。

Edit: The goal is to still check for the token, if it's present/valid then next plug ( LoadResource ) would get current_user, if not then current_user should be nil without raising. 编辑:目标是仍然检查令牌,如果它存在/有效然后下一个插件( LoadResource )将获得current_user,如果没有那么current_user应该是nil而不提高。

Based on https://github.com/ueberauth/guardian/blob/v1.2.1/lib/guardian/plug/verify_header.ex#L94 基于https://github.com/ueberauth/guardian/blob/v1.2.1/lib/guardian/plug/verify_header.ex#L94

you can see that guardian will do nothing when token is not found, it only halt when the token is invalid. 你可以看到,当找不到令牌时,监护人什么都不做,只有当令牌无效时它才会停止。

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

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