Module: Restforce::Concerns::Authentication

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

Instance Method Summary collapse

Instance Method Details

#authenticate!Object

Public: Force an authentication



5
6
7
8
9
10
11
12
# File 'lib/restforce/concerns/authentication.rb', line 5

def authenticate!
  unless authentication_middleware
    raise AuthenticationError, 'No authentication middleware present'
  end

  middleware = authentication_middleware.new nil, self, options
  middleware.authenticate!
end

#authentication_middlewareObject

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



15
16
17
18
19
20
21
# File 'lib/restforce/concerns/authentication.rb', line 15

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

#oauth_refresh?Boolean

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

Returns:

  • (Boolean)


34
35
36
37
38
# File 'lib/restforce/concerns/authentication.rb', line 34

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)


25
26
27
28
29
30
# File 'lib/restforce/concerns/authentication.rb', line 25

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