Skip to content
3 changes: 3 additions & 0 deletions gems/smithy-client/lib/smithy-client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@
require_relative 'smithy-client/identity'
require_relative 'smithy-client/identity_provider'
require_relative 'smithy-client/refreshing_identity_provider'
require_relative 'smithy-client/identities/http_api_key'
require_relative 'smithy-client/identities/http_login'
require_relative 'smithy-client/identities/token'

# stubbing

Expand Down
4 changes: 2 additions & 2 deletions gems/smithy-client/lib/smithy-client/http_bearer_provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

module Smithy
module Client
# Returns an HTTP Bearer identity
# Returns a Token identity
class HttpBearerProvider
include IdentityProvider

# @param [String] token
def initialize(token)
@identity = Identities::HttpBearer.new(token: token)
@identity = Identities::Token.new(token: token)
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,21 @@
module Smithy
module Client
module Identities
# Identity class for HTTP Bearer token authentication.
class HttpBearer < Identity
# Identity class for token authentication.
class Token < Identity
def initialize(token:, **)
@token = token
super(**)
end

# @return [String, nil]
attr_reader :token

# Removing the token from the default inspect string.
# @api private
def inspect
"#<#{self.class.name} token=[FILTERED]>"
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

require_relative '../http_bearer_provider'
require_relative '../identities/http_bearer'
require_relative '../identities/token'

module Smithy
module Client
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def resolve_auth(context, auth_options)
auth_options.each do |auth_option|
# Anonymous auth does not have a plugin and does not sign,
# so if auth scheme is noAuth then just return scheme_id.
return { scheme_id: auth_option } if auth_option == 'smithy.api#noAuth'
return { scheme_id: auth_option } if %w[smithy.api#noAuth smithy.api#optionalAuth].include?(auth_option)

unless context.config.auth_schemes.key?(auth_option)
failures << "Auth scheme #{auth_option} was not enabled for this request"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
module Smithy
module Client
module Identities
class HttpBearer < Identity
class Token < Identity
def initialize: (token: String, **untyped options) -> void
attr_reader token: String
def inspect: () -> String
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ module Plugins
client_class.add_plugin(HttpBearerAuth)
resp = client.operation
expect(resp.context.auth[:scheme_id]).to equal('smithy.api#httpBearerAuth')
expect(resp.context.auth[:identity]).to be_a(Identities::HttpBearer)
expect(resp.context.auth[:identity]).to be_a(Identities::Token)
end

it 'resolves auth for http digest auth' do
Expand Down