标签: devise

How to auto-generate passwords in Rails Devise?

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!

ruby-on-rails devise

31
推荐指数
3
解决办法
2万
查看次数

什么是最安全的Devise配置?

我即将开始在我们公司设立一个仅限员工的Rails应用程序来处理敏感信息.将会有防火墙,物理安全措施等.我现在关心的是应用程序的登录过程.

我想使用Devise进行身份验证.Devise最安全的配置是什么?

我想我会做以下事情:

  • 在少量登录尝试失败后锁定帐户
  • 使用config.paranoid这样攻击者无法判断他们是否猜到了有效的电子邮件地址
  • 也许通过电子邮件禁用密码重置?

一些我不确定的具体事情,用devise.rb斜体字引用:

  • 胡椒.Devise可以选择"设置胡椒来生成加密密码".我的理解是,这是一个单独的,特定于应用程序的值,它将诸如"password123"之类的愚蠢密码转换为类似"password123K#(!@ akdlwekdf"或"*%!kd39gpassword123"或类似之前的任何哈希值).这是为了挫败彩虹表攻击,但我对这篇文章的理解是,它不如每个密码的独特盐那么好.然后,这篇文章本文说bcrypt有内置的盐.使用胡椒与bcrypt真的添加任何东西吗?我可以,还有什么需要,还有一个盐柱吗?
  • 伸展."对于bcrypt,这是散列密码的成本,默认为10." 基于这个问题,我正在考虑使用12的工作系数.这看起来合情合理吗?
  • 密码长度.一般来说,较长的密码似乎更安全,但我不希望它太难以让用户将它写在某张纸上.如果我们使用bcrypt,密码长度是否重要?
  • SSL cookie.对于启用了SSL的公共应用程序,将cookie标记为"这只能通过HTTPS传输"可以防止Firesheep风格的攻击.但我不确定为内部应用程序获得安全证书会有多大意义.这很傻吗?

我还缺少什么?

security encryption bcrypt devise ruby-on-rails-3

31
推荐指数
1
解决办法
7170
查看次数

Rails api和本机移动应用程序身份验证

我知道有很多关于这个主题的信息,但我找不到任何最新的信息.我看到这样的主题与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到最佳答案.

android ruby-on-rails devise ios oauth-2.0

31
推荐指数
3
解决办法
1万
查看次数

如何在覆盖设计注册控制器时编写控制器测试?

我希望覆盖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)

routing routes ruby-on-rails devise ruby-on-rails-3

30
推荐指数
1
解决办法
5874
查看次数

注销后,如果我按下按钮,我可以看到需要登录的最后一页

我已经在我的Web应用程序中配置了设计.我有以下工作流程的问题:

要访问管理面板,我需要登录.之后,我正常导航到我的网络应用程序的管理面板.当我单击logout时,它会将我重定向到根页面,这是我想要的行为.

奇怪的是,在这个页面中开始,在上面的操作之后,我点击了浏览器的后退按钮,它显示了我的缓存的最后一页.我的会话已被破坏,因为如果我点击刷新它重定向我并提示登录访问该页面,但我不希望能够看到浏览器的最后一个历史页面.

这怎么可能,我该怎么做才能防止它呢?它与浏览器缓存有关吗?解决此问题的唯一方法是从登录页面中删除缓存以防止此行为?我怎样才能做到这一点?

ruby-on-rails browser-cache devise ruby-on-rails-3

30
推荐指数
2
解决办法
9652
查看次数

通过FactoryGirl定义中的rolify设置角色

我正在使用设计,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)

rspec ruby-on-rails devise factory-bot

30
推荐指数
1
解决办法
6195
查看次数

用Rails设计4

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)

ruby-on-rails bundler devise

30
推荐指数
2
解决办法
4万
查看次数

Rails,Devise,Rspec:未定义的方法'sign_in'

我正在尝试在Rails中编写Rspec测试,使用Devise帮助方法进行登录和注销.sign_in方法无效.但是,在对应用程序进行一系列更改之前,它已经提前工作了.

我尝试过的事情:

  • 我在Rspec.configure中包含了测试助手.
  • 使用Warden的login_as
  • 清除Rails缓存.
  • 摆脱Capybara,看看是否导致问题
  • 我没有在我的控制器规范中明确设置会话(例如没有valid_session)

到目前为止,没有骰子.使用已登录用户测试控制器需要做些什么?

错误信息:

 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)

rspec devise ruby-on-rails-4

30
推荐指数
5
解决办法
2万
查看次数

使用Rails 4.2升级时,Devise会引发错误

当我跑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:resetdb:migratedb:setup:

rake aborted!
NoMethodError: undefined method `merge!' for #<ActionDispatch::Routing::Mapper::Scope:0x007fca8d3f2780>
Run Code Online (Sandbox Code Playgroud)

ruby ruby-on-rails devise ruby-on-rails-4

30
推荐指数
2
解决办法
7700
查看次数

Devise中sign_in页面的路径助手的名称是什么?

我在文档中找不到这个.我发现的只是一种after_sign_in_path_for方法.我想要的是这样的东西,sign_in_path_for(:account)所以我不必硬编码"/ account/sign_in"路径.如果Devise有这样的事情,任何想法?

ruby-on-rails devise

29
推荐指数
1
解决办法
1万
查看次数