使用 Devise 验证静态文件?
Authenticate static files with Devise?
我在 /public/support
的网站上有一个静态的 Jekyll 支持页面。主要的 rails 应用程序在 devise 之后——整个过程。如果您未通过身份验证,您将被踢回到登录状态。我可以 'hide' Devise 身份验证背后的这个静态站点 - 即只允许在经过身份验证时访问静态页面吗?
我最终找到了这个:
https://docs.nginx.com/nginx/admin-guide/security-controls/configuring-subrequest-authentication/
在我的 NGINX 配置中我有这个:
location /support {
auth_request /auth;
auth_request_set $auth_status $upstream_status;
error_page 403 https://$host;
}
在我的应用程序控制器中我有:
before_action :authenticate_user!, except: :auth
这个by-passes设计。
在路线中:
get '/auth', to: 'errors#auth'
将它添加到我现有的自定义错误控制器中是有意义的。
然后在控制器中:
def auth
user_signed_in? ? render(status: 200, layout: :blank) : render(status: 403, layout: :blank)
end
空白布局没有内容 - 只是一个 <%= yield %>
。
如果用户有一个打开的 Devise 会话,他们可以访问支持站点,否则他们将被重定向到登录页面(Devise 的默认设置)。
我在 /public/support
的网站上有一个静态的 Jekyll 支持页面。主要的 rails 应用程序在 devise 之后——整个过程。如果您未通过身份验证,您将被踢回到登录状态。我可以 'hide' Devise 身份验证背后的这个静态站点 - 即只允许在经过身份验证时访问静态页面吗?
我最终找到了这个:
https://docs.nginx.com/nginx/admin-guide/security-controls/configuring-subrequest-authentication/
在我的 NGINX 配置中我有这个:
location /support {
auth_request /auth;
auth_request_set $auth_status $upstream_status;
error_page 403 https://$host;
}
在我的应用程序控制器中我有:
before_action :authenticate_user!, except: :auth
这个by-passes设计。
在路线中:
get '/auth', to: 'errors#auth'
将它添加到我现有的自定义错误控制器中是有意义的。
然后在控制器中:
def auth
user_signed_in? ? render(status: 200, layout: :blank) : render(status: 403, layout: :blank)
end
空白布局没有内容 - 只是一个 <%= yield %>
。
如果用户有一个打开的 Devise 会话,他们可以访问支持站点,否则他们将被重定向到登录页面(Devise 的默认设置)。