Class: Tilia::Http::Auth::Bearer
- Inherits:
-
AbstractAuth
- Object
- AbstractAuth
- Tilia::Http::Auth::Bearer
- Defined in:
- lib/tilia/http/auth/bearer.rb
Overview
HTTP Bearer authentication utility.
This class helps you setup bearer auth. The process is fairly simple:
-
Instantiate the class.
-
Call getToken (this will return null or a token as string)
-
If you didn’t get a valid token, call ‘requireLogin’
Instance Attribute Summary
Attributes inherited from AbstractAuth
Instance Method Summary collapse
-
#require_login ⇒ void
This method sends the needed HTTP header and statuscode (401) to force authentication.
-
#token ⇒ Object
This method returns a string with an access token.
Methods inherited from AbstractAuth
Constructor Details
This class inherits a constructor from Tilia::Http::Auth::AbstractAuth
Instance Method Details
#require_login ⇒ void
This method returns an undefined value.
This method sends the needed HTTP header and statuscode (401) to force authentication.
30 31 32 33 |
# File 'lib/tilia/http/auth/bearer.rb', line 30 def require_login @response.add_header('WWW-Authenticate', "Bearer realm=\"#{@realm}\"") @response.status = 401 end |
#token ⇒ Object
This method returns a string with an access token.
If no token was found, this method returns null.
17 18 19 20 21 22 23 24 |
# File 'lib/tilia/http/auth/bearer.rb', line 17 def token auth = @request.header('Authorization') return nil unless auth return nil unless auth[0..6].downcase == 'bearer ' auth[7..-1] end |