Class: HaveAPI::Fs::Auth::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/haveapi/fs/auth/base.rb

Overview

Base class for all authentication methods.

Direct Known Subclasses

Basic, NoAuth, Token

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cfg, opts) ⇒ Base

Returns a new instance of Base.

Parameters:

  • cfg (Hash)

    server config

  • opts (Hash)

    mount options



23
24
25
26
27
28
# File 'lib/haveapi/fs/auth/base.rb', line 23

def initialize(cfg, opts)
  @cfg = cfg
  @opts = opts

  setup
end

Class Method Details

.method_nameObject



4
5
6
# File 'lib/haveapi/fs/auth/base.rb', line 4

def self.method_name
  @method_name
end

.register(name) ⇒ Object

All authentication providers must register using this method.

Parameters:

  • name (Symbol)


10
11
12
13
# File 'lib/haveapi/fs/auth/base.rb', line 10

def self.register(name)
  HaveAPI::Fs.register_auth(name, self)
  @method_name = name
end

.use?(opts) ⇒ Boolean

Check if this authentication provider should be used based on opts.

Parameters:

  • opts (Hash)

    mount options

Returns:

  • (Boolean)


17
18
19
# File 'lib/haveapi/fs/auth/base.rb', line 17

def self.use?(opts)
  false
end

Instance Method Details

#authenticate(client) ⇒ Object

Authenticate the client object

Parameters:

  • client (HaveAPI::Client::Client)


47
48
49
# File 'lib/haveapi/fs/auth/base.rb', line 47

def authenticate(client)
  
end

#check(client) ⇒ Object

Check whether the authentication works by running some real API request.



52
53
54
# File 'lib/haveapi/fs/auth/base.rb', line 52

def check(client)
  client.user.current
end

#nameObject



35
36
37
# File 'lib/haveapi/fs/auth/base.rb', line 35

def name
  self.class.method_name
end

#setupObject

Called right after #initialize.



31
32
33
# File 'lib/haveapi/fs/auth/base.rb', line 31

def setup

end

#validateObject

In this method, the provider should check if it has all needed information. Missing pieces can be queried from the user on stdin.



41
42
43
# File 'lib/haveapi/fs/auth/base.rb', line 41

def validate

end