2016-05-04 18 views
1

我有一個使用devise和devise_token_auth的Rails 4.X應用程序。我想在調用此應用時加密電子郵件和密碼。使用encrypted_pa​​ssword登錄devise_token_auth

這裏是服務器端代碼:

user.rb

class User < ActiveRecord::Base 
    # Include default devise modules. Others available are: 
    # :confirmable, :lockable, :timeoutable and :omniauthable 
    devise :database_authenticatable, :registerable, 
     :recoverable, :rememberable, :trackable, :validatable 

    include DeviseTokenAuth::Concerns::User 

的Gemfile

gem 'devise' 
gem 'devise_token_auth' 
gem 'omniauth' 

這是我的電話捲髮(有明文的用戶名和密碼)

curl -v -H 'Content-Type: application/json' -H 'Accept: application/json' -X POST http://localhost:3000/api/auth/sign_in -d "{\"email\":\"[email protected]\",\"password\":\"aaaaaaa"}" 

我知道我ca n使用https保護最初的呼叫。但是,有沒有其他方式發送用戶名和密碼加密(不使用https)? 謝謝!

回答

1

您可以按RFC 7616中的規定執行challenge-response authentication。這將通過明文通道充分保護密碼。但是,這種方法本質上傾向於man-in-the-middle attacks。另一個問題是,這種方法依賴於共享的祕密,這會破壞服務器端的安全密碼存儲。

我的建議是通過安全通道(即https)使用RFC 7617中指定的基本認證方案。這是相對容易實施和建立的做法。

+0

謝謝! Https是! –

相關問題