Skip to content

Commit

Permalink
Change cookie key to cookie key suffix
Browse files Browse the repository at this point in the history
  • Loading branch information
Yvo van Beek committed May 23, 2015
1 parent 4421f0a commit 57e2850
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,8 @@ You can configure the MfaSession cookie by creating an initializer:
# The cookie normally expires in 24 hours, you can change this to 1 month
GoogleAuthenticatorRails.time_until_expiration = 1.month

# You can override the cookie's key, by default this is <class>_mfa_credentials
GoogleAuthenticatorRails.cookie_key = 'mfa_credentials'
# You can override the suffix of the cookie's key, by default this is mfa_credentials
GoogleAuthenticatorRails.cookie_key_suffix = 'mfa_credentials'

# Rails offers a few more cookie options, by default only :httponly is turned on, you can change it to HTTPS only:
GoogleAuthenticatorRails.cookie_options = { :httponly => true, :secure => true, :domain => :all }
Expand Down
12 changes: 6 additions & 6 deletions lib/google-authenticator-rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ module GoogleAuthenticatorRails
# How long a Session::Persistence cookie should last.
@@time_until_expiration = 24.hours

# Name of a Session::Persistence cookie
@@cookie_key = nil
# Last part of a Session::Persistence cookie's key
@@cookie_key_suffix = nil

# Additional configuration passed to a Session::Persistence cookie.
@@cookie_options = { :httponly => true }
Expand Down Expand Up @@ -59,12 +59,12 @@ def self.time_until_expiration=(time_until_expiration)
@@time_until_expiration = time_until_expiration
end

def self.cookie_key
@@cookie_key
def self.cookie_key_suffix
@@cookie_key_suffix
end

def self.cookie_key=(key)
@@cookie_key = key
def self.cookie_key_suffix=(suffix)
@@cookie_key_suffix = suffix
end

def self.cookie_options
Expand Down
3 changes: 2 additions & 1 deletion lib/google-authenticator-rails/session/persistence.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ def create_cookie(token, user_id)
end

def cookie_key
GoogleAuthenticatorRails.cookie_key || "#{klass.to_s.downcase}_mfa_credentials"
suffix = "#{GoogleAuthenticatorRails.cookie_key_suffix}" || 'mfa_credentials'
"#{klass.to_s.downcase}_#{suffix}"
end
end

Expand Down

0 comments on commit 57e2850

Please sign in to comment.