Module: Utcp::Auth

Defined in:
lib/utcp/auth.rb

Defined Under Namespace

Classes: ApiKey, Base, Basic, OAuth2

Class Method Summary collapse

Class Method Details

.from_hash(h) ⇒ Object



96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/utcp/auth.rb', line 96

def self.from_hash(h)
  return nil unless h.is_a?(Hash)
  type = (h["auth_type"] || h["type"] || "").downcase
  case type
  when "api_key", "apikey"
    ApiKey.new(api_key: h["api_key"] || h["key"] || "", var_name: h["var_name"] || "Authorization", location: (h["location"] || "header"))
  when "basic"
    Basic.new(username: h["username"] || "", password: h["password"] || "")
  when "oauth2"
    OAuth2.new(token_url: h["token_url"] || h["tokenUrl"] || "", client_id: h["client_id"] || "", client_secret: h["client_secret"] || "", scope: h["scope"])
  else
    nil
  end
end