Skip to content

Commit

Permalink
Add AUTHENTICATION_HEADER to X::Authenticator base class
Browse files Browse the repository at this point in the history
  • Loading branch information
sferik committed Oct 25, 2023
1 parent a6b6acd commit dcbb6a6
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
4 changes: 3 additions & 1 deletion lib/x/authenticator.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
module X
# Base Authenticator class
class Authenticator
AUTHENTICATION_HEADER = "Authorization".freeze

def header(_request)
{"Authorization" => ""}
{AUTHENTICATION_HEADER => ""}
end
end
end
2 changes: 1 addition & 1 deletion lib/x/bearer_token_authenticator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def initialize(bearer_token:) # rubocop:disable Lint/MissingSuper
end

def header(_request)
{"Authorization" => "Bearer #{bearer_token}"}
{AUTHENTICATION_HEADER => "Bearer #{bearer_token}"}
end
end
end
2 changes: 1 addition & 1 deletion lib/x/oauth_authenticator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def initialize(api_key:, api_key_secret:, access_token:, access_token_secret:) #

def header(request)
method, url, query_params = parse_request(request)
{"Authorization" => build_oauth_header(method, url, query_params)}
{AUTHENTICATION_HEADER => build_oauth_header(method, url, query_params)}
end

private
Expand Down
6 changes: 4 additions & 2 deletions sig/x.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@ module X
VERSION: Gem::Version

class Authenticator
AUTHENTICATION_HEADER: String

def header: (Net::HTTPRequest? request) -> Hash[String, String]
end

class BearerTokenAuthenticator
class BearerTokenAuthenticator < Authenticator
attr_accessor bearer_token: String
def initialize: (bearer_token: String) -> void
def header: (Net::HTTPRequest? request) -> Hash[String, String]
end

class OAuthAuthenticator
class OAuthAuthenticator < Authenticator
OAUTH_VERSION: String
OAUTH_SIGNATURE_METHOD: String
OAUTH_SIGNATURE_ALGORITHM: String
Expand Down

0 comments on commit dcbb6a6

Please sign in to comment.