Class: Beats::Auth

Inherits:
Object
  • Object
show all
Defined in:
lib/beats/auth.rb

Overview

Note:

Credentials are stored in a users home directiory in the file ~/.beats/credentials.yml.

Helper class for asking for and handling authentication credentials. The CLI interface uses this class to prompt the user for her credentials when she tries to access a protected resource.

Class Method Summary collapse

Class Method Details

.access_tokenString

Reads the users access token from her credentials file.

Returns:

  • (String)

    An access token, or nil if the user hasn't authenticated yet.



25
26
27
28
29
30
# File 'lib/beats/auth.rb', line 25

def access_token
  @credentials ||= read_credentials
  if @credentials
    @credentials['access_token']
  end
end

.loginObject

Prompt the user for her credentials. Will display an interactive command line prompt. If the credentials are valid they will be cached in the ~/.beats/credentials.yml file (as an access token).



13
14
15
# File 'lib/beats/auth.rb', line 13

def 
  ask_for_credentials
end

.logoutObject

Wipe the current users credentials from the system.



18
19
20
# File 'lib/beats/auth.rb', line 18

def logout
  delete_credentials
end