Module: DotNetServices::Authentication
- Defined in:
- lib/dot_net_services/authentication.rb
Overview
This stores the token and expiration time. The default expiration time is 1 day.
Defined Under Namespace
Classes: Anonymous, Certificate, Token, UsernamePassword
Class Method Summary collapse
- .clear_cache! ⇒ Object
-
.create_authenticator(auth_data) ⇒ Object
Create an authenticator based on the data provided.
- .setup(auth_data) ⇒ Object
Class Method Details
.clear_cache! ⇒ Object
162 163 164 |
# File 'lib/dot_net_services/authentication.rb', line 162 def clear_cache! @cache.clear end |
.create_authenticator(auth_data) ⇒ Object
Create an authenticator based on the data provided.
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/dot_net_services/authentication.rb', line 129 def create_authenticator(auth_data) if auth_data.nil? Authentication::Anonymous.new elsif !auth_data.is_a? Hash auth_data elsif auth_data.empty? Authentication::Anonymous.new else auth_data_copy = auth_data.dup username = auth_data_copy.delete(:username) password = auth_data_copy.delete(:password) certificate = auth_data_copy.delete(:certificate) unless auth_data_copy.empty? raise ArgumentError, "Auth data contains unknown options: #{auth_data.keys.inspect}" end if username && !password raise ArgumentError, "Auth data specifies username, but no password." elsif password && !username raise ArgumentError, "Auth data specifies password, but no username." elsif (username || password) && certificate raise ArgumentError, "Cannot determine authentication type from auth data." elsif username && password Authentication::UsernamePassword.new(username, password) elsif certificate Authentication::Certificate.new else raise "Internal error. Unable to setup authenticator from #{auth_data.inspect}" end end end |
.setup(auth_data) ⇒ Object
123 124 125 126 |
# File 'lib/dot_net_services/authentication.rb', line 123 def setup(auth_data) authenticator = create_authenticator(auth_data) @cache[authenticator] ||= authenticator end |