Class: Sitefull::Auth::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/sitefull-cloud/auth/base.rb

Direct Known Subclasses

Amazon, Azure, Google

Constant Summary collapse

MISSING_AUTHORIZATION_URI =
'Missing Authorization URL'.freeze
MISSING_BASE_URI =
'Missing base URL and redirect URL'.freeze
MISSING_BASE_URI_SCHEME =
'Base URL must be an absolute URL'.freeze
MISSING_CALLBACK_URI =
'No callback URI specified'.freeze
MISSING_CLIENT_ID =
'Missing Client ID'.freeze
MISSING_CLIENT_SECRET =
'Missing Client Secret'.freeze
MISSING_REDIRECT_URI_SCHEME =
'Redirect URL must be an absolute URL'.freeze
MISSING_SCOPE =
'Missing scope'.freeze
MISSING_TOKEN_CREDENTIALS_URI =
'Missing Token Credentials URL'.freeze

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Base

Returns a new instance of Base.



15
16
17
# File 'lib/sitefull-cloud/auth/base.rb', line 15

def initialize(options = {})
  @options = validate(options) if options[:validate].to_s.empty? || options[:validate]
end

Instance Method Details

#authorization_uri(_) ⇒ Object



38
39
40
# File 'lib/sitefull-cloud/auth/base.rb', line 38

def authorization_uri(_)
  fail MISSING_AUTHORIZATION_URI
end

#authorization_url_optionsObject



30
31
32
# File 'lib/sitefull-cloud/auth/base.rb', line 30

def authorization_url_options
  @options.select { |k| [:state, :login_hint, :redirect_uri].include? k.to_sym }
end

#callback_uriObject



34
35
36
# File 'lib/sitefull-cloud/auth/base.rb', line 34

def callback_uri
  fail MISSING_CALLBACK_URI
end

#required_settingsObject



50
51
52
# File 'lib/sitefull-cloud/auth/base.rb', line 50

def required_settings
  [:client_id, :client_secret]
end

#scopeObject



42
43
44
# File 'lib/sitefull-cloud/auth/base.rb', line 42

def scope
  fail MISSING_SCOPE
end

#token_credentials_uri(_) ⇒ Object



46
47
48
# File 'lib/sitefull-cloud/auth/base.rb', line 46

def token_credentials_uri(_)
  fail MISSING_TOKEN_CREDENTIALS_URI
end

#token_optionsObject



26
27
28
# File 'lib/sitefull-cloud/auth/base.rb', line 26

def token_options
  @options.select { |k| [:authorization_uri, :client_id, :client_secret, :scope, :token_credential_uri, :redirect_uri].include? k.to_sym }.merge(@options[:token] || {})
end

#validate(options = {}) ⇒ Object



19
20
21
22
23
24
# File 'lib/sitefull-cloud/auth/base.rb', line 19

def validate(options = {})
  fail MISSING_CLIENT_ID if options[:client_id].to_s.empty?
  fail MISSING_CLIENT_SECRET if options[:client_secret].to_s.empty?
  fail MISSING_REDIRECT_URI_SCHEME if !options[:redirect_uri].to_s.empty? && URI(options[:redirect_uri].to_s).scheme.to_s.empty?
  process(options)
end