class Stormpath::Authentication::HttpBasicAuthentication

Constants

BASIC_PATTERN

Attributes

application[R]
authorization_header[R]

Public Class Methods

new(application, authorization_header) click to toggle source
   # File lib/stormpath-sdk/auth/http_basic_authentication.rb
 7 def initialize(application, authorization_header)
 8   @application = application
 9   @authorization_header = authorization_header
10   raise Stormpath::Error if authorization_header.nil?
11 end

Public Instance Methods

authenticate!() click to toggle source
   # File lib/stormpath-sdk/auth/http_basic_authentication.rb
13 def authenticate!
14   raise Stormpath::Error if fetched_api_key.nil?
15   raise Stormpath::Error if fetched_api_key.secret != api_key_secret
16   fetched_api_key
17 end

Private Instance Methods

api_key_id() click to toggle source
   # File lib/stormpath-sdk/auth/http_basic_authentication.rb
25 def api_key_id
26   decoded_authorization_header.first
27 end
api_key_secret() click to toggle source
   # File lib/stormpath-sdk/auth/http_basic_authentication.rb
29 def api_key_secret
30   decoded_authorization_header.last
31 end
basic_authorization_header() click to toggle source
   # File lib/stormpath-sdk/auth/http_basic_authentication.rb
41 def basic_authorization_header
42   raise Stormpath::Error unless authorization_header =~ BASIC_PATTERN
43   authorization_header.gsub(BASIC_PATTERN, '')
44 end
decoded_authorization_header() click to toggle source
   # File lib/stormpath-sdk/auth/http_basic_authentication.rb
33 def decoded_authorization_header
34   @decoded_authorization_header ||= begin
35     api_key_and_secret = Base64.decode64(basic_authorization_header).split(':')
36     raise Stormpath::Error if api_key_and_secret.count != 2
37     api_key_and_secret
38   end
39 end
fetched_api_key() click to toggle source
   # File lib/stormpath-sdk/auth/http_basic_authentication.rb
21 def fetched_api_key
22   @fetched_api_key ||= application.api_keys.search(id: api_key_id).first
23 end