Sha256: 4ed7e7e367a17bc9eb1f9642b9e2f6d3e25ff93150cb7b42b6c52cac150292df

Contents?: true

Size: 1.03 KB

Versions: 10

Compression:

Stored size: 1.03 KB

Contents

# Helper methods for user sign in with
# authentication token.
#

# Signs in a user via different methods (i.e., HTTP AUTH,
# Token Auth, plain). If no user is given with the +options+
# a new one is created.
#
def sign_in_as_new_user_with_token(options = {})
  trait = options[:use] ? options[:use] : :with_authentication_token
  user = options.delete(:user) || create(:user, trait)

  options[:auth_token_key] ||= Devise::TokenAuthenticatable.token_authentication_key
  options[:auth_token]     ||= user.authentication_token

  if options[:http_auth]
    header = "Basic #{Base64.encode64("#{options[:auth_token]}:X")}"
    get users_path(format: :xml), {}, "HTTP_AUTHORIZATION" => header
  elsif options[:token_auth]
    token_options = options[:token_options] || {}
    header = ActionController::HttpAuthentication::Token.encode_credentials(options[:auth_token], token_options)
    get users_path(format: :xml), {}, "HTTP_AUTHORIZATION" => header
  else
    get users_path(options[:auth_token_key].to_sym => options[:auth_token])
  end

  user
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
devise-token_authenticatable-1.1.0 spec/support/session_helper.rb
devise-token_authenticatable-1.0.2 spec/support/session_helper.rb
devise-token_authenticatable-1.0.1 spec/support/session_helper.rb
devise-token_authenticatable-1.0.0 spec/support/session_helper.rb
devise-token_authenticatable-0.5.3 spec/support/session_helper.rb
devise-token_authenticatable-0.5.2 spec/support/session_helper.rb
devise-token_authenticatable-0.5.1 spec/support/session_helper.rb
devise-token_authenticatable-0.4.10 spec/support/session_helper.rb
devise-token_authenticatable-0.5.0 spec/support/session_helper.rb
devise-token_authenticatable-0.4.9 spec/support/session_helper.rb