Return a string with http basic auth incorporated into it
513963
def add_http_basic_auth(url,
                        user=None,
                        password=None,
                        https_only=False):
    '''
    
    '''
    if user is None and password is None:
        return url
    else:
        urltuple = urlparse(url)
        if https_only and urltuple.scheme != 'https':
            raise ValueError('Basic Auth only supported for HTTPS')
        if password is None:
            netloc = '{0}@{1}'.format(
                user,
                urltuple.netloc
            )
            urltuple = urltuple._replace(netloc=netloc)
            return urlunparse(urltuple)
        else:
            netloc = '{0}:{1}@{2}'.format(
                user,
                password,
                urltuple.netloc
            )
            urltuple = urltuple._replace(netloc=netloc)
            return urlunparse(urltuple)
857283
def getHeaders(self):
        
        basicauth = base64.encodestring(b(self.user + ':' + self.password)).strip()
        return {
            "Depth": "1",
            "Authorization": 'Basic ' + _decode_utf8(basicauth),
            "Accept": "*/*"
        }
258987
function getAuthenticationObject () {
    const authString = url.parse(parts[0]).auth;

    if (authString) {
      return {
        source: getName(),
        user: authString.split(':')[0],
        pass: authString.split(':')[1]
      };
    } else {
      return {};
    }
  }
373221
def get_auth_basic(self):
        """"""
        username = ''
        password = ''
        auth_header = self.get_header('authorization')
        if auth_header:
            m = re.search(r"^Basic\s+(\S+)$", auth_header, re.I)
            if m:
                auth_str = Base64.decode(m.group(1))
                username, password = auth_str.split(':', 1)

        return username, password
553756
public String getAuthString() {
        String credentials = this.username + ":" + this.password;
        try {

            String encoded = new Base64().encodeAsString(credentials.getBytes("ascii"));
            return "Basic " + encoded;

        } catch (final UnsupportedEncodingException e) {

            throw new InvalidRequestException("It must be possible to encode credentials as ascii", credentials, e);

        }
    }
869390
def _authstr(self, auth):
        """"""
        if type(auth) is dict:
            return '{' + ','.join(["{0}:{1}".format(k, auth[k]) for k in sorted(auth.keys())]) + '}'
        return auth
96834
def OpenUrlWithBasicAuth(url, user='root', pwd=''):
   
   return requests.get(url, auth=HTTPBasicAuth(user, pwd), verify=False)
694800
def authbasic(request):
    
    if len(request.environ.get('HTTP_AUTHORIZATION', '')) > 0:
        auth = request.environ.get('HTTP_AUTHORIZATION')
        scheme, data = auth.split(None, 1)
        assert scheme.lower() == 'basic'
        data = base64.b64decode(data)
        if not isinstance(data, unicode):
            data = data.decode('utf-8')
        username, password = data.split(':', 1)
        if User.by_ldap_credentials(
                DBSession(), username, password, request.registry.settings):
            return HTTPFound(location=request.url)
        if User.by_credentials(DBSession(), username, password):
            return HTTPFound(location=request.url)
    return Response(status=401,
                    headerlist=[(str('WWW-Authenticate'),
                                 str('Basic realm="pyshop repository access"'),
                                 )],
                    )
1272411
def make_http_credentials(username=None, password=None):
    """"""
    credentials = ''
    if username is None:
        return credentials
    if username is not None:
        if ':' in username:
            return credentials
        credentials += username
    if credentials and password is not None:
        credentials += ":%s" % password
    return "%s@" % credentials
759521
def basic_auth_string(username, password):
    
    b64 = base64.encodestring('%s:%s' % (username, password)).strip()
    return 'Basic %s' % b64
836623
function parseAuth(auth) {
	if (auth && typeof auth === 'string') {
		var authObject = {
			username: auth.split(':')[0],
			password: auth.split(':')[1]
		};
		return authObject;
	} else {
		return auth;
	}
}
795547
def encode_basic_auth(username, password):
    
    return "Basic {}".format(
        b64encode(
            "{}:{}".format(
                username,
                password,
            ).encode("utf-8")
        ).decode("utf-8")
    )
1076931
def _auth(self):
        
        ts = datetime.datetime.now().strftime("%Y-%m-%d%H:%M:%S")
        hash_string = hashlib.md5("%s%s%s" % (ts, self.private_key, self.public_key)).hexdigest()
        return "ts=%s&apikey=%s&hash=%s" % (ts, self.public_key, hash_string)
874666
def build_preauth_str(preauth_key, account_name, timestamp, expires,
                      admin=False):
    
    if admin:
        s = '{0}|1|name|{1}|{2}'.format(account_name, expires, timestamp)
    else:
        s = '{0}|name|{1}|{2}'.format(account_name, expires, timestamp)

    return hmac.new(preauth_key.encode('utf-8'), s.encode('utf-8'),
                    hashlib.sha1).hexdigest()
609835
def decode(cls, auth_header: str, encoding: str='latin1') -> 'BasicAuth':
        """"""
        try:
            auth_type, encoded_credentials = auth_header.split(' ', 1)
        except ValueError:
            raise ValueError('Could not parse authorization header.')

        if auth_type.lower() != 'basic':
            raise ValueError('Unknown authorization method %s' % auth_type)

        try:
            decoded = base64.b64decode(
                encoded_credentials.encode('ascii'), validate=True
            ).decode(encoding)
        except binascii.Error:
            raise ValueError('Invalid base64 encoding.')

        try:
            # RFC 2617 HTTP Authentication
            # https://www.ietf.org/rfc/rfc2617.txt
            # the colon must be present, but the username and password may be
            # otherwise blank.
            username, password = decoded.split(':', 1)
        except ValueError:
            raise ValueError('Invalid credentials.')

        return cls(username, password, encoding=encoding)
144141
static AuthRequest fromString(String str) {
        String[] parts = str.split("-----");
        String clientId = parts[0];
        String[] scopes = parts.length == 2 ? parts[1].split(",") : new String[0];
        AuthRequest req = new AuthRequest("", clientId).withScopes(scopes);
        return req;
    }
559315
def parse_auth(header):
    
    try:
        method, data = header.split(None, 1)
        if method.lower() == 'basic':
            user, pwd = touni(base64.b64decode(tob(data))).split(':',1)
            return user, pwd
    except (KeyError, ValueError):
        return None