class Stormpath::Authentication::BasicAuthenticator

Public Class Methods

new(data_store) click to toggle source
   # File lib/stormpath-sdk/auth/basic_authenticator.rb
21 def initialize(data_store)
22   @data_store = data_store
23 end

Public Instance Methods

authenticate(parent_href, request) click to toggle source
   # File lib/stormpath-sdk/auth/basic_authenticator.rb
25 def authenticate(parent_href, request)
26   assert_not_nil parent_href, 'parentHref argument must be specified'
27   assert_kind_of UsernamePasswordRequest, request, 'Only UsernamePasswordRequest instances are supported.'
28 
29   username = request.principals
30   username ||= ''
31 
32   password = request.credentials
33   pw_string = password.join
34 
35   value = username + ':' + pw_string
36 
37   value = Base64.encode64(value).tr("\n", '')
38 
39   attempt = @data_store.instantiate(BasicLoginAttempt, nil)
40   attempt.type = 'basic'
41   attempt.value = value
42 
43   attempt.account_store = request.account_store if request.account_store
44 
45   href = parent_href + '/loginAttempts'
46 
47   @data_store.create(href, attempt, AuthenticationResult)
48 end