I am trying out how Devise works with one of my projects for user authentication. There is a user requirement that their admin should be able to generate a batch of username and user's password from time to time, and then the admin will email the new username and password to his users.
Assume the admin has the knowledge of direct SQL on the MySQL database, how can the generated usernames/passwords recognized by Devise? Thanks!
我即将开始在我们公司设立一个仅限员工的Rails应用程序来处理敏感信息.将会有防火墙,物理安全措施等.我现在关心的是应用程序的登录过程.
我想使用Devise进行身份验证.Devise最安全的配置是什么?
我想我会做以下事情:
config.paranoid这样攻击者无法判断他们是否猜到了有效的电子邮件地址一些我不确定的具体事情,用devise.rb斜体字引用:
我还缺少什么?
我知道有很多关于这个主题的信息,但我找不到任何最新的信息.我看到这样的主题与rails和android身份验证相关但我看到 TokenAuthenticatable现在已经从设计中删除了.
我的问题很简单:有没有一种很好的方法来使用Rails 4从本机Android和iPhone应用程序验证用户?有没有人知道提供解决方案的好教程或文章?
Adam Waite添加赏金:
我刚刚在这个问题上开了一个500赏金,因为我找不到在任何地方从iOS应用程序到Rails API验证用户的正确做法.这是我考虑做的事情,但不知道它是否安全?!:
我们假设我们有一个User记录.用户已注册已User在数据库中使用email列和password_digest列创建记录的帐户.
当用户登录时,我希望该用户在移动应用程序上保持身份验证,直到明确注销.
我想我们将需要基于令牌的身份验证.我可能会在创建时创建一个ApiKey记录,User并将其保存为User记录中的关联.
当用户登录/注册时,响应将包含一个API令牌(类似于SecureRandom.hex),它将保存在iOS Keychain中,并与所有后续请求一起使用,通过将其传递到标头并使用以下内容进行验证来验证用户:
before_filter :restrict_access
private
def restrict_access
authenticate_or_request_with_http_token do |token, options|
ApiKey.exists?(access_token: token)
end
Run Code Online (Sandbox Code Playgroud)
这样安全吗?我是否应该使用每个请求刷新令牌并将其包含在响应中?
我还有其他选择吗?Facebook,Twitter和Pinterest的喜欢做什么?
我知道OAuth2.0,但这不是用于授予外部应用程序吗?
有没有一个宝石可以管理这些?
对不起,这里完全不确定.
500到最佳答案.
我希望覆盖Devise::RegistrationsController实现一些自定义功能.为此,我创建了一个RegistrationsController像这样的新东西:
# /app/controllers/registrations_controller.rb
class RegistrationsController < Devise::RegistrationsController
def new
super
end
end
Run Code Online (Sandbox Code Playgroud)
并设置我的路线,如下所示:
devise_for :users, :controllers => { :registrations => "registrations" }
Run Code Online (Sandbox Code Playgroud)
并试图像这样测试它:
describe RegistrationsController do
describe "GET 'new'" do
it "should be successful" do
get :new
response.should be_success
end
end
end
Run Code Online (Sandbox Code Playgroud)
但这给了我一个错误:
1) RegistrationsController GET 'new' should be successful
Failure/Error: get :new
AbstractController::ActionNotFound:
Could not find devise mapping for path "/users/sign_up".
Maybe you forgot to wrap your route inside the scope block? For example:
devise_scope …Run Code Online (Sandbox Code Playgroud) 我已经在我的Web应用程序中配置了设计.我有以下工作流程的问题:
要访问管理面板,我需要登录.之后,我正常导航到我的网络应用程序的管理面板.当我单击logout时,它会将我重定向到根页面,这是我想要的行为.
奇怪的是,在这个页面中开始,在上面的操作之后,我点击了浏览器的后退按钮,它显示了我的缓存的最后一页.我的会话已被破坏,因为如果我点击刷新它重定向我并提示登录访问该页面,但我不希望能够看到浏览器的最后一个历史页面.
这怎么可能,我该怎么做才能防止它呢?它与浏览器缓存有关吗?解决此问题的唯一方法是从登录页面中删除缓存以防止此行为?我怎样才能做到这一点?
我正在使用设计,rolify和cancan.我也在使用rspec和FactoryGirl进行测试.现在我正在进行一些测试,我想为这些测试定义具有不同角色的用户.以下是我目前对如何使用FactoryGirl进行测试的猜测:
FactoryGirl.define do
factory :user do
name 'Test User'
email 'example@example.com'
password 'please'
password_confirmation 'please'
# required if the Devise Confirmable module is used
confirmed_at Time.now
factory :admin do
self.has_role :admin
end
factory :curator do
self.has_role :curator
end
factory :super_admin do
self.has_role :super_admin
end
end
end
Run Code Online (Sandbox Code Playgroud)
以下是我的一些测试似乎没有正确编写:require'pec_helper'
describe "Pages" do
subject { page }
before do
@newpage = FactoryGirl.create(:page)
@newpage.save
end
context 'not logged in' do
it_behaves_like 'not admin'
end
context 'logged in' do
context 'as user' do
before do …Run Code Online (Sandbox Code Playgroud) Devise背后的团队通过blogpost http://blog.plataformatec.com.br/2013/05/devise-and-rails-4/宣布
它发布了一个与Rails 4兼容的版本,称之为'3.0 rc' .在同一篇博文中,它也表示正在发布Devise 2.2.4.
我正在尝试构建一个Rails 4应用程序.当我这样做时gem install Devise,它安装了2.2.4,而不是与Rails 4兼容的版本.
Fetching: devise-2.2.4.gem (100%)
Run Code Online (Sandbox Code Playgroud)
我从blogpost中关于强参数的评论中假设我不能与Rails 4兼容.
我查看了Devise的github页面,但对我来说,如何安装与Rails 4兼容的版本并不明显.你能帮忙吗?
https://github.com/plataformatec/devise
注意,我试过了
gem install devise --version 3.0.0.rc1
Run Code Online (Sandbox Code Playgroud)
但它说
ERROR: Could not find a valid gem 'devise' (= 3.0.0.rc1) in any repository
ERROR: Possible alternatives: devise
Run Code Online (Sandbox Code Playgroud) 我正在尝试在Rails中编写Rspec测试,使用Devise帮助方法进行登录和注销.sign_in方法无效.但是,在对应用程序进行一系列更改之前,它已经提前工作了.
我尝试过的事情:
到目前为止,没有骰子.使用已登录用户测试控制器需要做些什么?
错误信息:
OrderItemsController GET #index renders the :index view
Failure/Error: sign_in :admin
NoMethodError:
undefined method `sign_in' for # <RSpec::ExampleGroups::OrderItemsController_2::GETIndex:0x00000102c002d0>
# ./spec/controllers/order_items_controller_spec.rb:6:in `block (2 levels) in <top (required)>'
Run Code Online (Sandbox Code Playgroud)
控制器规格
require 'spec_helper'
describe OrderItemsController do
before (:each) do
admin = create(:admin)
sign_in :admin
end
describe "GET #index" do
it "renders the :index view" do
get :index
expect( response ).to render_template :index
end
end
end
Run Code Online (Sandbox Code Playgroud)
spec_helper.rb
require 'rspec/rails'
require 'capybara/rspec'
RSpec.configure do |config|
config.include ApplicationHelper
config.include …Run Code Online (Sandbox Code Playgroud) 当我跑rails s:
/Users/galli01anthony/.rvm/gems/ruby-2.1.3/gems/devise-3.2.4/lib/devise/rails/routes.rb:455:in
`ensure in with_devise_exclusive_scope': undefined method `merge!' for
#<ActionDispatch::Routing::Mapper::Scope:0x007f8743e19020> (NoMethodError)
Run Code Online (Sandbox Code Playgroud)
当我跑rake db:reset或db:migrate或 db:setup:
rake aborted!
NoMethodError: undefined method `merge!' for #<ActionDispatch::Routing::Mapper::Scope:0x007fca8d3f2780>
Run Code Online (Sandbox Code Playgroud) 我在文档中找不到这个.我发现的只是一种after_sign_in_path_for方法.我想要的是这样的东西,sign_in_path_for(:account)所以我不必硬编码"/ account/sign_in"路径.如果Devise有这样的事情,任何想法?