-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathlogin_signer.rb
More file actions
34 lines (28 loc) · 945 Bytes
/
login_signer.rb
File metadata and controls
34 lines (28 loc) · 945 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# frozen_string_literal: true
module Smithy
module Client
# Signs requests with the Login identity.
class LoginSigner
# @param [Hash] options
# @option options [Symbol] :type
# The type of login authentication. Valid values are: :http_basic.
def initialize(options = {})
@type = options[:type]
end
def sign_request(context)
raise NotImplementedError unless @type == :http_basic
sign_with_basic(context.http_request, context.config.login_provider)
end
def presign_url(_context)
raise NotImplementedError
end
private
def sign_with_basic(http_request, provider)
http_request.headers.delete('Authorization')
identity = provider.identity
encoded = Base64.strict_encode64("#{identity.username}:#{identity.password}")
http_request.headers['Authorization'] = "Basic #{encoded}"
end
end
end
end