class Authorization
Used for basic authorization.
headers.add('authorization', Authorization.basic("my_username", "my_password"))
TODO Support other authorization mechanisms, e.g. bearer token.
Definitions
def credentials
Splits the header into the credentials.
Signature
-
returns
Tuple(String, String)
The username and password.
Implementation
def credentials
self.split(/\s+/, 2)
end
def self.basic(username, password)
Generate a new basic authorization header, encoding the given username and password.
Signature
-
parameter
username
String
The username.
-
parameter
password
String
The password.
-
returns
Authorization
The basic authorization header.
Implementation
def self.basic(username, password)
strict_base64_encoded = ["#{username}:#{password}"].pack("m0")
self.new(
"Basic #{strict_base64_encoded}"
)
end