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



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

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



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/restforce/concerns/authentication.rb', line 17

def authentication_middleware
  if username_password?
    Restforce::Middleware::Authentication::Password
  elsif oauth_refresh?
    Restforce::Middleware::Authentication::Token
  elsif jwt?
    Restforce::Middleware::Authentication::JWTBearer
  elsif client_credential?
    Restforce::Middleware::Authentication::ClientCredential
  end
end

#client_credential?Boolean

Internal: Returns true if client credential flow should be used for authentication.

Returns:

  • (Boolean)


56
57
58
# File 'lib/restforce/concerns/authentication.rb', line 56

def client_credential?
  options[:client_id] && options[:client_secret]
end

#jwt?Boolean

Internal: Returns true if jwt bearer token flow should be used for authentication.

Returns:

  • (Boolean)


48
49
50
51
52
# File 'lib/restforce/concerns/authentication.rb', line 48

def jwt?
  options[:jwt_key] &&
    options[:username] &&
    options[:client_id]
end

#oauth_refresh?Boolean

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

Returns:

  • (Boolean)


40
41
42
43
44
# File 'lib/restforce/concerns/authentication.rb', line 40

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)


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

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