Module: Force::Concerns::Authentication

Included in:
AbstractClient
Defined in:
lib/force/concerns/authentication.rb

Instance Method Summary collapse

Instance Method Details

#authenticate!Object

Public: Force an authentication



6
7
8
9
10
# File 'lib/force/concerns/authentication.rb', line 6

def authenticate!
  raise AuthenticationError, 'No authentication middleware present' unless authentication_middleware
  middleware = authentication_middleware.new nil, self, options
  middleware.authenticate!
end

#authentication_middlewareObject

Internal: Determines what middleware will be used based on the options provided



13
14
15
16
17
18
19
# File 'lib/force/concerns/authentication.rb', line 13

def authentication_middleware
  if username_password?
    Force::Middleware::Authentication::Password
  elsif oauth_refresh?
    Force::Middleware::Authentication::Token
  end
end

#oauth_refresh?Boolean

Internal: Returns true if oauth token refresh flow should be used for authentication.

Returns:

  • (Boolean)


32
33
34
35
36
# File 'lib/force/concerns/authentication.rb', line 32

def oauth_refresh?
  options[:refresh_token] &&
    options[:client_id] &&
    options[:client_secret]
end

#username_password?Boolean

Internal: Returns true if username/password (autonomous) flow should be used for authentication.

Returns:

  • (Boolean)


23
24
25
26
27
28
# File 'lib/force/concerns/authentication.rb', line 23

def username_password?
  options[:username] &&
    options[:password] &&
    options[:client_id] &&
    options[:client_secret]
end